File tree Expand file tree Collapse file tree 2 files changed +43
-6
lines changed Expand file tree Collapse file tree 2 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,42 @@ import background_location_tracker
74
74
}
75
75
```
76
76
77
+ ## Dart implementation
77
78
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:
79
113
80
114
#### I get a Unhandled Exception: MissingPluginException(No implementation found for method .... on channel ...)
81
115
Original file line number Diff line number Diff line change @@ -8,15 +8,17 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
8
8
import 'package:permission_handler/permission_handler.dart' ;
9
9
import 'package:shared_preferences/shared_preferences.dart' ;
10
10
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
+ }
15
17
16
18
Future <void > main () async {
17
19
WidgetsFlutterBinding .ensureInitialized ();
18
20
await BackgroundLocationTrackerManager .initialize (
19
- _backgroundCallback ,
21
+ backgroundCallback ,
20
22
config: const BackgroundLocationTrackerConfig (
21
23
loggingEnabled: true ,
22
24
androidConfig: AndroidConfig (
@@ -31,6 +33,7 @@ Future<void> main() async {
31
33
),
32
34
),
33
35
);
36
+
34
37
runApp (MyApp ());
35
38
}
36
39
You can’t perform that action at this time.
0 commit comments