Skip to content

Commit

Permalink
fixed permission handling & improved loading screens
Browse files Browse the repository at this point in the history
  • Loading branch information
zamirszn committed Sep 1, 2022
1 parent ab2554f commit 39a6487
Show file tree
Hide file tree
Showing 15 changed files with 376 additions and 223 deletions.
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GeemApp extends StatelessWidget {
fontFamily: "PulpDisplay",
scrollbarTheme: ScrollbarThemeData(
thickness: MaterialStateProperty.all(7),
thumbColor: MaterialStateProperty.all(appColor),
thumbColor: MaterialStateProperty.all(Colors.white),
),
primaryColor: geemBlue,
),
Expand Down
10 changes: 10 additions & 0 deletions lib/network/internet_connectivity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ import 'package:flutter/material.dart';
import 'package:geem/util/colors.dart';
import 'package:overlay_support/overlay_support.dart';

// checkInternetStream() {
// checkInternetSubscription =
// InternetConnectionChecker().onStatusChange.listen((internetStatus) {
// final hasInterent_ = internetStatus == InternetConnectionStatus.connected;
// hasInternet = hasInterent_;

// // hasInternet ? getForecastByLocation() : () {} //can set state here
// });
// }

// checkInternet() async {
// hasInterent = await InternetConnectionChecker().hasConnection;

Expand Down
32 changes: 25 additions & 7 deletions lib/network/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,43 @@ import 'package:location/location.dart';

var userLocation = Location();
// enable user's location service
Future enableUserLocation() async {
Future<bool> enableUserLocation() async {
bool hasLocation = false;
var locationServiceIsEnabled = await userLocation.serviceEnabled();
if (!locationServiceIsEnabled) {

if (locationServiceIsEnabled == true) {
hasLocation = true;
} else if (locationServiceIsEnabled == false) {
locationServiceIsEnabled = await userLocation.requestService();
if (!locationServiceIsEnabled) {
return;
if (locationServiceIsEnabled != true) {
hasLocation = false;
} else if (locationServiceIsEnabled == true) {
hasLocation = true;
}
}

return hasLocation;
}

Future getUserLocationPermission() async {
Future<bool> getUserLocationPermission() async {
// get users location permission
bool hasLocationPermission = false;

var locationPermissionGranted = await userLocation.hasPermission();
if (locationPermissionGranted == PermissionStatus.denied) {
if (locationPermissionGranted == PermissionStatus.granted) {
hasLocationPermission = true;

} else if (locationPermissionGranted == PermissionStatus.denied) {
locationPermissionGranted = await userLocation.requestPermission();
if (locationPermissionGranted != PermissionStatus.granted) {
return;
hasLocationPermission = false;

}
else if (locationPermissionGranted == PermissionStatus.granted){
hasLocationPermission = true;
}
}
return hasLocationPermission;
}

Future<LocationData> getUserLocation() async {
Expand Down
60 changes: 60 additions & 0 deletions lib/ui/screens/error_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:flutter/material.dart';
import 'package:lottie/lottie.dart';

class ErrorScreen extends StatelessWidget {
const ErrorScreen({
Key? key,
required this.deviceScreen,
required this.onPressed,
}) : super(key: key);

final Size deviceScreen;
final Function onPressed;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Lottie.asset(
animate: true,
"lottie/cloud_attention.json",
width: deviceScreen.width / 2,
),
),
SizedBox(
width: deviceScreen.width / 1.2,
child: const Text(
"Please make sure you have location & internet service enabled",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
),
),
),
TextButton.icon(
icon: const Icon(
Icons.refresh_outlined,
color: Colors.black,
),
onPressed: () {
onPressed();
},
label: const Text(
"Retry",
style: TextStyle(
fontSize: 15,
color: Colors.black,
),
)),
],
),
),
);
}
}
Loading

0 comments on commit 39a6487

Please sign in to comment.