diff --git a/frontend/app/lib/data/database.dart b/frontend/app/lib/data/database.dart index 6d47478..6342ddb 100644 --- a/frontend/app/lib/data/database.dart +++ b/frontend/app/lib/data/database.dart @@ -91,6 +91,11 @@ class Session { print('INSERT RESULT: $result'); } + Future removeSession(String sessionId) async { + final db = _database; + await db.delete('sessions', where: 'sessionId = ?', whereArgs: [sessionId]); + } + Future> getSessions() async { final db = await database; diff --git a/frontend/app/lib/pages/start_page.dart b/frontend/app/lib/pages/start_page.dart index 308619a..b106f3b 100644 --- a/frontend/app/lib/pages/start_page.dart +++ b/frontend/app/lib/pages/start_page.dart @@ -21,7 +21,10 @@ class _StartPageState extends State { final List bottombarButtons = []; void _init() async { - widget.client ??= await GClient.client; + final c = await GClient.client; + setState(() { + widget.client = c; + }); } @override @@ -37,7 +40,14 @@ class _StartPageState extends State { appBar: AppBar( automaticallyImplyLeading: false, ), - drawer: const SideDrawer(), + drawer: SideDrawer( + onLogout: () { + setState(() { + widget.client?.session + .removeSession(widget.client!.session.sessionId!); + }); + }, + ), bottomNavigationBar: BottomBar(widget: widget), body: Padding( padding: const EdgeInsets.all(16.0), @@ -121,10 +131,13 @@ class _StartPageState extends State { } class SideDrawer extends StatelessWidget { - const SideDrawer({ + SideDrawer({ super.key, + required this.onLogout, }); + Function() onLogout; + @override Widget build(BuildContext context) { return Drawer( @@ -189,6 +202,24 @@ class SideDrawer extends StatelessWidget { ], ), ), + TextButton( + onPressed: () { + onLogout(); + }, + child: const Row( + children: [ + Text( + 'Log out', + style: TextStyle(fontSize: 20), + ), + Spacer(), + Icon( + Icons.logout, + color: Colors.white, + ), + ], + ), + ), const SizedBox( height: 250, )