request_permission on location

location
Elham Rababah 5 years ago
parent c7c51ff55a
commit fcfb19963c

@ -5,6 +5,8 @@
In most cases you can leave this as-is, but you if you want to provide In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. --> FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application <application
android:name="io.flutter.app.FlutterApplication" android:name="io.flutter.app.FlutterApplication"
android:label="driver App" android:label="driver App"

@ -1,14 +1,14 @@
import 'package:driverapp/config/config.dart'; import 'package:driverapp/config/config.dart';
import 'package:driverapp/core/model/orders/deliverd_order_req_model.dart';
import 'package:driverapp/core/model/orders/deliverd_order_res_model.dart';
import 'package:driverapp/core/model/orders/next_order_request_model.dart'; import 'package:driverapp/core/model/orders/next_order_request_model.dart';
import 'package:driverapp/core/model/orders/pending_orders_req_model.dart'; import 'package:driverapp/core/model/orders/pending_orders_req_model.dart';
import 'package:driverapp/core/model/orders/pending_orders_res_model.dart'; import 'package:driverapp/core/model/orders/pending_orders_res_model.dart';
import 'package:driverapp/core/model/orders/update_order_status_request_model.dart'; import 'package:driverapp/core/model/orders/update_order_status_request_model.dart';
import 'package:driverapp/core/model/scan_qr/scan_qr_request_model.dart'; import 'package:driverapp/core/model/scan_qr/scan_qr_request_model.dart';
import 'package:driverapp/core/service/base_service.dart'; import 'package:driverapp/core/service/base_service.dart';
import 'package:driverapp/core/model/orders/deliverd_order_req_model.dart';
import 'package:driverapp/uitl/utils.dart'; import 'package:driverapp/uitl/utils.dart';
import 'package:location/location.dart'; import 'package:location/location.dart';
import 'package:driverapp/core/model/orders/deliverd_order_res_model.dart';
class OrdersService extends BaseService { class OrdersService extends BaseService {
List<PendingOrdersRes> _orders = List(); List<PendingOrdersRes> _orders = List();
@ -30,32 +30,37 @@ class OrdersService extends BaseService {
); );
Future getPendingOrders() async { Future getPendingOrders() async {
// if (await Utils.isLocationPermissionGranted()) {
LocationData loc = await Utils.getLocation(); LocationData loc = await Utils.getLocation();
PendingOrders _requestGetPendingOrders = PendingOrders(
searchKey: "", if (loc != null) {
pageSize: 0, PendingOrders _requestGetPendingOrders = PendingOrders(
pageIndex: 0, searchKey: "",
latitude: loc.latitude.toString(), pageSize: 0,
longitude: loc.longitude.toString(), pageIndex: 0,
); latitude: loc.latitude.toString(),
hasError = false; longitude: loc.longitude.toString(),
try { );
await baseAppClient.post(GET_ALL_ORDERS, hasError = false;
onSuccess: (dynamic response, int statusCode) { try {
_orders.clear(); await baseAppClient.post(GET_ALL_ORDERS,
response['PatientER_Delivery_GetAllOrderList'].forEach((order) { onSuccess: (dynamic response, int statusCode) {
_orders.add(PendingOrdersRes.fromJson(order)); _orders.clear();
}); response['PatientER_Delivery_GetAllOrderList'].forEach((order) {
}, onFailure: (String error, int statusCode) { _orders.add(PendingOrdersRes.fromJson(order));
});
}, onFailure: (String error, int statusCode) {
hasError = true;
super.error = error;
}, body: _requestGetPendingOrders.toJson());
} catch (e) {
hasError = true; hasError = true;
super.error = error; super.error = error;
}, body: _requestGetPendingOrders.toJson());
} catch (e) {
hasError = true;
super.error = error;
throw e; throw e;
}
} }
// }
} }
Future insertOrder(ScanQrRequestModel _scanQrRequestModel) async { Future insertOrder(ScanQrRequestModel _scanQrRequestModel) async {

@ -41,6 +41,12 @@ class _DashboardScreenState extends State<DashboardScreen> {
super.didChangeDependencies(); super.didChangeDependencies();
} }
@override
void initState() {
super.initState();
Utils.getLocationPermission();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
int orderId; int orderId;
@ -53,463 +59,463 @@ class _DashboardScreenState extends State<DashboardScreen> {
child: ListView( child: ListView(
children: <Widget>[ children: <Widget>[
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Padding( Padding(
padding: EdgeInsets.all(16.0), padding: EdgeInsets.all(16.0),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
SafeArea( SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
TranslationBase.of(context).haveGreatDay,
style: TextStyle(
fontSize: 14.5,
color: Color(0xff636363),
fontWeight: FontWeight.w300),
),
Padding(
padding: EdgeInsets.only(top: 4.5),
child: Text(
_authenticationViewModel.user.userName,
style: TextStyle(
fontSize: 22.0,
color: Hexcolor("#343333"),
fontWeight: FontWeight.bold),
),
),
],
),
),
],
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: SafeArea(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Text( InkWell(
TranslationBase.of(context).haveGreatDay, child: CircleAvatar(
style: TextStyle( radius: 25.5,
fontSize: 14.5, backgroundColor: Color(0xff30B7B9),
color: Color(0xff636363), child: CircleAvatar(
fontWeight: FontWeight.w300), backgroundColor: Color(0xff30B7B9),
), maxRadius: 26.0,
Padding( child: Image.asset(
padding: EdgeInsets.only(top: 4.5), 'assets/images/driver.png',
child: Text( fit: BoxFit.contain,
_authenticationViewModel.user.userName, ),
style: TextStyle( ),
fontSize: 22.0,
color: Hexcolor("#343333"),
fontWeight: FontWeight.bold),
), ),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingPage(
driverName: _authenticationViewModel
.user.userName,
driverID: _authenticationViewModel
.user.userID)));
},
), ),
], ],
), ),
), ),
],
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: SafeArea(
child: Column(
children: <Widget>[
InkWell(
child: CircleAvatar(
radius: 25.5,
backgroundColor: Color(0xff30B7B9),
child: CircleAvatar(
backgroundColor: Color(0xff30B7B9),
maxRadius: 26.0,
child: Image.asset(
'assets/images/driver.png',
fit: BoxFit.contain,
),
),
),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SettingPage(
driverName: _authenticationViewModel
.user.userName,
driverID: _authenticationViewModel
.user.userID)));
},
),
],
), ),
), ],
), ),
], Row(
), children: <Widget>[
Row( Expanded(
children: <Widget>[ child: Column(
Expanded( children: <Widget>[
child: Column( Padding(
children: <Widget>[ padding: EdgeInsets.symmetric(horizontal: 10.0),
Padding( child: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0), height: MediaQuery.of(context).orientation ==
child: Container(
height: MediaQuery.of(context).orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * 0.16 ? MediaQuery.of(context).size.height * 0.16
: MediaQuery.of(context).size.height * 0.30, : MediaQuery.of(context).size.height * 0.30,
width: MediaQuery.of(context).size.width * 0.44, width: MediaQuery.of(context).size.width * 0.44,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0), borderRadius: BorderRadius.circular(15.0),
gradient: LINEAR_GRADIENT, gradient: LINEAR_GRADIENT,
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Padding( child: Padding(
padding: EdgeInsets.all(2.0), padding: EdgeInsets.all(2.0),
child: Column( child: Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceEvenly, MainAxisAlignment.spaceEvenly,
children: <Widget>[ children: <Widget>[
Text( Text(
TranslationBase.of(context).youHave, TranslationBase.of(context).youHave,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: MediaQuery.of(context) fontSize: MediaQuery.of(context)
.orientation == .orientation ==
Orientation.landscape Orientation.landscape
? SizeConfig.textMultiplier * ? SizeConfig.textMultiplier *
2.2 2.2
: SizeConfig.textMultiplier * : SizeConfig.textMultiplier *
1.3, 1.3,
), ),
), ),
Text( Text(
'5', '5',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: fontSize:
SizeConfig.textMultiplier * SizeConfig.textMultiplier *
3.0), 3.0),
), ),
Text( Text(
TranslationBase.of(context) TranslationBase.of(context)
.undeliveredPackages, .undeliveredPackages,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: MediaQuery.of(context) fontSize: MediaQuery.of(context)
.orientation == .orientation ==
Orientation.landscape Orientation.landscape
? SizeConfig.textMultiplier * ? SizeConfig.textMultiplier *
2.2 2.2
: SizeConfig.textMultiplier * : SizeConfig.textMultiplier *
1.3, 1.3,
), ),
) )
], ],
),
),
), ),
), Padding(
), padding: EdgeInsets.only(right: 9.5),
Padding( child: Container(
padding: EdgeInsets.only(right: 9.5), width: 100,
child: Container( height: 100,
width: 100, decoration: BoxDecoration(
height: 100, color: Colors.white10,
decoration: BoxDecoration( shape: BoxShape.circle),
color: Colors.white10, child: Column(
shape: BoxShape.circle), mainAxisAlignment:
child: Column(
mainAxisAlignment:
MainAxisAlignment.center, MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Image.asset( Image.asset(
'assets/images/closed_box.png', 'assets/images/closed_box.png',
height: MediaQuery.of(context) height: MediaQuery.of(context)
.orientation == .orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context) ? MediaQuery.of(context)
.size .size
.height * .height *
0.09 0.09
: MediaQuery.of(context) : MediaQuery.of(context)
.size .size
.height * .height *
0.20, 0.20,
width: MediaQuery.of(context) width: MediaQuery.of(context)
.size .size
.width * .width *
0.20, 0.20,
scale: 0.9, scale: 0.9,
fit: BoxFit.contain, fit: BoxFit.contain,
),
],
), ),
], ),
), ),
), ],
), ),
], ),
), )
), ],
) ),
], ),
), Expanded(
), child: Column(
Expanded( children: <Widget>[
child: Column( Padding(
children: <Widget>[ padding: EdgeInsets.symmetric(horizontal: 10.0),
Padding( child: Container(
padding: EdgeInsets.symmetric(horizontal: 10.0), height: MediaQuery.of(context).orientation ==
child: Container(
height: MediaQuery.of(context).orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * 0.16 ? MediaQuery.of(context).size.height * 0.16
: MediaQuery.of(context).size.height * 0.30, : MediaQuery.of(context).size.height * 0.30,
width: MediaQuery.of(context).size.width * 0.45, width: MediaQuery.of(context).size.width * 0.45,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0), borderRadius: BorderRadius.circular(15.0),
gradient: LINEAR_GRADIENT, gradient: LINEAR_GRADIENT,
), ),
child: InkWell( child: InkWell(
onTap: () => Navigator.push( onTap: () => Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => builder: (context) =>
DeliverdOrdersPage())), DeliverdOrdersPage())),
child: Row( child: Row(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceBetween, MainAxisAlignment.spaceBetween,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Padding( child: Padding(
padding: EdgeInsets.all(2.0), padding: EdgeInsets.all(2.0),
child: Column( child: Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceEvenly, MainAxisAlignment.spaceEvenly,
children: <Widget>[ children: <Widget>[
Text( Text(
TranslationBase.of(context).youHave, TranslationBase.of(context).youHave,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: MediaQuery.of(context) fontSize: MediaQuery.of(context)
.orientation == .orientation ==
Orientation.landscape Orientation.landscape
? SizeConfig.textMultiplier * ? SizeConfig.textMultiplier *
2.2 2.2
: SizeConfig.textMultiplier * : SizeConfig.textMultiplier *
1.3, 1.3,
), ),
), ),
Text( Text(
'3', '3',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: fontSize:
SizeConfig.textMultiplier * SizeConfig.textMultiplier *
3.0), 3.0),
), ),
Text( Text(
TranslationBase.of(context) TranslationBase.of(context)
.deliveredPackages, .deliveredPackages,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: MediaQuery.of(context) fontSize: MediaQuery.of(context)
.orientation == .orientation ==
Orientation.landscape Orientation.landscape
? SizeConfig.textMultiplier * ? SizeConfig.textMultiplier *
2.2 2.2
: SizeConfig.textMultiplier * : SizeConfig.textMultiplier *
1.3, 1.3,
), ),
) )
], ],
), ),
), ),
),
Padding(
padding: EdgeInsets.only(right: 9.5),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.white10,
shape: BoxShape.circle,
), ),
child: Column( Padding(
mainAxisAlignment: padding: EdgeInsets.only(right: 9.5),
child: Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: Colors.white10,
shape: BoxShape.circle,
),
child: Column(
mainAxisAlignment:
MainAxisAlignment.center, MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Image.asset( Image.asset(
'assets/images/opend_box.png', 'assets/images/opend_box.png',
height: MediaQuery.of(context) height: MediaQuery.of(context)
.orientation == .orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context) ? MediaQuery.of(context)
.size .size
.height * .height *
0.09 0.09
: MediaQuery.of(context) : MediaQuery.of(context)
.size .size
.height * .height *
0.20, 0.20,
width: MediaQuery.of(context) width: MediaQuery.of(context)
.size .size
.width * .width *
0.20, 0.20,
scale: 0.9, scale: 0.9,
fit: BoxFit.contain, fit: BoxFit.contain,
),
],
), ),
], ),
), ),
), ],
), ),
], ),
), ),
), )
), ],
) ),
], ),
), ],
), ),
], Padding(
), padding: EdgeInsets.symmetric(vertical: 16.0, horizontal: 15.0),
Padding( child: Row(
padding: EdgeInsets.symmetric(vertical: 16.0, horizontal: 15.0), children: <Widget>[
child: Row( Expanded(
children: <Widget>[ child: InkWell(
Expanded( onTap: () {
child: InkWell( _scanQrAndGetPatient(context, model);
onTap: () { },
_scanQrAndGetPatient(context, model); child: Container(
}, height: MediaQuery.of(context).orientation ==
child: Container(
height: MediaQuery.of(context).orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * 0.18 ? MediaQuery.of(context).size.height * 0.18
: MediaQuery.of(context).size.height * 0.30, : MediaQuery.of(context).size.height * 0.30,
width: MediaQuery.of(context).size.width * 0.50, width: MediaQuery.of(context).size.width * 0.50,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0), borderRadius: BorderRadius.circular(15.0),
gradient: LINEAR_GRADIENT, gradient: LINEAR_GRADIENT,
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Image.asset( Column(
'assets/images/qr_code.png', mainAxisAlignment: MainAxisAlignment.center,
width: MediaQuery.of(context).size.width * children: <Widget>[
0.26, Image.asset(
height: MediaQuery.of(context) 'assets/images/qr_code.png',
.orientation == width: MediaQuery.of(context).size.width *
0.26,
height: MediaQuery.of(context)
.orientation ==
Orientation.portrait Orientation.portrait
? MediaQuery.of(context).size.height * ? MediaQuery.of(context).size.height *
0.14 0.14
: MediaQuery.of(context).size.height * : MediaQuery.of(context).size.height *
0.28, 0.28,
fit: BoxFit.contain, fit: BoxFit.contain,
) )
], ],
), ),
Column( Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.spaceEvenly, MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[ children: <Widget>[
Padding( Padding(
padding: EdgeInsets.only(top: 8.0), padding: EdgeInsets.only(top: 8.0),
child: Text( child: Text(
TranslationBase.of(context).scan, TranslationBase.of(context).scan,
style: TextStyle( style: TextStyle(
fontSize: MediaQuery.of(context) fontSize: MediaQuery.of(context)
.orientation == .orientation ==
Orientation.landscape Orientation.landscape
? SizeConfig.textMultiplier * 6.0 ? SizeConfig.textMultiplier * 6.0
: SizeConfig.textMultiplier * 4.0, : SizeConfig.textMultiplier * 4.0,
color: Colors.white, color: Colors.white,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
),
),
), ),
), Padding(
), padding: EdgeInsets.only(top: 0.0),
Padding( child: Text(
padding: EdgeInsets.only(top: 0.0), TranslationBase.of(context)
child: Text( .toAddPackageToQue,
TranslationBase.of(context) style: TextStyle(
.toAddPackageToQue, fontSize: MediaQuery.of(context)
style: TextStyle( .orientation ==
fontSize: MediaQuery.of(context)
.orientation ==
Orientation.landscape Orientation.landscape
? SizeConfig.textMultiplier * 3.0 ? SizeConfig.textMultiplier * 3.0
: SizeConfig.textMultiplier * 2.0, : SizeConfig.textMultiplier * 2.0,
color: Colors.white, color: Colors.white,
letterSpacing: 0.2, letterSpacing: 0.2,
wordSpacing: 0.5, wordSpacing: 0.5,
),
),
), ),
), ],
), )
], ],
) ),
], ),
), ),
), )
),
)
],
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 1.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
children: <Widget>[
Text(TranslationBase.of(context).nearestDropOffs,
style: TextStyle(
fontSize: 18.0,
color: Hexcolor("#343333"),
fontWeight: FontWeight.bold)),
], ],
), ),
if (model.state == ViewState.Idle) ),
Column( Padding(
mainAxisAlignment: MainAxisAlignment.center, padding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 1.0),
children: <Widget>[ child: Row(
InkWell( mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Row( children: <Widget>[
children: <Widget>[ Column(
Text( children: <Widget>[
TranslationBase.of(context).seeAll, Text(TranslationBase.of(context).nearestDropOffs,
style: TextStyle( style: TextStyle(
fontSize: 14.5, color: Color(0xff42B6AD)), fontSize: 18.0,
color: Hexcolor("#343333"),
fontWeight: FontWeight.bold)),
],
),
if (model.state == ViewState.Idle)
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
child: Row(
children: <Widget>[
Text(
TranslationBase.of(context).seeAll,
style: TextStyle(
fontSize: 14.5, color: Color(0xff42B6AD)),
),
Icon(
Icons.arrow_forward_ios,
size: 15.0,
color: Color(0xff42B6AD),
),
],
), ),
Icon( onTap: () => Navigator.push(
Icons.arrow_forward_ios, context,
size: 15.0, MaterialPageRoute(
color: Color(0xff42B6AD), builder: (context) => OrdersListScreen()),
), ),
], ),
), ],
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrdersListScreen()),
),
), ),
], ],
),
),
NetworkBaseView(
baseViewModel: model,
child: Expanded(
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: model.orders == null
? 0
: model.orders.length < 3 ? model.orders.length : 3,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 0.2),
child: OrderInfoCard(
order: model.orders[index],
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => InformationPage(
model.orders[index])));
}),
);
},
), ),
], ),
),
),
NetworkBaseView(
baseViewModel: model,
child: Expanded(
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: model.orders == null
? 0
: model.orders.length < 3 ? model.orders.length : 3,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 0.2),
child: OrderInfoCard(
order: model.orders[index],
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => InformationPage(
model.orders[index])));
}),
);
},
), ),
), ],
), ),
], ),
), ),
),
),
); );
} }

