diff --git a/frontend/app/lib/gapi/client.dart b/frontend/app/lib/gapi/client.dart index aae5a46..3ec591a 100644 --- a/frontend/app/lib/gapi/client.dart +++ b/frontend/app/lib/gapi/client.dart @@ -23,7 +23,9 @@ class GClient { GClient c = GClient(); c.session = s; final sessions = await c.session.getSessions(); - c.session = sessions[0]; + if (sessions.isNotEmpty) { + c.session = sessions[0]; + } return c; } @@ -43,7 +45,9 @@ class GClient { session = await Session.newSession; final sessions = await session.getSessions(); - session = sessions[0]; + if (sessions.isNotEmpty) { + session = sessions[0]; + } } Future createAccount( diff --git a/frontend/app/lib/main.dart b/frontend/app/lib/main.dart index 78e9a9a..8e44a71 100644 --- a/frontend/app/lib/main.dart +++ b/frontend/app/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:app/gapi/client.dart'; import 'package:app/pages/start_page.dart'; import 'package:app/widgets/background.dart'; import 'package:flutter/material.dart'; @@ -43,7 +44,9 @@ void main() async { foregroundColor: Colors.white, )), home: Background( - child: StartPage(), + child: StartPage( + client: await GClient.client, + ), ), ), ); diff --git a/frontend/app/lib/pages/dashboard_page.dart b/frontend/app/lib/pages/dashboard_page.dart index 6db7ed0..7279de4 100644 --- a/frontend/app/lib/pages/dashboard_page.dart +++ b/frontend/app/lib/pages/dashboard_page.dart @@ -1,12 +1,18 @@ import 'package:app/gapi/client.dart'; +import 'package:app/pages/start_page.dart'; import 'package:app/pb/account_info.pb.dart'; import 'package:app/pb/rpc_get_account_info.pb.dart'; import 'package:app/widgets/background.dart'; +import 'package:app/widgets/bottom_bar.dart'; import 'package:app/widgets/loading_widget.dart'; +import 'package:app/widgets/side_drawer.dart'; import 'package:flutter/material.dart'; class DashboardPage extends StatefulWidget { - const DashboardPage({super.key, required this.client}); + const DashboardPage({ + super.key, + required this.client, + }); final GClient client; @@ -27,10 +33,6 @@ class _DashboardPageState extends State { @override void initState() { super.initState(); - // if (widget.client.session.accessToken == '') { - // Navigator.of(context).pop(); - // return; - // } _setLoading(true); widget.client.getAccountInfo( @@ -59,7 +61,193 @@ class _DashboardPageState extends State { height: 80, ), ), - bottomNavigationBar: BottomBar(), + drawer: Builder(builder: (context) { + return SideDrawer( + children: [ + const Spacer(), + TextButton( + onPressed: () { + Scaffold.of(context).closeDrawer(); + }, + child: const Row( + children: [ + Text( + 'About', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.question_answer, + color: Colors.white, + ), + ], + ), + ), + TextButton( + onPressed: () { + Scaffold.of(context).closeDrawer(); + }, + child: const Row( + children: [ + Text( + 'Datenschutz', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.privacy_tip, + color: Colors.white, + ), + ], + ), + ), + TextButton( + onPressed: () { + Scaffold.of(context).closeDrawer(); + }, + child: const Row( + children: [ + Text( + 'Impressum', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.apartment, + color: Colors.white, + ), + ], + ), + ), + if (widget.client.session.accessToken != null) + TextButton( + onPressed: () { + widget.client.session.accessToken = null; + widget.client.session + .removeSession(widget.client.session.sessionId!); + + Navigator.of(context).pop(widget.client); + }, + child: const Row( + children: [ + Text( + 'Log out', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.logout, + color: Colors.white, + ), + ], + ), + ), + const SizedBox( + height: 250, + ) + ], + ); + }), + bottomNavigationBar: Builder( + builder: (context) { + return BottomBar( + children: widget.client.session.accessToken != null + ? [ + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: 'Personen', + icon: Column( + children: [ + IconButton( + onPressed: () => + Scaffold.of(context).openDrawer(), + icon: const Icon( + Icons.group, + color: Colors.white, + ), + ), + const Text( + 'Personen', + style: TextStyle( + color: Colors.white, + fontSize: 16, + ), + ) + ], + ), + ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: 'Home', + icon: Column( + children: [ + IconButton( + onPressed: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => StartPage( + client: widget.client, + ), + ), + ); + }, + icon: const Icon( + Icons.home, + color: Colors.white, + ), + ), + const Text( + 'Home', + style: TextStyle( + color: Colors.white, + fontSize: 16, + ), + ) + ], + ), + ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: 'Menu', + icon: IconButton( + onPressed: () { + Scaffold.of(context).openDrawer(); + }, + icon: const Icon( + Icons.menu, + color: Colors.white, + ), + ), + ) + ] + : [ + BottomNavigationBarItem( + label: 'back', + backgroundColor: Colors.white, + icon: IconButton( + onPressed: () => + Navigator.of(context).pop(widget.client), + icon: const Icon( + Icons.arrow_back, + color: Colors.white, + ), + ), + ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: 'Menu', + icon: IconButton( + onPressed: () => Scaffold.of(context).openDrawer(), + icon: const Icon( + Icons.menu, + color: Colors.white, + ), + ), + ), + ], + ); + }, + ), body: !_loading ? Background( child: Center( @@ -83,40 +271,3 @@ class _DashboardPageState extends State { ); } } - -class BottomBar extends StatelessWidget { - const BottomBar({ - super.key, - }); - - @override - Widget build(BuildContext context) { - return BottomNavigationBar( - items: [ - BottomNavigationBarItem( - label: 'back', - backgroundColor: Colors.white, - icon: IconButton( - onPressed: () => Navigator.of(context).pop(), - icon: const Icon( - Icons.arrow_back, - color: Colors.white, - ), - ), - ), - BottomNavigationBarItem( - backgroundColor: Colors.white, - label: 'Menu', - icon: IconButton( - onPressed: () => Scaffold.of(context).openDrawer(), - icon: const Icon( - Icons.person, - color: Colors.white, - ), - ), - ), - ], - backgroundColor: Colors.black, - ); - } -} diff --git a/frontend/app/lib/pages/login_page.dart b/frontend/app/lib/pages/login_page.dart index 4856e08..26d7482 100644 --- a/frontend/app/lib/pages/login_page.dart +++ b/frontend/app/lib/pages/login_page.dart @@ -35,7 +35,7 @@ class _LoginPageState extends State { void _bottomBarAction(int index) { switch (bottombarButtons[index].label?.toLowerCase()) { case 'back': - Navigator.of(context).pop(); + Navigator.of(context).pop(client); } } @@ -92,7 +92,7 @@ class _LoginPageState extends State { label: 'back', backgroundColor: Colors.white, icon: IconButton( - onPressed: () => Navigator.of(context).pop(), + onPressed: () => Navigator.of(context).pop(client), icon: const Icon( Icons.arrow_back, color: Colors.white, diff --git a/frontend/app/lib/pages/start_page.dart b/frontend/app/lib/pages/start_page.dart index e3f2ba9..c4f76db 100644 --- a/frontend/app/lib/pages/start_page.dart +++ b/frontend/app/lib/pages/start_page.dart @@ -1,4 +1,5 @@ import 'package:app/gapi/client.dart'; +import 'package:app/pages/dashboard_page.dart'; import 'package:app/pages/login_page.dart'; import 'package:app/widgets/background.dart'; import 'package:app/widgets/bottom_bar.dart'; @@ -9,10 +10,10 @@ import 'dart:core'; class StartPage extends StatefulWidget { StartPage({ super.key, - this.client, + required this.client, }); - GClient? client; + GClient client; @override State createState() => _StartPageState(); @@ -42,88 +43,90 @@ class _StartPageState extends State { appBar: AppBar( automaticallyImplyLeading: false, ), - drawer: SideDrawer(children: [ - const Spacer(), - TextButton( - onPressed: () { - Scaffold.of(context).closeDrawer(); - }, - child: const Row( - children: [ - Text( - 'About', - style: TextStyle(fontSize: 20), - ), - Spacer(), - Icon( - Icons.question_answer, - color: Colors.white, - ), - ], + drawer: Builder(builder: (context) { + return SideDrawer(children: [ + const Spacer(), + TextButton( + onPressed: () { + Scaffold.of(context).closeDrawer(); + }, + child: const Row( + children: [ + Text( + 'About', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.question_answer, + color: Colors.white, + ), + ], + ), ), - ), - TextButton( - onPressed: () { - Scaffold.of(context).closeDrawer(); - }, - child: const Row( - children: [ - Text( - 'Datenschutz', - style: TextStyle(fontSize: 20), - ), - Spacer(), - Icon( - Icons.privacy_tip, - color: Colors.white, - ), - ], + TextButton( + onPressed: () { + Scaffold.of(context).closeDrawer(); + }, + child: const Row( + children: [ + Text( + 'Datenschutz', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.privacy_tip, + color: Colors.white, + ), + ], + ), ), - ), - TextButton( - onPressed: () { - Scaffold.of(context).closeDrawer(); - }, - child: const Row( - children: [ - Text( - 'Impressum', - style: TextStyle(fontSize: 20), - ), - Spacer(), - Icon( - Icons.apartment, - color: Colors.white, - ), - ], + TextButton( + onPressed: () { + Scaffold.of(context).closeDrawer(); + }, + child: const Row( + children: [ + Text( + 'Impressum', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.apartment, + color: Colors.white, + ), + ], + ), ), - ), - TextButton( - onPressed: () { - setState(() { - widget.client?.session.accessToken = null; - widget.client?.session - .removeSession(widget.client!.session.sessionId!); - }); - }, - child: const Row( - children: [ - Text( - 'Log out', - style: TextStyle(fontSize: 20), - ), - Spacer(), - Icon( - Icons.logout, - color: Colors.white, - ), - ], + TextButton( + onPressed: () { + setState(() { + widget.client?.session.accessToken = null; + widget.client?.session + .removeSession(widget.client!.session.sessionId!); + }); + }, + child: const Row( + children: [ + Text( + 'Log out', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.logout, + color: Colors.white, + ), + ], + ), ), - ), - const SizedBox( - height: 250, - ) - ]), + const SizedBox( + height: 250, + ) + ]); + }), bottomNavigationBar: Builder(builder: (context) { return BottomBar( // onTap: (value) => _bottomBarAction(value), @@ -151,6 +154,44 @@ class _StartPageState extends State { ], ), ), + BottomNavigationBarItem( + backgroundColor: Colors.white, + label: 'Dashboard', + icon: Column( + children: [ + IconButton( + onPressed: () async { + // setState(() { + + GClient c = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => DashboardPage( + client: widget.client!, + ), + ), + ); + print('Got Client back: $c'); + // }); + setState(() { + widget.client = c; + }); + }, + icon: const Icon( + Icons.dashboard, + color: Colors.white, + ), + ), + const Text( + 'Dashboard', + style: TextStyle( + color: Colors.white, + fontSize: 16, + ), + ) + ], + ), + ), BottomNavigationBarItem( backgroundColor: Colors.white, label: 'Menu', @@ -172,9 +213,11 @@ class _StartPageState extends State { icon: Column( children: [ IconButton( - onPressed: () { - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => LoginPage())); + onPressed: () async { + widget.client = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LoginPage())); }, icon: const Icon( Icons.login, @@ -197,9 +240,11 @@ class _StartPageState extends State { icon: Column( children: [ IconButton( - onPressed: () { - Navigator.of(context).push(MaterialPageRoute( - builder: (context) => LoginPage())); + onPressed: () async { + widget.client = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) => LoginPage())); }, icon: const Icon( Icons.login,