Beginning to use different contexts
This commit is contained in:
@@ -1,85 +1,117 @@
|
||||
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:flutter/material.dart';
|
||||
|
||||
import 'package:fast_network_navigation/pages/overview.dart';
|
||||
import 'package:fast_network_navigation/pages/profile.dart';
|
||||
|
||||
|
||||
// BasePage is the scaffold that holds all other pages
|
||||
// A side drawer is used to switch between pages
|
||||
class BasePage extends StatefulWidget {
|
||||
const BasePage({super.key, required this.title});
|
||||
final String title;
|
||||
final String mainScreen;
|
||||
final String currentMap;
|
||||
final List<Trip> trips;
|
||||
|
||||
const BasePage({super.key, required this.mainScreen, this.currentMap = "map", this.trips = const []});
|
||||
|
||||
@override
|
||||
State<BasePage> createState() => _BasePageState();
|
||||
}
|
||||
|
||||
class _BasePageState extends State<BasePage> {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
}
|
||||
|
||||
Widget currentView = NavigationOverview();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget currentView = const Text("loading...");
|
||||
if (widget.mainScreen == "map") {
|
||||
currentView = NavigationOverview();
|
||||
} else if (widget.mainScreen == "tutorial") {
|
||||
currentView = TutorialPage();
|
||||
} else if (widget.mainScreen == "profile") {
|
||||
currentView = ProfilePage();
|
||||
}
|
||||
|
||||
final ThemeData theme = Theme.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(widget.title)),
|
||||
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: ListView(
|
||||
// Important: Remove any padding from the ListView.
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
DrawerHeader(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [Colors.cyan, theme.primaryColor])
|
||||
),
|
||||
child: const Text('The fanciest navigation!'),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'City Nav',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Start'),
|
||||
leading: const Icon(Icons.map),
|
||||
selected: _selectedIndex == 0,
|
||||
selected: widget.mainScreen == "map",
|
||||
onTap: () {
|
||||
// Update the state of the app
|
||||
_onItemTapped(0);
|
||||
// Then close the drawer
|
||||
currentView = NavigationOverview();
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BasePage(mainScreen: "map")
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Trip Overview'),
|
||||
leading: const Icon(Icons.list),
|
||||
trailing: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const NewTripPage()
|
||||
)
|
||||
);
|
||||
},
|
||||
child: const Text('New'),
|
||||
),
|
||||
),
|
||||
Expanded(child: TripsOverview()),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
title: const Text('How to use'),
|
||||
leading: Icon(Icons.help),
|
||||
selected: _selectedIndex == 1,
|
||||
selected: widget.mainScreen == "tutorial",
|
||||
onTap: () {
|
||||
// Update the state of the app
|
||||
_onItemTapped(1);
|
||||
currentView = const Text("ghfhggfhgf");
|
||||
|
||||
// Then close the drawer
|
||||
Navigator.pop(context);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BasePage(mainScreen: "tutorial")
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(),
|
||||
|
||||
ListTile(
|
||||
title: const Text('Settings'),
|
||||
leading: const Icon(Icons.settings),
|
||||
selected: _selectedIndex == 2,
|
||||
selected: widget.mainScreen == "profile",
|
||||
onTap: () {
|
||||
_onItemTapped(2);
|
||||
currentView = ProfilePage();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => BasePage(mainScreen: "profile")
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
// settings in the bottom of the drawer
|
||||
],
|
||||
|
Reference in New Issue
Block a user