Skip to content

Commit dcb8cbe

Browse files
author
Arthur Abrantes
committed
1.1.0
1 parent ba793c4 commit dcb8cbe

20 files changed

Lines changed: 157 additions & 72 deletions

‎.env‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DEV_URLS_API_KEY = AIzaSyCh6OCFrssXSWPKXICqWp_eWdkOHcv1e8M
1010

1111
# cloud functions config
1212
EMULATE_CLOUD_FUNCTIONS = false
13-
HOST_IP_ADDRESS = 192.168.0.104
13+
HOST_IP_ADDRESS = 192.168.0.103
1414
CLOUD_FUNCTIONS_PORT = 5001
1515

1616
################################################################################

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ rundev: check-dev-env
6565
run: check-env
6666
$(FLUTTERRUN) \
6767
-v \
68-
--release \
68+
--debug \
6969
--flavor prod \
7070
--dart-define=IOS_GOOGLE_MAPS_API_KEY=$(IOS_GOOGLE_MAPS_API_KEY) \
7171
--dart-define=ANDROID_GOOGLE_MAPS_API_KEY=$(ANDROID_GOOGLE_MAPS_API_KEY) \

‎android/app/src/main/AndroidManifest.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@
5555
<!--@arthur added googleMapsApiKey so google maps sdk works-->
5656
<meta-data
5757
android:name="com.google.android.geo.API_KEY"
58-
android:value="AIzaSyDSncKvHZCRNVlb24bCQGJn2Ra9HrFjk7g" />
58+
android:value="AIzaSyDtewMXcgzwFyulh6SkPH7_aMRXRVQDLiA" />
5959
</application>
6060
</manifest>

‎ios/Runner/AppDelegate.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import GoogleMaps
3131
}
3232
// provide API key so google Maps SDK works for iOS
3333
// TODO: get from --dart-define
34-
GMSServices.provideAPIKey("AIzaSyALo1HaLc0mN0cwfChySKdz04zY9k-pGVk")
34+
GMSServices.provideAPIKey("AIzaSyCK58KogR8m_I_unlhint9mwQkAy-_Ft3g")
3535
GeneratedPluginRegistrant.register(with: self)
3636
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
3737
}

