@@ -23,7 +23,6 @@ import 'package:rider_frontend/screens/start.dart';
2323import 'package:rider_frontend/styles.dart' ;
2424import 'package:rider_frontend/utils/utils.dart' ;
2525import 'package:rider_frontend/vendors/firebaseFunctions/interfaces.dart' ;
26- import 'package:rider_frontend/vendors/firebaseFunctions/methods.dart' ;
2726import 'package:rider_frontend/vendors/firebaseDatabase/methods.dart' ;
2827import 'package:rider_frontend/vendors/geolocator.dart' ;
2928import 'package:rider_frontend/widgets/confirmTripWidget.dart' ;
@@ -87,7 +86,8 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
8786 // asks them to reshare. The function is only defined once the tree has been
8887 // built though, to avoid exceptions of trying to ask for location permission
8988 // simultaneously. After all, we already ask for them in initState.
90- if (didChangeAppLifecycleCallback != null ) {
89+ if (didChangeAppLifecycleCallback != null &&
90+ state == AppLifecycleState .resumed) {
9191 didChangeAppLifecycleCallback ();
9292 }
9393 }
@@ -109,7 +109,6 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
109109
110110 // add listeners after tree is built and we have context
111111 WidgetsBinding .instance.addPostFrameCallback ((_) async {
112- // after finishing _getUserPosition,
113112 userPositionFuture.then ((position) async {
114113 if (position != null ) {
115114 // user retrieved lat and lng to set maps camera view. notifying is
@@ -177,7 +176,7 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
177176 final screenWidth = MediaQuery .of (context).size.width;
178177 TripModel trip = Provider .of <TripModel >(context, listen: false );
179178 UserModel user = Provider .of <UserModel >(context, listen: false );
180- GoogleMapsModel googleMaps = Provider .of <GoogleMapsModel >(context);
179+ PartnerModel partner = Provider .of <PartnerModel >(context, listen : false );
181180 FirebaseModel firebase = Provider .of <FirebaseModel >(context);
182181 ConnectivityModel connectivity = Provider .of <ConnectivityModel >(context);
183182
@@ -190,12 +189,14 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
190189 // download user data
191190 try {
192191 user.downloadData (firebase);
193- trip.downloadData ();
192+ trip.downloadData (firebase, partner );
194193 } catch (e) {}
195194 // save fcm token to database
196195 firebase.messaging.getToken ().then (
197196 (token) => saveTokenToDatabase (token),
198197 );
198+ // update user position
199+ _getUserPosition ();
199200 }
200201 }
201202
@@ -232,12 +233,21 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
232233 // so if user stops sharing location or disable notificatoin, we will know.
233234 if (didChangeAppLifecycleCallback == null ) {
234235 didChangeAppLifecycleCallback = () async {
236+ Position userPos;
235237 try {
236- await determineUserPosition ();
237- } catch (e) {
238+ userPos = await determineUserPosition ();
239+ if (userPos != null ) {
240+ // if user has not stopped sharing location, call handlePositionUpdates so
241+ // we are sure we're listening to location updates, just in case the OS
242+ // decided to kill the process while the app was in the background.
243+ widget.user.handlePositionUpdates ();
244+ }
245+ } catch (_) {
246+ // if user stopped sharing location, trigger getUserPosition
238247 _getUserPosition ();
239248 }
240249
250+ // ask user to reactivate notificaitons if they stopped them
241251 await firebase.requestNotifications (context);
242252
243253 // on android, workaround the google maps issue of not displaying the
@@ -254,32 +264,33 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
254264 drawer: Menu (),
255265 body: Stack (
256266 children: [
257- GoogleMap (
258- myLocationButtonEnabled: googleMaps.myLocationButtonEnabled,
259- myLocationEnabled: googleMaps.myLocationEnabled,
260- trafficEnabled: false ,
261- zoomControlsEnabled: false ,
262- mapType: MapType .normal,
263- initialCameraPosition: CameraPosition (
264- target: googleMaps.initialCameraLatLng ??
265- LatLng (- 17.217600 , - 46.874621 ), // defaults to paracatu
266- zoom: googleMaps.initialZoom ?? 16.5 ,
267- ),
268- padding: EdgeInsets .only (
269- top: googleMaps.googleMapsTopPadding ?? screenHeight / 12 ,
270- bottom:
271- googleMaps.googleMapsBottomPadding ?? screenHeight / 8.5 ,
272- left: screenWidth / 20 ,
273- right: screenWidth / 20 ,
274- ),
275- onMapCreated: (c) async {
276- await googleMaps.onMapCreatedCallback (c, notify: false );
277- // call _redrawUIOnTripUpdate so UI is updated only when maps is ready
278- await _redrawUIOnTripUpdate (context);
279- },
280- polylines: Set <Polyline >.of (googleMaps.polylines.values),
281- markers: googleMaps.markers,
282- ),
267+ Consumer <GoogleMapsModel >(builder: (context, g, _) {
268+ return GoogleMap (
269+ myLocationButtonEnabled: g.myLocationButtonEnabled,
270+ myLocationEnabled: g.myLocationEnabled,
271+ trafficEnabled: false ,
272+ zoomControlsEnabled: false ,
273+ mapType: MapType .normal,
274+ initialCameraPosition: CameraPosition (
275+ target: g.initialCameraLatLng ??
276+ LatLng (- 17.217600 , - 46.874621 ), // defaults to paracatu
277+ zoom: g.initialZoom ?? 16.5 ,
278+ ),
279+ padding: EdgeInsets .only (
280+ top: g.googleMapsTopPadding ?? screenHeight / 12 ,
281+ bottom: g.googleMapsBottomPadding ?? screenHeight / 8.5 ,
282+ left: screenWidth / 20 ,
283+ right: screenWidth / 20 ,
284+ ),
285+ onMapCreated: (c) async {
286+ await g.onMapCreatedCallback (c, notify: false );
287+ // call _redrawUIOnTripUpdate so UI is updated only when maps is ready
288+ await _redrawUIOnTripUpdate (context);
289+ },
290+ polylines: Set <Polyline >.of (g.polylines.values),
291+ markers: g.markers,
292+ );
293+ }),
283294 Consumer <UserModel >(builder: (context, u, _) {
284295 return Stack (
285296 children: [
@@ -362,7 +373,7 @@ class HomeState extends State<Home> with WidgetsBindingObserver {
362373 // if we could get position, make sure to resubscribe to position changes
363374 // again, as the subscription may have been cancelled if user stopped
364375 // sharing location.
365- widget.user.updateGeocodingOnPositionChange ();
376+ widget.user.handlePositionUpdates ();
366377 return pos;
367378 }
368379
0 commit comments