Skip to content

Commit

Permalink
Merge pull request #1 from EmmanuelTobi/master
Browse files Browse the repository at this point in the history
Location Permission feature setups and implementations for PetShop
  • Loading branch information
thenifemi committed Jun 5, 2020
2 parents 31d79a1 + 9d60c36 commit 321152b
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 41 deletions.
138 changes: 97 additions & 41 deletions lib/screens/settings_screens/passwordSecurity.dart
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter_svg/svg.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:mollet/screens/settings_screens/changePassword.dart';
import 'package:mollet/utils/colors.dart';
import 'package:mollet/utils/permission_handler.dart';
import 'package:permission_handler/permission_handler.dart';

class SecurityScreen extends StatelessWidget {
@override
Expand Down Expand Up @@ -30,52 +32,106 @@ class SecurityScreen extends StatelessWidget {
),
centerTitle: true,
),
body: Container(
padding: const EdgeInsets.only(right: 20.0, left: 20.0),
child: Column(children: <Widget>[
SizedBox(
height: 60,
width: double.infinity,
child: RawMaterialButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => ChangePasswordScreen(),
),
);
},
child: Row(
children: <Widget>[
Container(
padding: const EdgeInsets.only(right: 20.0),
child: SvgPicture.asset(
"assets/images/key.svg",
height: 20,
color: MColors.textGrey,
),
),
Expanded(
child: Text(
"Change password",
style: GoogleFonts.montserrat(
color: MColors.primaryPurple,
fontSize: 15.0,
body: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.only(right: 20.0, left: 20.0),
child: Column(children: <Widget>[
SizedBox(
height: 60,
width: double.infinity,
child: RawMaterialButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => ChangePasswordScreen(),
),
),
),
Icon(
Icons.arrow_forward_ios,
color: MColors.textGrey,
size: 16.0,
);
},
child: Row(
children: <Widget>[
Container(
padding: const EdgeInsets.only(right: 20.0),
child: SvgPicture.asset(
"assets/images/key.svg",
height: 20,
color: MColors.textGrey,
),
),
Expanded(
child: Text(
"Change password",
style: GoogleFonts.montserrat(
color: MColors.primaryPurple,
fontSize: 15.0,
),
),
),
Icon(
Icons.arrow_forward_ios,
color: MColors.textGrey,
size: 16.0,
),
],
),
],
),
),
),
Divider(
height: 1.0,
),
]),
),
Divider(
height: 1.0,

Container(
padding: const EdgeInsets.only(right: 20.0, left: 20.0),
child: Column(children: <Widget>[
SizedBox(
height: 60,
width: double.infinity,
child: RawMaterialButton(
onPressed: () {

PermissionUtil.isLocationServiceAndPermissionsActive().then((value) {
if(value == false) {
PermissionUtil.requestPermission(PermissionGroup.location);
}
}
);
},
child: Row(
children: <Widget>[
Container(
padding: const EdgeInsets.only(right: 20.0),
child: SvgPicture.asset(
"assets/images/key.svg",
height: 20,
color: MColors.textGrey,
),
),
Expanded(
child: Text(
"Location feature",
style: GoogleFonts.montserrat(
color: MColors.primaryPurple,
fontSize: 15.0,
),
),
),
Icon(
Icons.arrow_forward_ios,
color: MColors.textGrey,
size: 16.0,
),
],
),
),
),
Divider(
height: 1.0,
),
]),
),
]),
],
),
);
}
Expand Down
47 changes: 47 additions & 0 deletions lib/utils/permission_handler.dart
@@ -0,0 +1,47 @@
import 'package:geolocation/geolocation.dart';
import 'package:permission_handler/permission_handler.dart';

class PermissionUtil {

// Allows request any permission in the Permission Group with this method
static Future<bool> requestPermission(PermissionGroup permission) async {
final PermissionHandler _permissionHandler = PermissionHandler();
_permissionHandler.shouldShowRequestPermissionRationale(permission);
final result = await _permissionHandler.requestPermissions([permission]);
if (result[permission] == PermissionStatus.granted) {
return true;
}
return false;
}

// Allows checks on any permission in the Permission Group with this method
static Future<bool> hasPermission(PermissionGroup permission) async {
final PermissionHandler _permissionHandler = PermissionHandler();
var permissionStatus = await _permissionHandler.checkPermissionStatus(permission);
return permissionStatus == PermissionStatus.granted;
}

//below is about gps and location services checks

static Future<bool> isGpsServiceActive() async {
final GeolocationResult gps = await Geolocation.isLocationOperational();
if(!gps.isSuccessful) {
await Geolocation.enableLocationServices()
.then((GeolocationResult onValue) async {
if (onValue.isSuccessful) return true;
else return false;
});
}
return true;
}

static Future<bool> isLocationServiceAndPermissionsActive() async {
final GeolocationResult gpsServiceActive = await Geolocation.isLocationOperational();
final gpsPermissionGranted = await PermissionUtil.hasPermission(PermissionGroup.locationWhenInUse);

if(gpsServiceActive.isSuccessful == false || gpsPermissionGranted == false)
return false;

return true;
}
}
3 changes: 3 additions & 0 deletions pubspec.yaml
Expand Up @@ -29,6 +29,9 @@ dependencies:
provider:
bubble_tab_indicator: ^0.1.4
carousel_slider: ^2.0.0
permission_handler: ^3.1.0
geolocator: ^5.3.1
geolocation: ^1.1.2

flutter_icons:
android: true
Expand Down

0 comments on commit 321152b

Please sign in to comment.