revamp new trip flow
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:anyway/layout.dart';
|
||||
import 'package:anyway/main.dart';
|
||||
import 'package:anyway/structs/preferences.dart';
|
||||
import 'package:anyway/structs/trip.dart';
|
||||
import 'package:anyway/utils/fetch_trip.dart';
|
||||
@@ -8,8 +9,12 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class NewTripButton extends StatefulWidget {
|
||||
final Trip trip;
|
||||
final UserPreferences preferences;
|
||||
|
||||
const NewTripButton({required this.trip});
|
||||
const NewTripButton({
|
||||
required this.trip,
|
||||
required this.preferences,
|
||||
});
|
||||
|
||||
@override
|
||||
State<NewTripButton> createState() => _NewTripButtonState();
|
||||
@@ -23,42 +28,39 @@ class _NewTripButtonState extends State<NewTripButton> {
|
||||
listenable: widget.trip,
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
if (widget.trip.landmarks.isEmpty){
|
||||
// Fallback if the trip setup is lagging behind
|
||||
// This should in theory never happen
|
||||
return Container();
|
||||
}
|
||||
return FloatingActionButton.extended(
|
||||
onPressed: () async {
|
||||
Future<UserPreferences> preferences = loadUserPreferences();
|
||||
Trip trip = widget.trip;
|
||||
fetchTrip(trip, preferences);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BasePage(mainScreen: "map", trip: trip)
|
||||
)
|
||||
);
|
||||
},
|
||||
icon: Icon(Icons.add),
|
||||
label: FutureBuilder(
|
||||
future: widget.trip.cityName,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return AutoSizeText(
|
||||
'New trip to ${snapshot.data.toString()}',
|
||||
style: TextStyle(fontSize: 18),
|
||||
maxLines: 2,
|
||||
);
|
||||
} else {
|
||||
return AutoSizeText(
|
||||
'New trip to ...',
|
||||
style: TextStyle(fontSize: 18),
|
||||
maxLines: 2,
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
onPressed: onPressed,
|
||||
icon: const Icon(Icons.add),
|
||||
label: AutoSizeText('Start planning!'),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void onPressed() async {
|
||||
// Check that the preferences are valid
|
||||
UserPreferences preferences = widget.preferences;
|
||||
if (preferences.nature.value == 0 && preferences.shopping.value == 0 && preferences.sightseeing.value == 0){
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text("Please specify at least one preference"))
|
||||
);
|
||||
} else if (preferences.maxTime.value == 0){
|
||||
rootScaffoldMessengerKey.currentState!.showSnackBar(
|
||||
SnackBar(content: Text("Please choose a longer duration"))
|
||||
);
|
||||
} else {
|
||||
Trip trip = widget.trip;
|
||||
fetchTrip(trip, widget.preferences);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BasePage(mainScreen: "map", trip: trip)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user