ft/adds persistence

TODO: Logout function
This commit is contained in:
itsscb 2023-10-30 00:38:03 +01:00
parent dc3a28ba5f
commit 0c0b0b4594
2 changed files with 39 additions and 3 deletions

View File

@ -91,6 +91,11 @@ class Session {
print('INSERT RESULT: $result');
}
Future<void> removeSession(String sessionId) async {
final db = _database;
await db.delete('sessions', where: 'sessionId = ?', whereArgs: [sessionId]);
}
Future<List<Session>> getSessions() async {
final db = await database;

View File

@ -21,7 +21,10 @@ class _StartPageState extends State<StartPage> {
final List<BottomNavigationBarItem> 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<StartPage> {
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<StartPage> {
}
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,
)