Compare commits

..

No commits in common. "46bb1ce74cf605177a5441e47d0202980a2eb117" and "206483de09f6347560bb22550d32e8199143fc65" have entirely different histories.

5 changed files with 120 additions and 283 deletions

View File

@ -1,104 +0,0 @@
import 'package:flutter/material.dart';
class SideMenu extends StatefulWidget {
final Widget body;
const SideMenu({Key? key, required this.body}) : super(key: key);
@override
State<SideMenu> createState() => _SideMenuState();
}
class _SideMenuState extends State<SideMenu> {
int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('SkanTavels'),
),
drawer: 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.pushReplacementNamed(context, '/home');
},
),
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.pushReplacementNamed(context, '/profile');
},
),
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.pushReplacementNamed(context, '/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.pushReplacementNamed(context, '/login');
},
),
],
),
),
body: widget.body,
);
}
}

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mobile/base/sidemenu.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'register.dart'; import 'register.dart';
import 'api.dart' as api; import 'api.dart' as api;
@ -18,8 +17,7 @@ class _LoginPageState extends State<LoginPage> {
final passwordInput = TextEditingController(); final passwordInput = TextEditingController();
Future<void> _login() async { Future<void> _login() async {
final token = await api final token = await api.request(context, api.ApiService.auth, 'POST', '/api/Users/login', {
.request(context, api.ApiService.auth, 'POST', '/api/Users/login', {
'email': emailInput.text, 'email': emailInput.text,
'password': passwordInput.text, 'password': passwordInput.text,
}); });
@ -30,47 +28,40 @@ class _LoginPageState extends State<LoginPage> {
prefs.setString('token', token); prefs.setString('token', token);
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Successfully logged in')));
const SnackBar(content: Text('Successfully logged in')));
Navigator.pop(context); Navigator.pop(context);
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SideMenu( return Scaffold(
body: Scaffold( appBar: AppBar(
body: Center( backgroundColor: Theme.of(context).colorScheme.inversePrimary,
child: Container( title: Text(widget.title),
constraints: ),
const BoxConstraints(minWidth: 100, maxWidth: 400), body: Center(
child: Column(children: [ child: Container(
constraints: const BoxConstraints(minWidth: 100, maxWidth: 400),
child: Column(
children: [
const SizedBox(height: 80), const SizedBox(height: 80),
const Text('Email'), const Text('Email'),
TextField(controller: emailInput), TextField(controller: emailInput),
const SizedBox(height: 30), const SizedBox(height: 30),
const Text('Password'), const Text('Password'),
TextField( TextField(controller: passwordInput, obscureText: true, enableSuggestions: false, autocorrect: false),
controller: passwordInput,
obscureText: true,
enableSuggestions: false,
autocorrect: false),
const SizedBox(height: 30), const SizedBox(height: 30),
ElevatedButton(onPressed: _login, child: const Text('Login')), ElevatedButton(onPressed: _login, child: const Text('Login')),
const SizedBox(height: 10), const SizedBox(height: 10),
TextButton( TextButton(
child: const Text('Register account'), child: const Text('Register account'),
onPressed: () => Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const RegisterPage(title: 'Register')))), onPressed: () => Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const RegisterPage(title: 'Register'))),
ElevatedButton(onPressed: _login, child: const Text('Log ind')), )
const SizedBox(height: 10), ]
TextButton( )
child: const Text('Registrer konto'), )
onPressed: () => Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const RegisterPage(title: 'Registrer'))), )
),
]),
),
),
),
); );
} }

View File

