@@ -39,11 +39,13 @@ Future<void> main() async {
39
39
40
40
@override
41
41
class MyApp extends StatefulWidget {
42
+ const MyApp ({Key ? key}) : super (key: key);
43
+
42
44
@override
43
- _MyAppState createState () => _MyAppState ();
45
+ MyAppState createState () => MyAppState ();
44
46
}
45
47
46
- class _MyAppState extends State <MyApp > {
48
+ class MyAppState extends State <MyApp > {
47
49
var isTracking = false ;
48
50
49
51
Timer ? _timer;
@@ -69,51 +71,47 @@ class _MyAppState extends State<MyApp> {
69
71
appBar: AppBar (
70
72
title: const Text ('Plugin example app' ),
71
73
),
72
- body: Container (
74
+ body: SizedBox (
73
75
width: double .infinity,
74
76
child: Column (
75
77
children: [
76
78
Expanded (
77
79
child: Column (
78
80
children: [
79
81
MaterialButton (
80
- child: const Text ('Request location permission' ),
81
82
onPressed: _requestLocationPermission,
83
+ child: const Text ('Request location permission' ),
82
84
),
83
85
if (Platform .isAndroid) ...[
84
- const Text (
85
- 'Permission on android is only needed starting from sdk 33.' ),
86
+ const Text ('Permission on android is only needed starting from sdk 33.' ),
86
87
],
87
88
MaterialButton (
88
- child: const Text ('Request Notification permission' ),
89
89
onPressed: _requestNotificationPermission,
90
+ child: const Text ('Request Notification permission' ),
90
91
),
91
92
MaterialButton (
92
93
child: const Text ('Send notification' ),
93
- onPressed: () =>
94
- sendNotification ('Hello from another world' ),
94
+ onPressed: () => sendNotification ('Hello from another world' ),
95
95
),
96
96
MaterialButton (
97
- child: const Text ('Start Tracking' ),
98
97
onPressed: isTracking
99
98
? null
100
99
: () async {
101
- await BackgroundLocationTrackerManager
102
- .startTracking ();
100
+ await BackgroundLocationTrackerManager .startTracking ();
103
101
setState (() => isTracking = true );
104
102
},
103
+ child: const Text ('Start Tracking' ),
105
104
),
106
105
MaterialButton (
107
- child: const Text ('Stop Tracking' ),
108
106
onPressed: isTracking
109
107
? () async {
110
108
await LocationDao ().clear ();
111
109
await _getLocations ();
112
- await BackgroundLocationTrackerManager
113
- .stopTracking ();
110
+ await BackgroundLocationTrackerManager .stopTracking ();
114
111
setState (() => isTracking = false );
115
112
}
116
113
: null ,
114
+ child: const Text ('Stop Tracking' ),
117
115
),
118
116
],
119
117
),
@@ -125,8 +123,8 @@ class _MyAppState extends State<MyApp> {
125
123
),
126
124
const Text ('Locations' ),
127
125
MaterialButton (
128
- child: const Text ('Refresh locations' ),
129
126
onPressed: _getLocations,
127
+ child: const Text ('Refresh locations' ),
130
128
),
131
129
Expanded (
132
130
child: Builder (
@@ -188,8 +186,7 @@ class _MyAppState extends State<MyApp> {
188
186
189
187
void _startLocationsUpdatesStream () {
190
188
_timer? .cancel ();
191
- _timer = Timer .periodic (
192
- const Duration (milliseconds: 250 ), (timer) => _getLocations ());
189
+ _timer = Timer .periodic (const Duration (milliseconds: 250 ), (timer) => _getLocations ());
193
190
}
194
191
}
195
192
@@ -220,15 +217,12 @@ class LocationDao {
220
217
221
218
SharedPreferences ? _prefs;
222
219
223
- Future <SharedPreferences > get prefs async =>
224
- _prefs ?? = await SharedPreferences .getInstance ();
220
+ Future <SharedPreferences > get prefs async => _prefs ?? = await SharedPreferences .getInstance ();
225
221
226
222
Future <void > saveLocation (BackgroundLocationUpdateData data) async {
227
223
final locations = await getLocations ();
228
- locations.add (
229
- '${DateTime .now ().toIso8601String ()} ${data .lat },${data .lon }' );
230
- await (await prefs)
231
- .setString (_locationsKey, locations.join (_locationSeparator));
224
+ locations.add ('${DateTime .now ().toIso8601String ()} ${data .lat },${data .lon }' );
225
+ await (await prefs).setString (_locationsKey, locations.join (_locationSeparator));
232
226
}
233
227
234
228
Future <List <String >> getLocations () async {
0 commit comments