revamp new trip flow

This commit is contained in:
2024-09-24 22:58:28 +02:00
parent eaa2334942
commit ed60fcba06
26 changed files with 663 additions and 302 deletions

View File

@@ -6,9 +6,12 @@ import 'dart:developer';
import 'package:anyway/structs/trip.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class NewTripLocationSearch extends StatefulWidget {
Future<SharedPreferences> prefs = SharedPreferences.getInstance();
Trip trip;
NewTripLocationSearch(
this.trip,
);
@@ -45,20 +48,51 @@ class _NewTripLocationSearchState extends State<NewTripLocationSearch> {
}
}
@override
Widget build(BuildContext context) {
return SearchBar(
hintText: 'Enter a city name or long press on the map.',
onSubmitted: setTripLocation,
controller: _controller,
leading: Icon(Icons.search),
trailing: [ElevatedButton(
late Widget locationSearchBar = SearchBar(
hintText: 'Enter a city name or long press on the map.',
onSubmitted: setTripLocation,
controller: _controller,
leading: Icon(Icons.search),
trailing: [
ElevatedButton(
onPressed: () {
setTripLocation(_controller.text);
},
child: Text('Search'),
),]
)
]
);
late Widget useCurrentLocationButton = ElevatedButton(
onPressed: () {
// setTripLocation(location);
// TODO: get current location
},
child: Text('Use current location'),
);
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: widget.prefs,
builder: (context, snapshot) {
if (snapshot.hasData) {
final useLocation = snapshot.data!.getBool('useLocation') ?? false;
if (useLocation) {
return Column(
children: [
locationSearchBar,
useCurrentLocationButton,
],
);
} else {
return locationSearchBar;
}
} else {
return locationSearchBar;
}
},
);
}
}
}