<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ishita</title>
    <description>The latest articles on DEV Community by Ishita (@ishita__14cc5a0ee7a).</description>
    <link>https://dev.to/ishita__14cc5a0ee7a</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2118339%2Fb803832b-f1e0-464a-a897-27657980a278.jpg</url>
      <title>DEV Community: Ishita</title>
      <link>https://dev.to/ishita__14cc5a0ee7a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ishita__14cc5a0ee7a"/>
    <language>en</language>
    <item>
      <title>🚀 Building Group Track: An Open-Source Location Tracker App with Flutter</title>
      <dc:creator>Ishita</dc:creator>
      <pubDate>Thu, 17 Oct 2024 11:02:40 +0000</pubDate>
      <link>https://dev.to/ishita__14cc5a0ee7a/building-group-track-an-open-source-location-tracker-app-with-flutter-4hkk</link>
      <guid>https://dev.to/ishita__14cc5a0ee7a/building-group-track-an-open-source-location-tracker-app-with-flutter-4hkk</guid>
      <description>&lt;p&gt;Hey, Dev Community! 👋&lt;/p&gt;

&lt;p&gt;I’m excited to introduce &lt;a href="https://github.com/canopas/group-track-flutter" rel="noopener noreferrer"&gt;Group Track&lt;/a&gt;, an open-source Flutter project that showcases best practices for building location-based apps. Working with location services can get tricky—finding the right solutions isn’t always straightforward. Through this project, we demonstrate how to handle the key challenges of real-time tracking, map integration, and state management to create a seamless user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🛠️ What Group Track Covers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this project, we explore several important concepts and implementations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-Time Location Sharing 📍: Efficient tracking of user location in real time.&lt;/li&gt;
&lt;li&gt;State Management with Bloc 🧠: Manage app state to ensure smooth updates and responsive UIs.&lt;/li&gt;
&lt;li&gt;Google Maps Customisation 🗺️: Apply custom markers, overlays, and controls to fit your app’s needs.&lt;/li&gt;
&lt;li&gt;Geofencing Integration 🏡: Set specific locations and trigger actions when users enter or leave them.&lt;/li&gt;
&lt;li&gt;Background and Foreground Location Management 🔄: Ensure the app runs reliably whether it’s active or in the background.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🎯 Why We Built This Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The goal behind Group Track was to create a resource for developers interested in location-based app development. We hope it provides insights into handling common challenges—like updating location data reliably or managing real-time state changes—all while keeping code organised and maintainable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔗 Explore the Code and Learn More&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Whether you’re building your own location-based app or just curious about Flutter’s potential, Group Track is available as a resource to explore. Feel free to dive into the code and see how we’ve implemented these features.&lt;br&gt;
👉 Check out the &lt;a href="https://github.com/canopas/group-track-flutter" rel="noopener noreferrer"&gt;Group Track GitHub Repo&lt;/a&gt;&lt;br&gt;
We hope it gives you some useful ideas for your own projects. Thanks for checking it out! 😊&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introducing GroupTrack: Simplified Location-Based Services for Flutter</title>
      <dc:creator>Ishita</dc:creator>
      <pubDate>Tue, 08 Oct 2024 09:49:48 +0000</pubDate>
      <link>https://dev.to/ishita__14cc5a0ee7a/introducing-grouptrack-simplified-location-based-services-for-flutter-3l9i</link>
      <guid>https://dev.to/ishita__14cc5a0ee7a/introducing-grouptrack-simplified-location-based-services-for-flutter-3l9i</guid>
      <description>&lt;p&gt;Hello community👋.&lt;/p&gt;

&lt;p&gt;We all know that working with location-based services can be challenging😩—from managing location accuracy to ensuring efficient background updates, it’s a time-consuming⌛ process.&lt;/p&gt;

&lt;p&gt;Developers often face issues like::&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managing accuracy&lt;/li&gt;
&lt;li&gt;Handling background services&lt;/li&gt;
&lt;li&gt;Optimising battery usage&lt;/li&gt;
&lt;li&gt;Real-time background updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To make this easier for developers, our &lt;a href="https://canopas.com/" rel="noopener noreferrer"&gt;CanopasTeam&lt;/a&gt; has built &lt;strong&gt;GroupTrack&lt;/strong&gt;, an open-source Flutter project aimed at simplifying location-based services and background operations. &lt;a href="https://github.com/canopas/group-track-flutter" rel="noopener noreferrer"&gt;GroupTrack&lt;/a&gt; tackles the common problems developers face.&lt;/p&gt;

