Build a Location Service in Flutter

Last updated 2 years ago by Dane Mackier


Getting your location in Flutter is an easy task. This tutorial will show you how to wrap the location package into a service that’s easy to consume in your application.

Create a new Flutter project and follow along.


Provider is my default dependency provider/state management solution so we’ll use that as well. We’ll add both packages to the pubspec.

provider: ^3.0.0 location: ^2.3.5


Add the location permission into the AndroidManifest.xml manifest outside of the application tag.

... <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application android:name="" android:label="The Guardian" android:icon="@mipmap/ic_launcher"> ... </application> ...

Update your file to this

android.enableJetifier=true android.useAndroidX=true org.gradle.jvmargs=-Xmx1536M

Update your build.gradle file dependencies to this

dependencies { classpath '' classpath '' }

And make sure your compileSdkVersion is 28.


Add the Location Permissions to your info plist with the appropriate Messages.

<key>NSLocationWhenInUseUsageDescription</key> <string>This app requires access to your location for FilledStacks tutorial.</string> <key>NSLocationAlwaysUsageDescription</key> <string>This app requires access to your location for FilledStacks tutorial.</string>

That’s all the setup done. If you’re running into AndroidX problems make sure to migrate or use an older version of this package if you don’t want to migrate.

Service Implementation

If there’s one thing I can recommend is to read up on the Single Responsibility Principle. Based on this I’ve made it a habit to architect my apps using single-purpose services that I inject/locate where required. Let’s create our LocationService. This service will:

  1. Provider a stream of continuous updates we can depend on
  2. Provider a function to do a once off request for the current location
Read full Article