Add logout button (Fixes #1)
This commit is contained in:
parent
66def02aba
commit
26880f8fb3
|
@ -14,6 +14,13 @@ class APICache {
|
||||||
feeds = ObjectCache(api);
|
feeds = ObjectCache(api);
|
||||||
groups = ObjectCache(api);
|
groups = ObjectCache(api);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
items._items.clear();
|
||||||
|
feeds._items.clear();
|
||||||
|
groups._items.clear();
|
||||||
|
feedsGroups.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ObjectCache<K, T> {
|
class ObjectCache<K, T> {
|
||||||
|
@ -40,7 +47,8 @@ class ObjectCache<K, T> {
|
||||||
class ItemCache extends ObjectCache<int, Item> {
|
class ItemCache extends ObjectCache<int, Item> {
|
||||||
/// Get all items for a given feed
|
/// Get all items for a given feed
|
||||||
List<Item> getForFeed(int 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();
|
return _items.values.where((item) => item.feedId == feed).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:feet/pages/login.dart';
|
||||||
import 'package:feet/widgets/centered_page_hint.dart';
|
import 'package:feet/widgets/centered_page_hint.dart';
|
||||||
import 'package:feet/widgets/homepage_post.dart';
|
import 'package:feet/widgets/homepage_post.dart';
|
||||||
import 'package:feet/widgets/login_prompt.dart';
|
import 'package:feet/widgets/login_prompt.dart';
|
||||||
|
@ -167,9 +168,49 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.replay_outlined),
|
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(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
currentIndex: _index,
|
currentIndex: _index,
|
||||||
onTap: (value) => setState(() => _index = value),
|
onTap: (value) => setState(() => _index = value),
|
||||||
|
|
Loading…
Reference in a new issue