reworked page layout inheritence
This commit is contained in:
		| @@ -1,145 +0,0 @@ | ||||
| import 'package:anyway/main.dart'; | ||||
| import 'package:anyway/modules/help_dialog.dart'; | ||||
| import 'package:anyway/pages/current_trip.dart'; | ||||
| import 'package:anyway/pages/settings.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| import 'package:anyway/constants.dart'; | ||||
|  | ||||
| import 'package:anyway/structs/trip.dart'; | ||||
| import 'package:anyway/modules/trips_saved_list.dart'; | ||||
| import 'package:anyway/utils/load_trips.dart'; | ||||
|  | ||||
| import 'package:anyway/pages/new_trip_location.dart'; | ||||
| import 'package:anyway/pages/onboarding.dart'; | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| // BasePage is the scaffold that holds a child page and a side drawer | ||||
| // The side drawer is the main way to switch between pages | ||||
|  | ||||
| class BasePage extends StatefulWidget { | ||||
|   final Widget mainScreen; | ||||
|   final Widget title; | ||||
|   final List<String> helpTexts; | ||||
|  | ||||
|   const BasePage({ | ||||
|     super.key, | ||||
|     required this.mainScreen, | ||||
|     this.title = const Text(APP_NAME), | ||||
|     this.helpTexts = const [], | ||||
|   }); | ||||
|  | ||||
|   @override | ||||
|   State<BasePage> createState() => _BasePageState(); | ||||
| } | ||||
|  | ||||
| class _BasePageState extends State<BasePage> { | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     savedTrips.loadTrips(); | ||||
|  | ||||
|  | ||||
|     return Scaffold( | ||||
|       appBar: AppBar( | ||||
|         title: widget.title, | ||||
|         actions: [ | ||||
|           IconButton( | ||||
|             icon: const Icon(Icons.help), | ||||
|             tooltip: 'Help', | ||||
|             onPressed: () { | ||||
|               if (widget.helpTexts.isNotEmpty) { | ||||
|                 helpDialog(context, widget.helpTexts[0], widget.helpTexts[1]); | ||||
|               } | ||||
|             } | ||||
|           ), | ||||
|         ], | ||||
|       ), | ||||
|       body: Center(child: widget.mainScreen), | ||||
|       drawer: Drawer( | ||||
|         child: Column( | ||||
|           children: [ | ||||
|             Container( | ||||
|               decoration: BoxDecoration( | ||||
|                 gradient: APP_GRADIENT, | ||||
|               ), | ||||
|               height: 150, | ||||
|               child: Center( | ||||
|                 child: Text( | ||||
|                   APP_NAME, | ||||
|                   style: TextStyle( | ||||
|                     color: Colors.white, | ||||
|                     fontSize: 24, | ||||
|                     fontWeight: FontWeight.bold, | ||||
|                   ), | ||||
|                 ), | ||||
|               ), | ||||
|             ), | ||||
|  | ||||
|             ListTile( | ||||
|               title: const Text('Your Trips'), | ||||
|               leading: const Icon(Icons.map), | ||||
|               // TODO: this is not working! | ||||
|               selected: widget.mainScreen is TripPage, | ||||
|               onTap: () {}, | ||||
|               trailing: ElevatedButton( | ||||
|                 onPressed: () { | ||||
|                   Navigator.of(context).push( | ||||
|                     MaterialPageRoute( | ||||
|                       builder: (context) => const NewTripPage() | ||||
|                     ) | ||||
|                   ); | ||||
|                 }, | ||||
|                 child: const Text('New'), | ||||
|               ), | ||||
|             ), | ||||
|  | ||||
|             // Adds a ListView to the drawer. This ensures the user can scroll | ||||
|             // through the options in the drawer if there isn't enough vertical | ||||
|             // space to fit everything. | ||||
|             Expanded( | ||||
|               child: TripsOverview(trips: savedTrips), | ||||
|             ), | ||||
|             ElevatedButton( | ||||
|               onPressed: () async { | ||||
|                 savedTrips.clearTrips(); | ||||
|               }, | ||||
|               child: const Text('Clear trips'), | ||||
|             ), | ||||
|             const Divider(indent: 10, endIndent: 10), | ||||
|             ListTile( | ||||
|               title: const Text('How to use'), | ||||
|               leading: Icon(Icons.help), | ||||
|               // TODO: this is not working! | ||||
|               selected: widget.mainScreen is OnboardingPage, | ||||
|               onTap: () { | ||||
|                 Navigator.of(context).push( | ||||
|                   MaterialPageRoute( | ||||
|                     builder: (context) => OnboardingPage() | ||||
|                   ) | ||||
|                 ); | ||||
|               }, | ||||
|             ), | ||||
|  | ||||
|             // settings in the bottom of the drawer | ||||
|             ListTile( | ||||
|               title: const Text('Settings'), | ||||
|               leading: const Icon(Icons.settings), | ||||
|               // TODO: this is not working! | ||||
|               selected: widget.mainScreen is SettingsPage, | ||||
|               onTap: () { | ||||
|                 Navigator.of(context).push( | ||||
|                   MaterialPageRoute( | ||||
|                     builder: (context) => SettingsPage() | ||||
|                   ) | ||||
|                 ); | ||||
|               }, | ||||
|             ), | ||||
|           ], | ||||
|         ), | ||||
|       ), | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| @@ -1,5 +1,5 @@ | ||||
| import 'package:anyway/constants.dart'; | ||||
| import 'package:anyway/pages/base_page.dart'; | ||||
| import 'package:anyway/layouts/scaffold.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:sliding_up_panel/sliding_up_panel.dart'; | ||||
|  | ||||
| @@ -28,12 +28,13 @@ class TripPage extends StatefulWidget { | ||||
|  | ||||
|  | ||||
|  | ||||
| class _TripPageState extends State<TripPage> { | ||||
| class _TripPageState extends State<TripPage> with ScaffoldLayout{ | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return BasePage( | ||||
|       mainScreen: SlidingUpPanel( | ||||
|     return mainScaffold( | ||||
|       context, | ||||
|       child: SlidingUpPanel( | ||||
|         // use panelBuilder instead of panel so that we can reuse the scrollcontroller for the listview | ||||
|         panelBuilder: (scrollcontroller) => CurrentTripPanel(controller: scrollcontroller, trip: widget.trip), | ||||
|         // using collapsed and panelBuilder seems to show both at the same time, so we include the greeter in the panelBuilder | ||||
| @@ -58,9 +59,13 @@ class _TripPageState extends State<TripPage> { | ||||
|       title: FutureBuilder( | ||||
|         future: widget.trip.cityName, | ||||
|         builder: (context, snapshot) => Text( | ||||
|           'Your trip to ${snapshot.hasData ? snapshot.data! : "..."}', | ||||
|           'Trip to ${snapshot.hasData ? snapshot.data! : "..."}', | ||||
|         ) | ||||
|       ), | ||||
|       helpTexts: [ | ||||
|         'Current trip', | ||||
|         'You can see and edit your current trip here. Swipe up from the bottom to see a detailed view of the recommendations.' | ||||
|       ], | ||||
|     ); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| import 'package:anyway/layouts/scaffold.dart'; | ||||
| import 'package:anyway/modules/new_trip_options_button.dart'; | ||||
| import 'package:anyway/pages/base_page.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
|  | ||||
| import "package:anyway/structs/trip.dart"; | ||||
| @@ -14,7 +14,7 @@ class NewTripPage extends StatefulWidget { | ||||
|   _NewTripPageState createState() => _NewTripPageState(); | ||||
| } | ||||
|  | ||||
| class _NewTripPageState extends State<NewTripPage> { | ||||
| class _NewTripPageState extends State<NewTripPage> with ScaffoldLayout { | ||||
|   final TextEditingController latController = TextEditingController(); | ||||
|   final TextEditingController lonController = TextEditingController(); | ||||
|   Trip trip = Trip(); | ||||
| @@ -23,8 +23,9 @@ class _NewTripPageState extends State<NewTripPage> { | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     // floating search bar and map as a background | ||||
|     return BasePage( | ||||
|       mainScreen: Scaffold( | ||||
|     return mainScaffold( | ||||
|       context, | ||||
|       child: Scaffold( | ||||
|         body: Stack( | ||||
|           children: [ | ||||
|             NewTripMap(trip), | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| import 'package:anyway/layouts/scaffold.dart'; | ||||
| import 'package:anyway/modules/new_trip_button.dart'; | ||||
| import 'package:anyway/pages/base_page.dart'; | ||||
| import 'package:anyway/structs/preferences.dart'; | ||||
| import 'package:anyway/structs/trip.dart'; | ||||
| import 'package:flutter/cupertino.dart'; | ||||
| @@ -15,13 +15,14 @@ class NewTripPreferencesPage extends StatefulWidget { | ||||
|   _NewTripPreferencesPageState createState() => _NewTripPreferencesPageState(); | ||||
| } | ||||
|  | ||||
| class _NewTripPreferencesPageState extends State<NewTripPreferencesPage> { | ||||
| class _NewTripPreferencesPageState extends State<NewTripPreferencesPage> with ScaffoldLayout { | ||||
|   UserPreferences preferences = UserPreferences(); | ||||
|  | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return BasePage( | ||||
|       mainScreen: Scaffold( | ||||
|     return mainScaffold( | ||||
|       context, | ||||
|       child: Scaffold( | ||||
|         body: ListView( | ||||
|           children: [ | ||||
|             // Center( | ||||
| @@ -41,23 +42,22 @@ class _NewTripPreferencesPageState extends State<NewTripPreferencesPage> { | ||||
|             //   ) | ||||
|             // ), | ||||
|  | ||||
|             Center( | ||||
|               child: Padding( | ||||
|               padding: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 0), | ||||
|                 child: Text('Tell us about your ideal trip.', style: TextStyle(fontSize: 18)) | ||||
|               ), | ||||
|           Center( | ||||
|             child: Padding( | ||||
|             padding: EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 0), | ||||
|               child: Text('Tell us about your ideal trip.', style: TextStyle(fontSize: 18)) | ||||
|             ), | ||||
|           ), | ||||
|  | ||||
|             Divider(indent: 25, endIndent: 25, height: 50), | ||||
|           Divider(indent: 25, endIndent: 25, height: 50), | ||||
|  | ||||
|             durationPicker(preferences.maxTime), | ||||
|           durationPicker(preferences.maxTime), | ||||
|  | ||||
|             preferenceSliders([preferences.sightseeing, preferences.shopping, preferences.nature]), | ||||
|           ] | ||||
|         ), | ||||
|         floatingActionButton: NewTripButton(trip: widget.trip, preferences: preferences), | ||||
|           preferenceSliders([preferences.sightseeing, preferences.shopping, preferences.nature]), | ||||
|         ] | ||||
|       ), | ||||
|       floatingActionButton: NewTripButton(trip: widget.trip, preferences: preferences), | ||||
|       ), | ||||
|        | ||||
|       title: FutureBuilder( | ||||
|         future: widget.trip.cityName, | ||||
|         builder: (context, snapshot) => Text( | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| import 'package:anyway/constants.dart'; | ||||
| import 'package:anyway/layouts/scaffold.dart'; | ||||
| import 'package:anyway/main.dart'; | ||||
| import 'package:anyway/pages/base_page.dart'; | ||||
| import 'package:flutter/material.dart'; | ||||
| import 'package:permission_handler/permission_handler.dart'; | ||||
| import 'package:shared_preferences/shared_preferences.dart'; | ||||
| @@ -14,42 +14,41 @@ class SettingsPage extends StatefulWidget { | ||||
|   _SettingsPageState createState() => _SettingsPageState(); | ||||
| } | ||||
|  | ||||
| class _SettingsPageState extends State<SettingsPage> { | ||||
| class _SettingsPageState extends State<SettingsPage> with ScaffoldLayout { | ||||
|   @override | ||||
|   Widget build(BuildContext context) { | ||||
|     return BasePage( | ||||
|       mainScreen: ListView( | ||||
|         padding: EdgeInsets.all(15), | ||||
|         children: [ | ||||
|           // First a round, centered image | ||||
|           Center( | ||||
|             child: CircleAvatar( | ||||
|               radius: 75, | ||||
|               child: Icon(Icons.settings, size: 100), | ||||
|             ) | ||||
|           ), | ||||
|           Center( | ||||
|             child: Text('Global settings', style: TextStyle(fontSize: 24)) | ||||
|           ), | ||||
|   Widget build (BuildContext context) => mainScaffold( | ||||
|     context, | ||||
|     child: ListView( | ||||
|       padding: EdgeInsets.all(15), | ||||
|       children: [ | ||||
|         // First a round, centered image | ||||
|         Center( | ||||
|           child: CircleAvatar( | ||||
|             radius: 75, | ||||
|             child: Icon(Icons.settings, size: 100), | ||||
|           ) | ||||
|         ), | ||||
|         Center( | ||||
|           child: Text('Global settings', style: TextStyle(fontSize: 24)) | ||||
|         ), | ||||
|  | ||||
|           Divider(indent: 25, endIndent: 25, height: 50), | ||||
|         Divider(indent: 25, endIndent: 25, height: 50), | ||||
|  | ||||
|           darkMode(), | ||||
|           setLocationUsage(), | ||||
|           setDebugMode(), | ||||
|         darkMode(), | ||||
|         setLocationUsage(), | ||||
|         setDebugMode(), | ||||
|  | ||||
|           Divider(indent: 25, endIndent: 25, height: 50), | ||||
|         Divider(indent: 25, endIndent: 25, height: 50), | ||||
|  | ||||
|           privacyInfo(), | ||||
|         ] | ||||
|       ), | ||||
|       title: Text('Settings'), | ||||
|       helpTexts: [ | ||||
|         'Settings', | ||||
|         'Preferences set in this page are global and will affect the entire application.' | ||||
|       ], | ||||
|     ); | ||||
|   } | ||||
|         privacyInfo(), | ||||
|       ] | ||||
|     ), | ||||
|     title: Text('Settings'), | ||||
|     helpTexts: [ | ||||
|       'Settings', | ||||
|       'Preferences set in this page are global and will affect the entire application.' | ||||
|     ], | ||||
|   ); | ||||
|  | ||||
|   Widget setDebugMode() { | ||||
|     return Row( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user