‎lib/app.dart‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ class _AppState extends State<App> {
101101
);
102102
}
103103
initializeModels();
104+
105+
// throw error if there is no connection, so Start screen can be pushed
106+
bool hasConnection = await connectivity.checkConnection();
107+
if (!hasConnection) {
108+
throw FirebaseAuthException(code: "network-error");
109+
}
110+
104111
// download user data so we can know whether client has an account and
105112
// decide to push Start or Home screens
106113
try {
@@ -177,8 +184,8 @@ class _AppState extends State<App> {
177184
// download client and trip data
178185
await user.downloadData(firebaseModel, notify: false);
179186
await tripModel.downloadData(
180-
firebase: firebaseModel,
181-
partner: partner,
187+
firebaseModel,
188+
partner,
182189
notify: false,
183190
);
184191
}
@@ -261,7 +268,8 @@ class _AppState extends State<App> {
261268
initialRoute: !firebase.isRegistered ||
262269
user.id == null ||
263270
(snapshot.hasError &&
264-
error.code == "user-initialization-error")
271+
(error.code == "user-initialization-error" ||
272+
error.code == "network-error"))
265273
? Start.routeName
266274
: Home.routeName,
267275
// pass appropriate arguments to routes

‎lib/models/connectivity.dart‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:io';
33

44
import 'package:connectivity/connectivity.dart';
55
import 'package:flutter/material.dart';
6-
import 'package:rider_frontend/styles.dart';
76
import 'package:rider_frontend/utils/utils.dart';
87

98
class ConnectivityModel extends ChangeNotifier {
@@ -17,8 +16,8 @@ class ConnectivityModel extends ChangeNotifier {
1716
// start listening for connectivity changes
1817
_connectivity = Connectivity();
1918
_connectivitySubscription = _connectivity.onConnectivityChanged
20-
.listen((e) async => await _checkConnection());
21-
_checkConnection();
19+
.listen((e) async => await checkConnection());
20+
checkConnection();
2221
}
2322

2423
@override
@@ -30,7 +29,7 @@ class ConnectivityModel extends ChangeNotifier {
3029
}
3130

3231
// checkConnection tests whether there is a connection
33-
Future<void> _checkConnection() async {
32+
Future<bool> checkConnection() async {
3433
bool previousHasConnection = _hasConnection;
3534

3635
try {
@@ -48,6 +47,8 @@ class ConnectivityModel extends ChangeNotifier {
4847
if (previousHasConnection != _hasConnection) {
4948
notifyListeners();
5049
}
50+
51+
return _hasConnection;
5152
}
5253

5354
Future<void> alertWhenOffline(BuildContext context, {String message}) async {

‎lib/models/trip.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ class TripModel extends ChangeNotifier {
144144
}
145145

146146
// downloadData sends requests to download data about current trips and partner
147-
Future<void> downloadData({
147+
Future<void> downloadData(
148148
FirebaseModel firebase,
149-
PartnerModel partner,
149+
PartnerModel partner, {
150150
bool notify = true,
151151
}) async {
152152
Trip trip;
@@ -164,7 +164,7 @@ class TripModel extends ChangeNotifier {
164164
// wait a little bit and try again
165165
if (trip.tripStatus == TripStatus.waitingPayment) {
166166
await Future.delayed(Duration(milliseconds: 500));
167-
return downloadData(firebase: firebase, partner: partner, notify: notify);
167+
return downloadData(firebase, partner, notify: notify);
168168
}
169169

170170
// if trip has already been completed, clear the model

‎lib/models/user.dart‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ class UserModel extends ChangeNotifier {
166166
}
167167
}
168168

169-
// updates user geocoding whenever they move at least 50 meters
170-
void updateGeocodingOnPositionChange() {
169+
// updates user geocoding whenever they move at least 5 meters
170+
void handlePositionUpdates() {
171171
try {
172172
Stream<Position> userPositionStream = Geolocator.getPositionStream(
173173
desiredAccuracy: LocationAccuracy.best,
174-
distanceFilter: 50,
174+
distanceFilter: 10,
175175
);
176176
// cancel previous subscription if it exists
177177
cancelPositionChangeSubscription();
178-
// subscribe to changes in position, updating position and gocoding on changes
178+
// subscribe to changes in position, updating position and geocoding on changes
179179
_positionSubscription = userPositionStream.listen((position) async {
180180
_position = position;
181181
await getGeocoding(position, notify: false);
@@ -200,7 +200,7 @@ class UserModel extends ChangeNotifier {
200200
geocoding.results.length > 0) {
201201
geocodingResult = geocoding.results[0];
202202
}
203-
// set user position
203+
// set user geocoding
204204
_geocoding = geocodingResult;
205205
if (notify) {
206206
notifyListeners();

‎lib/screens/defineRoute.dart‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,19 @@ class DefineRouteState extends State<DefineRoute> {
138138
return GoBackScaffold(
139139
resizeToAvoidBottomInset: false,
140140
lockScreen: lockScreen,
141-
onPressed: () => Navigator.pop(context, true),
141+
onPressed: () {
142+
// if user is not accessing this screen in 'edit' mode, clear pickUp and
143+
// dropOff points if they pop back to the previous screen. This way, when
144+
// they reopen this screen the next time around, "Localização atual selecionada"
145+
// will show up and correclty display their current location, as opposed ot
146+
// it not showing up and a previous current location being preselected as
147+
// their pickUP point
148+
if (widget.mode == DefineRouteMode.request) {
149+
widget.trip.updatePickUpAddres(null);
150+
widget.trip.updateDropOffAddres(null);
151+
}
152+
Navigator.pop(context, true);
153+
},
142154
children: [
143155
Text(
144156
"Escolha o ponto de partida e o destino.",

‎lib/screens/home.dart‎

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import 'package:rider_frontend/screens/start.dart';
2323
import 'package:rider_frontend/styles.dart';
2424
import 'package:rider_frontend/utils/utils.dart';
2525
import 'package:rider_frontend/vendors/firebaseFunctions/interfaces.dart';
26-
import 'package:rider_frontend/vendors/firebaseFunctions/methods.dart';
2726
import 'package:rider_frontend/vendors/firebaseDatabase/methods.dart';
2827
import 'package:rider_frontend/vendors/geolocator.dart';
2928
import '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

Comments
 (0)