Add logout button (Fixes #1)

This commit is contained in:
Lea 2023-01-16 10:59:35 +01:00
parent 66def02aba
commit 26880f8fb3
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
2 changed files with 51 additions and 2 deletions

View file

@ -14,6 +14,13 @@ class APICache {
feeds = ObjectCache(api);
groups = ObjectCache(api);
}
void clear() {
items._items.clear();
feeds._items.clear();
groups._items.clear();
feedsGroups.clear();
}
}
class ObjectCache<K, T> {
@ -40,7 +47,8 @@ class ObjectCache<K, T> {
class ItemCache extends ObjectCache<int, Item> {
/// Get all items for a given feed
List<Item> getForFeed(int feed) {
if (api.cache.feeds.get(feed) == null) throw Exception('Feed $feed doesn\'t exist');
if (api.cache.feeds.get(feed) == null)
throw Exception('Feed $feed doesn\'t exist');
return _items.values.where((item) => item.feedId == feed).toList();
}

View file

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:feet/pages/login.dart';
import 'package:feet/widgets/centered_page_hint.dart';
import 'package:feet/widgets/homepage_post.dart';
import 'package:feet/widgets/login_prompt.dart';
@ -167,7 +168,47 @@ class _MyHomePageState extends State<MyHomePage> {
});
},
icon: const Icon(Icons.replay_outlined),
),
), // Refresh
PopupMenuButton(
itemBuilder: (context) => [
PopupMenuItem(
value: "log_out",
child: const Text("Log out"),
onTap: () {
Future.delayed(
const Duration(seconds: 0),
() => showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text("Log out"),
content: const Text(
"Are you sure you want to log out?"),
actions: [
TextButton(
onPressed: () async {
Navigator.pop(context);
await widget.prefs.clear();
setState(() {
widget.api.apiKey = null;
widget.api.apiUrl = null;
widget.api.cache.clear();
});
},
child: const Text("Do it!")),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("Nevermind"),
),
],
),
),
);
},
)
]),
],
),
bottomNavigationBar: BottomNavigationBar(