Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions geolocator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.1.0

- Adds updatePositionStream API for changing parameters while a position stream is running.

## 14.0.2

- Adds section about `UIBackgroundModes` to the README.
Expand Down
21 changes: 12 additions & 9 deletions geolocator/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

<!-- Permissions options for the `location` group -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />

<application
Expand All @@ -28,21 +31,21 @@
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
Expand All @@ -51,4 +54,4 @@
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
</manifest>
46 changes: 23 additions & 23 deletions geolocator/example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>App</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.app</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>App</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
</dict>
</plist>
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>App</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.app</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>App</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>12.0</string>
</dict>
</plist>
31 changes: 26 additions & 5 deletions geolocator/example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -149,6 +149,7 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
2169DAB2B55B50BFEA564873 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -165,7 +166,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1020;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
97C146ED1CF9000F007C117D = {
Expand Down Expand Up @@ -206,12 +207,31 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
2169DAB2B55B50BFEA564873 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Copy Pods Resources";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
);
name = "Thin Binary";
outputPaths = (
Expand Down Expand Up @@ -244,6 +264,7 @@
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand Down Expand Up @@ -332,7 +353,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -415,7 +436,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -464,7 +485,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 4 additions & 0 deletions geolocator/example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
71 changes: 68 additions & 3 deletions geolocator/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'dart:async';
import 'dart:io' show Platform;

import 'package:baseflow_plugin_template/baseflow_plugin_template.dart';
import 'package:flutter/material.dart';

import 'package:baseflow_plugin_template/baseflow_plugin_template.dart';
import 'package:geolocator/geolocator.dart';

/// Defines the main theme color.
Expand Down Expand Up @@ -39,9 +40,11 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {

final GeolocatorPlatform _geolocatorPlatform = GeolocatorPlatform.instance;
final List<_PositionItem> _positionItems = <_PositionItem>[];
final ScrollController _scrollController = ScrollController();
StreamSubscription<Position>? _positionStreamSubscription;
StreamSubscription<ServiceStatus>? _serviceStatusStreamSubscription;
bool positionStreamStarted = false;
bool fastUpdates = false;

@override
void initState() {
Expand Down Expand Up @@ -120,6 +123,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
(context) => Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
body: ListView.builder(
controller: _scrollController,
itemCount: _positionItems.length,
itemBuilder: (context, index) {
final positionItem = _positionItems[index];
Expand Down Expand Up @@ -167,6 +171,17 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
: const Icon(Icons.pause),
),
sizedBox,
if (_positionStreamSubscription != null)
Column(
mainAxisSize: MainAxisSize.min,
children: [
FloatingActionButton(
onPressed: _toggleUpdateSpeed,
child: const Icon(Icons.speed),
),
sizedBox,
],
),
FloatingActionButton(
onPressed: _getCurrentPosition,
child: const Icon(Icons.my_location),
Expand Down Expand Up @@ -252,9 +267,12 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
return true;
}

void _updatePositionList(_PositionItemType type, String displayValue) {
void _updatePositionList(_PositionItemType type, String displayValue) async {
_positionItems.add(_PositionItem(type, displayValue));
setState(() {});
await Future.delayed(const Duration(milliseconds: 50));
if (!mounted) return;
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
}

bool _isListening() => !(_positionStreamSubscription == null ||
Expand Down Expand Up @@ -299,7 +317,19 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {

void _toggleListening() {
if (_positionStreamSubscription == null) {
final positionStream = _geolocatorPlatform.getPositionStream();
final settings = AndroidSettings(
distanceFilter: 50,
foregroundNotificationConfig: const ForegroundNotificationConfig(
notificationTitle: 'Geolocator is tracking your trip',
notificationText:
'This is a persistent notification and is used to start a foreground service.',
enableWifiLock: true,
enableWakeLock: true,
setOngoing: true,
),
);
final positionStream =
_geolocatorPlatform.getPositionStream(locationSettings: settings);
_positionStreamSubscription = positionStream.handleError((error) {
_positionStreamSubscription?.cancel();
_positionStreamSubscription = null;
Expand Down Expand Up @@ -331,6 +361,41 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
});
}

Future<void> _toggleUpdateSpeed() async {
fastUpdates = !fastUpdates;

final LocationSettings settings;
if (Platform.isAndroid) {
settings = AndroidSettings(
accuracy: LocationAccuracy.best,
distanceFilter: 0,
intervalDuration: Duration(seconds: fastUpdates ? 1 : 10),
forceLocationManager: false,
useMSLAltitude: true,
);
} else if (Platform.isIOS) {
settings = AppleSettings(
accuracy: LocationAccuracy.best,
distanceFilter: fastUpdates ? 0 : 50,
activityType: ActivityType.fitness,
showBackgroundLocationIndicator: false,
allowBackgroundLocationUpdates: false,
);
} else {
settings = LocationSettings(
accuracy: LocationAccuracy.best,
distanceFilter: fastUpdates ? 0 : 50,
);
}

await _geolocatorPlatform.updatePositionStream(locationSettings: settings);

_updatePositionList(
_PositionItemType.log,
'Position updates ${fastUpdates ? 'sped up' : 'slowed down'}.',
);
}

@override
void dispose() {
if (_positionStreamSubscription != null) {
Expand Down
6 changes: 3 additions & 3 deletions geolocator/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
sdk: ^3.5.0

dependencies:
baseflow_plugin_template: ^2.1.2
baseflow_plugin_template: ^2.2.0

flutter:
sdk: flutter
Expand All @@ -24,11 +24,11 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.1+1
cupertino_icons: ^1.0.8

# The following adds the URL Launcher plugin which is used by
# the demo application to open the links in the web browser.
url_launcher: ^6.0.0-nullsafety.1
url_launcher: ^6.3.1

dev_dependencies:
flutter_test:
Expand Down
12 changes: 12 additions & 0 deletions geolocator/lib/geolocator.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:flutter/foundation.dart';

import 'package:geolocator_android/geolocator_android.dart';
import 'package:geolocator_apple/geolocator_apple.dart';
import 'package:geolocator_platform_interface/geolocator_platform_interface.dart';
Expand Down Expand Up @@ -192,6 +193,17 @@ class Geolocator {
locationSettings: locationSettings,
);

/// Updates the parameters of the active position stream.
///
/// Throws a [NotSubscribedException] when there is no active position stream
/// to update.
static Future<void> updatePositionStream({
required LocationSettings locationSettings,
}) =>
GeolocatorPlatform.instance.updatePositionStream(
locationSettings: locationSettings,
);

/// Returns a [Future] containing a [LocationAccuracyStatus]
/// When the user has given permission for approximate location,
/// [LocationAccuracyStatus.reduced] will be returned, if the user has
Expand Down
Loading
Loading