functional datastructure. Needs to be able to write to storage as well
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:fast_network_navigation/modules/trips_overview.dart';
|
||||
import 'package:fast_network_navigation/pages/new_trip.dart';
|
||||
import 'package:fast_network_navigation/pages/tutorial.dart';
|
||||
import 'package:fast_network_navigation/structs/trip.dart';
|
||||
import 'package:fast_network_navigation/utils/load_trips.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fast_network_navigation/pages/overview.dart';
|
||||
@@ -11,10 +12,13 @@ import 'package:fast_network_navigation/pages/profile.dart';
|
||||
// A side drawer is used to switch between pages
|
||||
class BasePage extends StatefulWidget {
|
||||
final String mainScreen;
|
||||
final String currentMap;
|
||||
final List<Trip> trips;
|
||||
final Trip? trip;
|
||||
|
||||
const BasePage({super.key, required this.mainScreen, this.currentMap = "map", this.trips = const []});
|
||||
const BasePage({
|
||||
super.key,
|
||||
required this.mainScreen,
|
||||
this.trip
|
||||
});
|
||||
|
||||
@override
|
||||
State<BasePage> createState() => _BasePageState();
|
||||
@@ -22,12 +26,15 @@ class BasePage extends StatefulWidget {
|
||||
|
||||
class _BasePageState extends State<BasePage> {
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget currentView = const Text("loading...");
|
||||
Future<List<Trip>> trips = loadTrips();
|
||||
Future<Trip> firstTrip = getFirstTrip(trips);
|
||||
// Future<Trip> trip = Future(trips[0]);
|
||||
|
||||
if (widget.mainScreen == "map") {
|
||||
currentView = NavigationOverview();
|
||||
currentView = NavigationOverview(trip: firstTrip);
|
||||
} else if (widget.mainScreen == "tutorial") {
|
||||
currentView = TutorialPage();
|
||||
} else if (widget.mainScreen == "profile") {
|
||||
@@ -40,9 +47,6 @@ class _BasePageState extends State<BasePage> {
|
||||
appBar: AppBar(title: Text("City Nav")),
|
||||
body: Center(child: currentView),
|
||||
drawer: Drawer(
|
||||
// Add 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.
|
||||
child: Column(
|
||||
children: [
|
||||
DrawerHeader(
|
||||
@@ -61,20 +65,10 @@ class _BasePageState extends State<BasePage> {
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Start'),
|
||||
title: const Text('Your Trips'),
|
||||
leading: const Icon(Icons.map),
|
||||
selected: widget.mainScreen == "map",
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BasePage(mainScreen: "map")
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Trip Overview'),
|
||||
leading: const Icon(Icons.list),
|
||||
onTap: () {},
|
||||
trailing: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
@@ -86,7 +80,23 @@ class _BasePageState extends State<BasePage> {
|
||||
child: const Text('New'),
|
||||
),
|
||||
),
|
||||
Expanded(child: TripsOverview()),
|
||||
|
||||
// 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: trips),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const NewTripPage()
|
||||
)
|
||||
);
|
||||
},
|
||||
child: const Text('Clear trips'),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
title: const Text('How to use'),
|
||||
@@ -101,6 +111,7 @@ class _BasePageState extends State<BasePage> {
|
||||
},
|
||||
),
|
||||
|
||||
// settings in the bottom of the drawer
|
||||
ListTile(
|
||||
title: const Text('Settings'),
|
||||
leading: const Icon(Icons.settings),
|
||||
@@ -113,7 +124,6 @@ class _BasePageState extends State<BasePage> {
|
||||
);
|
||||
},
|
||||
),
|
||||
// settings in the bottom of the drawer
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -121,3 +131,9 @@ class _BasePageState extends State<BasePage> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<Trip> getFirstTrip (Future<List<Trip>> trips) async {
|
||||
List<Trip> tripsf = await trips;
|
||||
return tripsf[0];
|
||||
}
|
Reference in New Issue
Block a user