@ -5,9 +5,6 @@ import 'package:mobile/register.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'login.dart'; import 'login.dart';
import 'api.dart' as api; import 'api.dart' as api;
import 'base/sidemenu.dart';
import "login.dart";
import 'profile.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -24,15 +21,6 @@ class MyApp extends StatelessWidget {
useMaterial3: true, useMaterial3: true,
), ),
home: const MyHomePage(title: 'SkanTravels'), home: const MyHomePage(title: 'SkanTravels'),
initialRoute: '/',
routes: {
'/home': (context) => const MyHomePage(
title: 'SkasdanTravels',
),
'/profile': (context) => const ProfilePage(),
'/login': (context) => const LoginPage(title: 'SkanTravels'),
'/register': (context) => const RegisterPage(title: 'SkanTravels'),
},
); );
} }
} }
@ -89,32 +77,21 @@ class _MyHomePageState extends State<MyHomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SideMenu( return Scaffold(
body: Scaffold( key: _scaffoldKey,
key: _scaffoldKey, appBar: AppBar(
appBar: AppBar( backgroundColor: Theme.of(context).colorScheme.inversePrimary,
backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(widget.title),
title: Text(widget.title), ),
), drawer: navigationMenu,
drawer: navigationMenu,
body: FlutterMap( body: FlutterMap(
options: const MapOptions( options: const MapOptions(
initialCenter: LatLng(55.9397, 9.5156), initialZoom: 7.0), initialCenter: LatLng(55.9397, 9.5156), initialZoom: 7.0),
children: [ children: [
openStreetMapTileLayer, TileLayer(
const MarkerLayer(markers: [ urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
Marker( userAgentPackageName: 'dev.fleaflet.flutter_map.example',
point: LatLng(56.465511, 9.411366), )
width: 60,
height: 100,
alignment: Alignment.center,
child: Icon(
Icons.location_pin,
size: 60,
color: Colors.purple,
),
),
]),
], ],
), ),
floatingActionButton: Row( floatingActionButton: Row(
@ -130,99 +107,93 @@ class _MyHomePageState extends State<MyHomePage> {
), ),
], ],
), ),
),
); );
} }
Drawer get navigationMenu => Drawer( Drawer get navigationMenu => Drawer(
child: ListView( child: ListView(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
children: [ children: [
const DrawerHeader( const DrawerHeader(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.blue, color: Colors.blue,
), ),
child: Text('Drawer Header'), 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,
),
...(
_isLoggedIn ? [
ListTile( ListTile(
title: const Text('Log out'), title: const Text('Home'),
leading: const Icon(Icons.logout), leading: const Icon(Icons.home),
selected: false, selected: _selectedIndex == 0,
onTap: _logout,
)
] : [
ListTile(
title: const Text('Register'),
leading: const Icon(Icons.add_box_outlined),
selected: _selectedIndex == 3,
onTap: () { onTap: () {
// Update the state of the app // Update the state of the app
_onItemTapped(3); _onItemTapped(0);
// Then close the drawer // Then close the drawer
Navigator.push(context, MaterialPageRoute(builder: (context) => const RegisterPage(title: 'Register'))) Navigator.pop(context);
.then(_postNavigationCallback);
}, },
), ),
ListTile( ListTile(
title: const Text('Login'), title: const Text('Favourites'),
leading: const Icon(Icons.login), leading: const Icon(Icons.star),
selected: _selectedIndex == 4, selected: _selectedIndex == 1,
onTap: () { onTap: () {
// Update the state of the app // Update the state of the app
_onItemTapped(4); _onItemTapped(1);
// Then close the drawer // Then close the drawer
Navigator.push(context, MaterialPageRoute(builder: (context) => const LoginPage(title: 'Login'))) Navigator.pop(context);
.then(_postNavigationCallback);
}, },
),
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,
),
...(
_isLoggedIn ? [
ListTile(
title: const Text('Log out'),
leading: const Icon(Icons.logout),
selected: false,
onTap: _logout,
)
] : [
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')))
.then(_postNavigationCallback);
},
),
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')))
.then(_postNavigationCallback);
},
)
]
) )
] ]
) ),
], );
),
);
TileLayer get openStreetMapTileLayer => TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'dev.fleaflet.flutter_map.example',
);
} }

View File

@ -1,15 +1 @@
import 'package:flutter/material.dart';
import 'base/sidemenu.dart'; // Import the base layout widget
class ProfilePage extends StatelessWidget {
const ProfilePage({super.key});
@override
Widget build(BuildContext context) {
return const SideMenu(
body: Center(
child: Text('This is Page 1'),
),
);
}
}

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mobile/base/sidemenu.dart';
import 'login.dart'; import 'login.dart';
import 'api.dart' as api; import 'api.dart' as api;
@ -18,8 +17,7 @@ class _RegisterPageState extends State<RegisterPage> {
final passwordInput = TextEditingController(); final passwordInput = TextEditingController();
Future<void> _register() async { Future<void> _register() async {
final result = final result = await api.request(context, api.ApiService.auth, 'POST', '/api/Users', {
await api.request(context, api.ApiService.auth, 'POST', '/api/Users', {
'username': usernameInput.text, 'username': usernameInput.text,
'email': emailInput.text, 'email': emailInput.text,
'password': passwordInput.text, 'password': passwordInput.text,
@ -28,24 +26,23 @@ class _RegisterPageState extends State<RegisterPage> {
if (result == null) return; if (result == null) return;
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Successfully registered, please login')));
content: Text('Successfully registered, please login'))); Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const LoginPage(title: 'Log ind')));
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const LoginPage(title: 'Log ind')));
} }
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SideMenu( return Scaffold(
body: Scaffold( appBar: AppBar(
body: Center( backgroundColor: Theme.of(context).colorScheme.inversePrimary,
child: Container( title: Text(widget.title),
constraints: ),
const BoxConstraints(minWidth: 100, maxWidth: 400), body: Center(
child: Column(children: [ child: Container(
constraints: const BoxConstraints(minWidth: 100, maxWidth: 400),
child: Column(
children: [
const SizedBox(height: 80), const SizedBox(height: 80),
const Text('Username'), const Text('Username'),
TextField(controller: usernameInput), TextField(controller: usernameInput),
@ -54,11 +51,7 @@ class _RegisterPageState extends State<RegisterPage> {
TextField(controller: emailInput), TextField(controller: emailInput),
const SizedBox(height: 30), const SizedBox(height: 30),
const Text('Password'), const Text('Password'),
TextField( TextField(controller: passwordInput, obscureText: true, enableSuggestions: false, autocorrect: false),
controller: passwordInput,
obscureText: true,
enableSuggestions: false,
autocorrect: false),
const SizedBox(height: 30), const SizedBox(height: 30),
ElevatedButton(onPressed: _register, child: const Text('Register')), ElevatedButton(onPressed: _register, child: const Text('Register')),
const SizedBox(height: 10), const SizedBox(height: 10),
@ -66,10 +59,10 @@ class _RegisterPageState extends State<RegisterPage> {
child: const Text('Login'), child: const Text('Login'),
onPressed: () => Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const LoginPage(title: 'Login'))) onPressed: () => Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => const LoginPage(title: 'Login')))
), ),
]), ]
), )
), )
), )
); );
} }