Add log out button
This commit is contained in:
parent
5c4526f1fc
commit
e478552587
|
@ -1,6 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:zenith/login.dart';
|
||||
import 'package:zenith/room.dart';
|
||||
import 'package:zenith/zenith_client_provider.dart';
|
||||
|
||||
|
@ -30,6 +32,48 @@ class _RoomsPageState extends State<RoomsPage> {
|
|||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
title: const Text("Zenith"),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Log out?"),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: const Text("Cancel")),
|
||||
ElevatedButton(
|
||||
child: const Text("Confirm"),
|
||||
onPressed: () async {
|
||||
print("Logging out...");
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.remove("homeserver");
|
||||
prefs.remove("username");
|
||||
prefs.remove("password");
|
||||
|
||||
if (!mounted) return;
|
||||
final provider = Provider.of<ZenithClientProvider>(
|
||||
context,
|
||||
listen: false);
|
||||
await provider.client.logout();
|
||||
|
||||
if (!mounted) return;
|
||||
Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const LoginPage()),
|
||||
(route) => false);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.logout))
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
|
|
Loading…
Reference in New Issue
Block a user