tentatively shrink trip overview, nicer onboarding
This commit is contained in:
		| @@ -3,7 +3,6 @@ import 'package:anyway/main.dart'; | ||||
| import 'package:anyway/structs/trip.dart'; | ||||
| import 'package:auto_size_text/auto_size_text.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:shared_preferences/shared_preferences.dart'; | ||||
|  | ||||
|  | ||||
| class saveButton extends StatefulWidget { | ||||
| @@ -19,8 +18,9 @@ class _saveButtonState extends State<saveButton> { | ||||
|   Widget build(BuildContext context) { | ||||
|     return ElevatedButton( | ||||
|       onPressed: () async { | ||||
|         SharedPreferences prefs = await SharedPreferences.getInstance(); | ||||
|         setState(() => widget.trip.toPrefs(prefs)); | ||||
|         savedTrips.addTrip(widget.trip); | ||||
|         // SharedPreferences prefs = await SharedPreferences.getInstance(); | ||||
|         // setState(() => widget.trip.toPrefs(prefs)); | ||||
|         rootScaffoldMessengerKey.currentState!.showSnackBar( | ||||
|           SnackBar( | ||||
|             content: Text('Trip saved'), | ||||
|   | ||||
| @@ -1,11 +1,12 @@ | ||||
| import 'package:anyway/pages/current_trip.dart'; | ||||
| import 'package:anyway/utils/load_trips.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| import 'package:anyway/structs/trip.dart'; | ||||
|  | ||||
|  | ||||
| class TripsOverview extends StatefulWidget { | ||||
|   final Future<List<Trip>> trips; | ||||
|   final SavedTrips trips; | ||||
|   const TripsOverview({ | ||||
|     super.key, | ||||
|     required this.trips, | ||||
| @@ -16,49 +17,34 @@ class TripsOverview extends StatefulWidget { | ||||
| } | ||||
|  | ||||
| class _TripsOverviewState extends State<TripsOverview> { | ||||
|   Widget listBuild (BuildContext context, AsyncSnapshot<List<Trip>> snapshot) { | ||||
|   Widget listBuild (BuildContext context, SavedTrips trips) { | ||||
|     List<Widget> children; | ||||
|     if (snapshot.hasData) { | ||||
|       children = List<Widget>.generate(snapshot.data!.length, (index) { | ||||
|         Trip trip = snapshot.data![index]; | ||||
|         return ListTile( | ||||
|           title: FutureBuilder( | ||||
|             future: trip.cityName, | ||||
|             builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | ||||
|               if (snapshot.hasData) { | ||||
|                 return Text("Trip to ${snapshot.data}"); | ||||
|               } else if (snapshot.hasError) { | ||||
|                 return Text("Error: ${snapshot.error}"); | ||||
|               } else { | ||||
|                 return const Text("Trip to ..."); | ||||
|               } | ||||
|             }, | ||||
|           ), | ||||
|           leading: Icon(Icons.pin_drop), | ||||
|           onTap: () { | ||||
|             Navigator.of(context).push( | ||||
|               MaterialPageRoute( | ||||
|                 builder: (context) => TripPage(trip: trip) | ||||
|               ) | ||||
|             ); | ||||
|     List<Trip> items = trips.trips; | ||||
|     children = List<Widget>.generate(items.length, (index) { | ||||
|       Trip trip = items[index]; | ||||
|       return ListTile( | ||||
|         title: FutureBuilder( | ||||
|           future: trip.cityName, | ||||
|           builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | ||||
|             if (snapshot.hasData) { | ||||
|               return Text("Trip to ${snapshot.data}"); | ||||
|             } else if (snapshot.hasError) { | ||||
|               return Text("Error: ${snapshot.error}"); | ||||
|             } else { | ||||
|               return const Text("Trip to ..."); | ||||
|             } | ||||
|           }, | ||||
|         ); | ||||
|       }); | ||||
|     } else if (snapshot.hasError) { | ||||
|       children = [ | ||||
|         const Icon( | ||||
|           Icons.error_outline, | ||||
|           color: Colors.red, | ||||
|           size: 60, | ||||
|         ), | ||||
|         Padding( | ||||
|           padding: const EdgeInsets.only(top: 16), | ||||
|           child: Text('Error: ${snapshot.error}'), | ||||
|         ), | ||||
|       ]; | ||||
|     } else { | ||||
|       children = [Center(child: CircularProgressIndicator())]; | ||||
|     } | ||||
|         leading: Icon(Icons.pin_drop), | ||||
|         onTap: () { | ||||
|           Navigator.of(context).push( | ||||
|             MaterialPageRoute( | ||||
|               builder: (context) => TripPage(trip: trip) | ||||
|             ) | ||||
|           ); | ||||
|         }, | ||||
|       ); | ||||
|     }); | ||||
|  | ||||
|     return ListView( | ||||
|       children: children, | ||||
| @@ -68,9 +54,11 @@ class _TripsOverviewState extends State<TripsOverview> { | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return FutureBuilder( | ||||
|       future: widget.trips, | ||||
|       builder: listBuild, | ||||
|     return ListenableBuilder( | ||||
|       listenable: widget.trips, | ||||
|       builder: (BuildContext context, Widget? child) { | ||||
|         return listBuild(context, widget.trips); | ||||
|       } | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user