1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:flutter_dotenv/flutter_dotenv.dart' ;
3
3
import 'package:flutter_bloc/flutter_bloc.dart' ;
4
+ import 'package:grid_frontend/services/android_background_task.dart' ;
4
5
import 'package:path_provider/path_provider.dart' ;
5
6
import 'package:provider/provider.dart' ;
6
7
import 'package:shared_preferences/shared_preferences.dart' ;
@@ -36,10 +37,16 @@ import 'package:grid_frontend/blocs/contacts/contacts_bloc.dart';
36
37
import 'package:grid_frontend/blocs/groups/groups_bloc.dart' ;
37
38
38
39
import 'package:grid_frontend/widgets/version_wrapper.dart' ;
40
+ import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
41
+
42
+
43
+
39
44
40
45
void main () async {
41
46
WidgetsFlutterBinding .ensureInitialized ();
42
47
48
+ bg.BackgroundGeolocation .registerHeadlessTask (headlessTask);
49
+
43
50
// Load .env file
44
51
await dotenv.load (fileName: ".env" );
45
52
@@ -60,6 +67,7 @@ void main() async {
60
67
await client.init ();
61
68
62
69
// Attempt to restore session
70
+ // TODO: this code chunk may do nothing actually
63
71
final prefs = await SharedPreferences .getInstance ();
64
72
String ? token = prefs.getString ('token' );
65
73
@@ -72,6 +80,7 @@ void main() async {
72
80
}
73
81
}
74
82
83
+
75
84
// Initialize repositories
76
85
final userRepository = UserRepository (databaseService);
77
86
final roomRepository = RoomRepository (databaseService);
@@ -80,7 +89,7 @@ void main() async {
80
89
final userKeysRepository = UserKeysRepository (databaseService);
81
90
final locationManager = LocationManager ();
82
91
// Initialize services
83
- final userService = UserService (client, locationRepository);
92
+ final userService = UserService (client, locationRepository, sharingPreferencesRepository );
84
93
final roomService = RoomService (client, userService, userRepository, userKeysRepository, roomRepository, locationRepository, sharingPreferencesRepository, locationManager);
85
94
86
95
final messageParser = MessageParser ();
@@ -145,6 +154,7 @@ void main() async {
145
154
mapBloc: context.read <MapBloc >(),
146
155
locationRepository: context.read <LocationRepository >(),
147
156
userLocationProvider: context.read <UserLocationProvider >(),
157
+ sharingPreferencesRepository: context.read <SharingPreferencesRepository >(),
148
158
),
149
159
),
150
160
BlocProvider <GroupsBloc >(
@@ -169,6 +179,7 @@ void main() async {
169
179
locationRepository,
170
180
context.read <GroupsBloc >(),
171
181
context.read <UserLocationProvider >(),
182
+ context.read <SharingPreferencesRepository >(),
172
183
)..startSync (),
173
184
update: (context, mapBloc, contactsBloc, groupsBloc, previous) =>
174
185
previous ?? SyncManager (
@@ -182,6 +193,7 @@ void main() async {
182
193
locationRepository,
183
194
groupsBloc,
184
195
context.read <UserLocationProvider >(),
196
+ sharingPreferencesRepository,
185
197
)..startSync (),
186
198
),
187
199
],
0 commit comments