From a082441826d64ba7c241b5e5164a59715a745e17 Mon Sep 17 00:00:00 2001 From: LilleBRG Date: Tue, 20 Aug 2024 16:46:13 +0200 Subject: [PATCH] menu partly done. --- Mobile/lib/Profile.dart | 1 + Mobile/lib/main.dart | 125 +++++++++++++++++++++++++++++++--------- 2 files changed, 98 insertions(+), 28 deletions(-) create mode 100644 Mobile/lib/Profile.dart diff --git a/Mobile/lib/Profile.dart b/Mobile/lib/Profile.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Mobile/lib/Profile.dart @@ -0,0 +1 @@ + diff --git a/Mobile/lib/main.dart b/Mobile/lib/main.dart index 18d4079..c7524f0 100644 --- a/Mobile/lib/main.dart +++ b/Mobile/lib/main.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; import "package:latlong2/latlong.dart"; +import 'package:mobile/register.dart'; import "login.dart"; void main() { @@ -9,28 +10,11 @@ void main() { class MyApp extends StatelessWidget { const MyApp({super.key}); - - // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'H4 Flutter', theme: ThemeData( - // This is the theme of your application. - // - // TRY THIS: Try running your application with "flutter run". You'll see - // the application has a purple toolbar. Then, without quitting the app, - // try changing the seedColor in the colorScheme below to Colors.green - // and then invoke "hot reload" (save your changes or press the "hot - // reload" button in a Flutter-supported IDE, or press "r" if you used - // the command line to start the app). - // - // Notice that the counter didn't reset back to zero; the application - // state is not lost during the reload. To reset the state, use hot - // restart instead. - // - // This works for code too, not just values: Most code changes can be - // tested with just a hot reload. colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue), useMaterial3: true, ), @@ -42,15 +26,6 @@ class MyApp extends StatelessWidget { class MyHomePage extends StatefulWidget { const MyHomePage({super.key, required this.title}); - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - final String title; @override @@ -58,6 +33,14 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { + int _selectedIndex = 0; + + void _onItemTapped(int index) { + setState(() { + _selectedIndex = index; + }); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -65,8 +48,10 @@ class _MyHomePageState extends State { backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title), ), + drawer: navigationMenu, body: FlutterMap( - options: const MapOptions(initialCenter: LatLng(55.9397, 9.5156), initialZoom: 7.0), + options: const MapOptions( + initialCenter: LatLng(55.9397, 9.5156), initialZoom: 7.0), children: [ TileLayer( urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', @@ -79,7 +64,10 @@ class _MyHomePageState extends State { children: [ FloatingActionButton( onPressed: () { - Navigator.push(context, MaterialPageRoute(builder: (context) => const LoginPage(title: "Login"))); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const LoginPage(title: "Login"))); }, tooltip: 'Login', child: const Icon(Icons.login), @@ -88,4 +76,85 @@ class _MyHomePageState extends State { ), ); } + + Drawer get navigationMenu => Drawer( + child: ListView( + padding: EdgeInsets.zero, + children: [ + const DrawerHeader( + decoration: BoxDecoration( + color: Colors.blue, + ), + child: Text('Drawer Header'), + ), + ListTile( + title: const Text('Home'), + leading: const Icon(Icons.home), + selected: _selectedIndex == 0, + onTap: () { + // Update the state of the app + _onItemTapped(0); + // Then close the drawer + Navigator.pop(context); + }, + ), + ListTile( + title: const Text('Favourites'), + leading: const Icon(Icons.star), + selected: _selectedIndex == 1, + onTap: () { + // Update the state of the app + _onItemTapped(1); + // Then close the drawer + Navigator.pop(context); + }, + ), + ListTile( + title: const Text('Profile'), + leading: const Icon(Icons.person), + selected: _selectedIndex == 2, + onTap: () { + // Update the state of the app + _onItemTapped(2); + // Then close the drawer + Navigator.pop(context); + }, + ), + const Divider( + color: Colors.grey, + thickness: 2, + indent: 40, + ), + ListTile( + title: const Text('Register'), + leading: const Icon(Icons.add_box_outlined), + selected: _selectedIndex == 3, + onTap: () { + // Update the state of the app + _onItemTapped(3); + // Then close the drawer + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + const RegisterPage(title: "Register"))); + }, + ), + ListTile( + title: const Text('Login'), + leading: const Icon(Icons.login), + selected: _selectedIndex == 4, + onTap: () { + // Update the state of the app + _onItemTapped(4); + // Then close the drawer + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const LoginPage(title: "Login"))); + }, + ), + ], + ), + ); }