diff --git a/lib/api/cache.dart b/lib/api/cache.dart index 2ed4ad8..e29af69 100644 --- a/lib/api/cache.dart +++ b/lib/api/cache.dart @@ -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 { @@ -40,7 +47,8 @@ class ObjectCache { class ItemCache extends ObjectCache { /// Get all items for a given feed List 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(); } diff --git a/lib/main.dart b/lib/main.dart index cfe6401..d37d606 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { }); }, 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(