&lt;p&gt;Let's delve into the specific approaches used in the project.&lt;/p&gt;

&lt;p&gt;1️⃣ &lt;strong&gt;Managing accuracy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The project utilises the &lt;a href="https://pub.dev/packages/geolocator" rel="noopener noreferrer"&gt;geolocator&lt;/a&gt; package, a popular Flutter plugin for accessing location services. This package allows the app to specify the desired accuracy when requesting location data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Position position = await Geolocator.getCurrentPosition(
  desiredAccuracy: LocationAccuracy.high,
  distanceFilter: 10, // Update every 10 meters
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Desired Accuracy Levels:&lt;/strong&gt; The desiredAccuracy parameter can be set to levels like &lt;code&gt;high&lt;/code&gt;, &lt;code&gt;medium&lt;/code&gt;, or &lt;code&gt;low&lt;/code&gt;, depending on the needs of the app at that moment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Impact on Battery Life:&lt;/strong&gt; Higher accuracy requires more power. By adjusting the accuracy level, the app conserves battery when high precision isn't necessary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reduces Unnecessary Updates:&lt;/strong&gt; By only receiving updates when the user has moved a certain distance, the app minimizes redundant processing and this helps in reducing CPU usage and conserves battery life.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;iOS Implementation:&lt;/strong&gt;&lt;br&gt;
For iOS, we use native code in the AppDelegate file to manage location services.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var locationManager: CLLocationManager?

override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -&amp;gt; Bool {
    setUpLocation()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

private func setUpLocation() {
    locationManager = CLLocationManager()
    locationManager?.delegate = self
    locationManager?.distanceFilter = 10
    locationManager?.desiredAccuracy = kCLLocationAccuracyBest
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2️⃣ &lt;strong&gt;Handling background services&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;To handle location services in the background, we configure both Android and iOS separately.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Android&lt;/strong&gt;&lt;br&gt;
Add the following service configuration to your AndroidManifest.xml file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;service  
    android:name="id.flutter.flutter_background_service.BackgroundService"
    android:enabled="true"
    android:exported="true"
    android:foregroundServiceType="location" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;iOS&lt;/strong&gt;&lt;br&gt;
Enable Background Mode in the Signing &amp;amp; Capabilities section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybdcnsqalafbh27daw7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fybdcnsqalafbh27daw7m.png" alt="Add background modes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;add this in app delegate&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private func setUpLocation() {
    locationManager?.allowsBackgroundLocationUpdates = true
    locationManager?.pausesLocationUpdatesAutomatically = false
    locationManager?.startMonitoringSignificantLocationChanges()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Flutter&lt;/strong&gt;&lt;br&gt;
The project utilises the &lt;a href="https://pub.dev/packages/flutter_background_service" rel="noopener noreferrer"&gt;flutter_background_service&lt;/a&gt; package for managing background service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() async {
WidgetsFlutterBinding.ensureInitialized();
  startService();
  runApp(
    UncontrolledProviderScope(container: container, child: const App()),
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final bgService = FlutterBackgroundService();
void startService() async {
  await bgService.configure(
    androidConfiguration: AndroidConfiguration(
      onStart: onStart,
      autoStart: false,
      isForegroundMode: true,
    ),
    iosConfiguration: IosConfiguration(
      autoStart: false,
      onForeground: onStart,
      onBackground: onIosBackground,
    ),
  );

  final isLocationPermission = await Permission.location.isGranted;
  if (isLocationPermission) {
    bgService.startService();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;StreamSubscription&amp;lt;Position&amp;gt;? positionSubscription;
Position? _position;

@pragma('vm:entry-point')
Future&amp;lt;void&amp;gt; onStart(ServiceInstance service) async {
  WidgetsFlutterBinding.ensureInitialized();
  final isLocationPermission = await Permission.location.isGranted;
  if (!isLocationPermission) return;

  if (service is AndroidServiceInstance) {
    service.setForegroundNotificationInfo(
      title: "Your space Location",
      content: "Location is being tracked",
    );
    service.setAsForegroundService();
  }

  _startLocationUpdates()

  service.on('stopService').listen((event) {
    positionSubscription?.cancel();
service.stopSelf();
  });
}

void _startLocationUpdates() {
  positionSubscription = Geolocator.getPositionStream(
    locationSettings: const LocationSettings(
      accuracy: LocationAccuracy.high,
      distanceFilter: LOCATION_UPDATE_DISTANCE,
    ),
  ).listen((position) {
    _position = position;
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@pragma('vm:entry-point')
bool onIosBackground(ServiceInstance service) {
  onStart(service);
  return true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
The app starts a background service that tracks the user’s location. It maintains this service in the background using flutter_background_service for Android and appropriate iOS configurations.&lt;/p&gt;

&lt;p&gt;3️⃣ &lt;strong&gt;Optimising battery usage&lt;/strong&gt;&lt;br&gt;
We prioritize battery efficiency while conducting background updates in our app.&lt;/p&gt;

&lt;p&gt;To achieve this, we request battery optimization permission from users. This allows the app to operate smoothly in the background without being terminated by the system's battery-saving measures.&lt;/p&gt;

&lt;p&gt;For Android, obtaining this permission is crucial for uninterrupted background operations. &lt;br&gt;
So you have to keep in mind that some of the devices do not allow direct battery restriction after allowing permission they want to enable manually battery restriction for apps from system settings.&lt;/p&gt;

&lt;p&gt;On iOS, we utilize background fetch and location updates to further enhance battery optimization.&lt;/p&gt;

&lt;p&gt;4️⃣ &lt;strong&gt;Real-time background updates&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For real-time location updates, we handle iOS separately to manage background update and battery optimisation&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;iOS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private func setUpLocation() {
    locationManager?.allowsBackgroundLocationUpdates = true
    locationManager?.pausesLocationUpdatesAutomatically = false
    locationManager?.startMonitoringSignificantLocationChanges()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let currentLocation = locations.last else { return }
    let now = Date().timeIntervalSince1970
    let lastUpdate = previousLocation?.timestamp.timeIntervalSince1970 ?? 0
    let timeDifference = now - lastUpdate
    if timeDifference &amp;lt; 60 { return }
    previousLocation = currentLocation

    let locationData: [String: Any] = [
        "latitude": currentLocation.coordinate.latitude,
        "longitude": currentLocation.coordinate.longitude,
        "timestamp": currentLocation.timestamp.timeIntervalSince1970 * 1000
    ]

    if let controller = window?.rootViewController as? FlutterViewController {
        let methodChannel = FlutterMethodChannel(name: "com.app_name/location", binaryMessenger: controller.binaryMessenger)
        methodChannel.invokeMethod("onLocationUpdate", arguments: locationData)
    }
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
    if status == .authorizedAlways || status == .authorizedWhenInUse {
        locationManager?.startMonitoringSignificantLocationChanges()
    } else {
        locationManager?.stopUpdatingLocation()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Flutter side:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const platform = MethodChannel('com.app_name/location');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;platform.setMethodCallHandler(_handleLocationUpdates);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;void&amp;gt; _handleLocationUpdates(MethodCall call) async {
  if (call.method == 'onLocationUpdate') {
    final Map&amp;lt;String, dynamic&amp;gt; locationData = Map&amp;lt;String, dynamic&amp;gt;.from(call.arguments);

    final double latitude = locationData['latitude'];
    final double longitude = locationData['longitude'];
    final DateTime timestamp = DateTime.fromMillisecondsSinceEpoch(locationData['timestamp'].toInt());

    // perform action required after getting location updates
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For real-time updates in Android, there's no need for native implementation; the geolocator will handle location updates by position that we declare before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Group Track simplifies location-based services for Flutter developers, making it easy to integrate real-time tracking with secure, efficient, and reliable performance. By addressing common pain points like accuracy, background services, battery optimization, and real-time updates, Group Track streamlines the process, helping developers build better apps faster.&lt;/p&gt;

&lt;p&gt;Here is the github repository, for more information check out this - &lt;a href="https://github.com/canopas/group-track-flutter" rel="noopener noreferrer"&gt;https://github.com/canopas/group-track-flutter&lt;/a&gt;&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>opensource</category>
      <category>location</category>
    </item>
  </channel>
</rss>