File diff suppressed because one or more lines are too long

@ -1,5 +1,9 @@
import 'package:app_settings/app_settings.dart';
import 'package:connectivity/connectivity.dart'; import 'package:connectivity/connectivity.dart';
import 'package:driverapp/config/config.dart';
import 'package:driverapp/pages/setting/request_permission_page.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:location/location.dart'; import 'package:location/location.dart';
import 'app_shared_preferences.dart'; import 'app_shared_preferences.dart';
@ -21,7 +25,7 @@ class Utils {
/// Check The Internet Connection /// Check The Internet Connection
static Future<bool> checkConnection() async { static Future<bool> checkConnection() async {
ConnectivityResult connectivityResult = ConnectivityResult connectivityResult =
await (Connectivity().checkConnectivity()); await (Connectivity().checkConnectivity());
if ((connectivityResult == ConnectivityResult.mobile) || if ((connectivityResult == ConnectivityResult.mobile) ||
(connectivityResult == ConnectivityResult.wifi)) { (connectivityResult == ConnectivityResult.wifi)) {
return true; return true;
@ -44,9 +48,63 @@ class Utils {
FocusScope.of(context).unfocus(); FocusScope.of(context).unfocus();
} }
static isLocationPermissionGranted() async {
return (await location.hasPermission()) == PermissionStatus.granted;
}
static Location location = new Location();
static Future<PermissionStatus> getLocationPermission() async {
bool _serviceEnabled;
PermissionStatus _permissionGranted;
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
try {
_serviceEnabled = await location.requestService();
} catch (e) {
print(e);
}
if (!_serviceEnabled) {
// Route to another page and send to him message "You have to enable location"
}
}
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
// _permissionGranted = await location.requestPermission();
if (_permissionGranted == PermissionStatus.denied) {
// Route to another page and send to him message "You have to give Permission"
Navigator.pushReplacement(
AppGlobal.context,
MaterialPageRoute(
builder: (context) => RequestPermissionPage(),
),
);
//return _permissionGranted;
} else if (_permissionGranted == PermissionStatus.deniedForever) {
AppSettings.openLocationSettings();
// open setting page
}
} else if (_permissionGranted == PermissionStatus.deniedForever) {
AppSettings.openLocationSettings();
// open setting page
}
return _permissionGranted;
}
static getLocation() async { static getLocation() async {
// AppGlobal.context
Location location = new Location(); Location location = new Location();
LocationData currentLocation = await location.getLocation(); LocationData currentLocation;
// await getLocationPermission();
try {
currentLocation = await location.getLocation();
} catch (e) {
await getLocationPermission();
print(e);
}
return currentLocation; return currentLocation;
} }

@ -75,6 +75,9 @@ dependencies:
#gradient #gradient
gradient_app_bar: ^0.1.3 gradient_app_bar: ^0.1.3
app_settings: ^4.0.3

Loading…
Cancel
Save