Better location handling on map
This commit is contained in:
@@ -29,14 +29,14 @@ class _TripPageState extends State<TripPage> {
|
||||
return SlidingUpPanel(
|
||||
panelBuilder: (sc) => _panelFull(sc),
|
||||
// collapsed: _floatingCollapsed(),
|
||||
body: MapWidget(trip: widget.trip),
|
||||
body: CurrentTripMap(trip: widget.trip),
|
||||
// renderPanelSheet: false,
|
||||
// backdropEnabled: true,
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.8,
|
||||
padding: EdgeInsets.only(left: 10, right: 10, top: 25, bottom: 10),
|
||||
// panelSnapping: false,
|
||||
borderRadius: BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)),
|
||||
boxShadow: [
|
||||
boxShadow: const [
|
||||
BoxShadow(
|
||||
blurRadius: 20.0,
|
||||
color: Colors.black,
|
||||
|
@@ -84,6 +84,8 @@ class _NewTripPreferencesPageState extends State<NewTripPreferencesPage> {
|
||||
for (SinglePreference pref in prefs) {
|
||||
sliders.add(
|
||||
Card(
|
||||
margin: const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 0),
|
||||
shadowColor: Colors.grey,
|
||||
child: ListTile(
|
||||
leading: pref.icon,
|
||||
title: Text(pref.name),
|
||||
@@ -100,8 +102,6 @@ class _NewTripPreferencesPageState extends State<NewTripPreferencesPage> {
|
||||
},
|
||||
)
|
||||
),
|
||||
margin: const EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 0),
|
||||
shadowColor: Colors.grey,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
|
||||
bool debugMode = false;
|
||||
bool useLocation = false;
|
||||
|
||||
class SettingsPage extends StatefulWidget {
|
||||
@override
|
||||
@@ -15,7 +14,6 @@ class SettingsPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SettingsPageState extends State<SettingsPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView(
|
||||
@@ -90,6 +88,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget darkMode() {
|
||||
return Row(
|
||||
children: [
|
||||
@@ -115,46 +114,58 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget setLocationUsage() {
|
||||
Future<SharedPreferences> preferences = SharedPreferences.getInstance();
|
||||
return Row(
|
||||
children: [
|
||||
Text('Use location services'),
|
||||
// white space
|
||||
Spacer(),
|
||||
Switch(
|
||||
value: useLocation,
|
||||
onChanged: (bool? newValue) async {
|
||||
await Permission.locationWhenInUse
|
||||
.onDeniedCallback(() {
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text('Location services are required for this feature'))
|
||||
);
|
||||
})
|
||||
.onGrantedCallback(() {
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text('Location services are now enabled'))
|
||||
);
|
||||
setState(() {
|
||||
useLocation = newValue!;
|
||||
});
|
||||
SharedPreferences.getInstance().then(
|
||||
(SharedPreferences prefs) {
|
||||
prefs.setBool('useLocation', useLocation);
|
||||
}
|
||||
);
|
||||
})
|
||||
.onPermanentlyDeniedCallback(() {
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text('Location services are required for this feature'))
|
||||
);
|
||||
})
|
||||
.request();
|
||||
FutureBuilder(
|
||||
future: preferences,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
bool useLocation = snapshot.data!.getBool('useLocation') ?? false;
|
||||
return Switch(
|
||||
value: useLocation,
|
||||
onChanged: setUseLocation,
|
||||
);
|
||||
} else {
|
||||
return CircularProgressIndicator();
|
||||
}
|
||||
}
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void setUseLocation(bool newValue) async {
|
||||
await Permission.locationWhenInUse
|
||||
.onDeniedCallback(() {
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text('Location services are required for this feature'))
|
||||
);
|
||||
})
|
||||
.onGrantedCallback(() {
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text('Location services are now enabled'))
|
||||
);
|
||||
SharedPreferences.getInstance().then(
|
||||
(SharedPreferences prefs) {
|
||||
setState(() {
|
||||
prefs.setBool('useLocation', newValue);
|
||||
});
|
||||
}
|
||||
);
|
||||
})
|
||||
.onPermanentlyDeniedCallback(() {
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text('Location services are required for this feature'))
|
||||
);
|
||||
})
|
||||
.request();
|
||||
}
|
||||
|
||||
Widget privacyInfo() {
|
||||
return Center(
|
||||
@@ -163,8 +174,8 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
Text('Our privacy policy is available under:'),
|
||||
|
||||
TextButton.icon(
|
||||
icon: Icon(Icons.info),
|
||||
label: Text(PRIVACY_URL),
|
||||
icon: Icon(Icons.info, color: Colors.white),
|
||||
label: Text(PRIVACY_URL, style: TextStyle(color: Colors.white)),
|
||||
onPressed: () async{
|
||||
await launchUrl(Uri.parse(PRIVACY_URL));
|
||||
}
|
||||
|
Reference in New Issue
Block a user