Skip to content

Commit 25fbf26

Browse files
Updated the readme & fix the example project
1 parent 46a3ce2 commit 25fbf26

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,42 @@ import background_location_tracker
7474
}
7575
```
7676

77+
## Dart implementation
7778

78-
FAQ:
79+
Make sure you set the `@pragma('vm:entry-point')` to make sure you can find the callback in release.
80+
81+
```
82+
@pragma('vm:entry-point')
83+
void backgroundCallback() {
84+
BackgroundLocationTrackerManager.handleBackgroundUpdated(
85+
(data) async => Repo().update(data),
86+
);
87+
}
88+
89+
Future<void> main() async {
90+
WidgetsFlutterBinding.ensureInitialized();
91+
await BackgroundLocationTrackerManager.initialize(
92+
backgroundCallback,
93+
config: const BackgroundLocationTrackerConfig(
94+
loggingEnabled: true,
95+
androidConfig: AndroidConfig(
96+
notificationIcon: 'explore',
97+
trackingInterval: Duration(seconds: 4),
98+
distanceFilterMeters: null,
99+
),
100+
iOSConfig: IOSConfig(
101+
activityType: ActivityType.FITNESS,
102+
distanceFilterMeters: null,
103+
restartAfterKill: true,
104+
),
105+
),
106+
);
107+
108+
runApp(MyApp());
109+
}
110+
```
111+
112+
# FAQ:
79113

80114
#### I get a Unhandled Exception: MissingPluginException(No implementation found for method .... on channel ...)
81115

example/lib/main.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
88
import 'package:permission_handler/permission_handler.dart';
99
import 'package:shared_preferences/shared_preferences.dart';
1010

11-
void _backgroundCallback() =>
12-
BackgroundLocationTrackerManager.handleBackgroundUpdated(
13-
(data) async => Repo().update(data),
14-
);
11+
@pragma('vm:entry-point')
12+
void backgroundCallback() {
13+
BackgroundLocationTrackerManager.handleBackgroundUpdated(
14+
(data) async => Repo().update(data),
15+
);
16+
}
1517

1618
Future<void> main() async {
1719
WidgetsFlutterBinding.ensureInitialized();
1820
await BackgroundLocationTrackerManager.initialize(
19-
_backgroundCallback,
21+
backgroundCallback,
2022
config: const BackgroundLocationTrackerConfig(
2123
loggingEnabled: true,
2224
androidConfig: AndroidConfig(
@@ -31,6 +33,7 @@ Future<void> main() async {
3133
),
3234
),
3335
);
36+
3437
runApp(MyApp());
3538
}
3639

0 commit comments

Comments
 (0)