Make demo warning appear correctly
This commit is contained in:
parent
93670f7c3d
commit
42423f50ec
263
lib/main.dart
263
lib/main.dart
|
@ -139,6 +139,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
super.initState();
|
||||
|
||||
setState(() {
|
||||
print("Demo: ${widget.prefs.getBool("isDemo")}");
|
||||
_isDemoUser = widget.prefs.getBool("isDemo") ?? false;
|
||||
});
|
||||
|
||||
|
@ -149,6 +150,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var isDemo = widget.prefs.getBool("isDemo");
|
||||
if (isDemo != _isDemoUser) {
|
||||
setState(() {
|
||||
_isDemoUser = isDemo ?? false;
|
||||
});
|
||||
}
|
||||
|
||||
var loggedIn = widget.api.loggedIn();
|
||||
var posts = widget.api.cache.items.getAll().values.where((element) =>
|
||||
_feedFilter.isEmpty || _feedFilter.contains(element.feedId));
|
||||
|
@ -209,140 +217,145 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.title),
|
||||
actions: [
|
||||
_isDemoUser
|
||||
? ElevatedButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Connected to demo server"),
|
||||
content: RichText(text: TextSpan(
|
||||
children: [
|
||||
const TextSpan(
|
||||
text: "You are currently connected to the demo server.\n"
|
||||
"Use the"
|
||||
),
|
||||
WidgetSpan(child: Icon(Icons.adaptive.more, size: 20),
|
||||
),
|
||||
const TextSpan(
|
||||
text: "button in the top right to log out and switch "
|
||||
"to your own instance once you're done exploring."
|
||||
),
|
||||
],
|
||||
)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text("Got it!"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color.fromARGB(255, 114, 77, 7),
|
||||
foregroundColor: Colors.amber,
|
||||
),
|
||||
child: Row(children: const [
|
||||
Icon(Icons.warning),
|
||||
SizedBox(width: 8),
|
||||
Text("Demo"),
|
||||
])
|
||||
)
|
||||
: Container(),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
var theme = Theme.of(context);
|
||||
|
||||
HapticFeedback.heavyImpact();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Refreshing feeds',
|
||||
style: TextStyle(color: theme.colorScheme.onBackground)),
|
||||
duration: const Duration(seconds: 2),
|
||||
backgroundColor: theme.colorScheme.secondaryContainer,
|
||||
),
|
||||
);
|
||||
refresh().then((_) {
|
||||
setState(() {});
|
||||
});
|
||||
},
|
||||
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(
|
||||
actions: loggedIn
|
||||
? [
|
||||
_isDemoUser
|
||||
? ElevatedButton(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Log out"),
|
||||
content: const Text(
|
||||
"Are you sure you want to log out?"),
|
||||
title: const Text("Connected to demo server"),
|
||||
content: RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
const TextSpan(
|
||||
text:
|
||||
"You are currently connected to the demo server.\n"
|
||||
"Use the"),
|
||||
WidgetSpan(
|
||||
child: Icon(Icons.adaptive.more, size: 20),
|
||||
),
|
||||
const TextSpan(
|
||||
text:
|
||||
"button in the top right to log out and switch "
|
||||
"to your own instance once you're done exploring."),
|
||||
],
|
||||
)),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Nevermind"),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text("Got it!"),
|
||||
),
|
||||
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!")),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
const Color.fromARGB(255, 114, 77, 7),
|
||||
foregroundColor: Colors.amber,
|
||||
),
|
||||
child: Row(children: const [
|
||||
Icon(Icons.warning),
|
||||
SizedBox(width: 8),
|
||||
Text("Demo"),
|
||||
]))
|
||||
: Container(),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
var theme = Theme.of(context);
|
||||
|
||||
HapticFeedback.heavyImpact();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Refreshing feeds',
|
||||
style: TextStyle(
|
||||
color: theme.colorScheme.onBackground)),
|
||||
duration: const Duration(seconds: 2),
|
||||
backgroundColor: theme.colorScheme.secondaryContainer,
|
||||
),
|
||||
);
|
||||
refresh().then((_) {
|
||||
setState(() {});
|
||||
});
|
||||
},
|
||||
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: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text("Nevermind"),
|
||||
),
|
||||
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!")),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: "filter",
|
||||
child: Text(_feedFilter.isEmpty
|
||||
? "Filter..."
|
||||
: "Filter (${_feedFilter.length}/${widget.api.cache.feeds.size})"),
|
||||
onTap: () {
|
||||
Future.delayed(
|
||||
Duration.zero,
|
||||
() => showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => FilterMenu(
|
||||
api: widget.api,
|
||||
initData: _feedFilter,
|
||||
onConfirm: (items) {
|
||||
setState(() {
|
||||
_feedFilter = items;
|
||||
});
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: "filter",
|
||||
child: Text(_feedFilter.isEmpty
|
||||
? "Filter..."
|
||||
: "Filter (${_feedFilter.length}/${widget.api.cache.feeds.size})"),
|
||||
onTap: () {
|
||||
Future.delayed(
|
||||
Duration.zero,
|
||||
() => showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => FilterMenu(
|
||||
api: widget.api,
|
||||
initData: _feedFilter,
|
||||
onConfirm: (items) {
|
||||
setState(() {
|
||||
_feedFilter = items;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: "feedback",
|
||||
child: const Text("Feedback"),
|
||||
onTap: () async {
|
||||
await openUrl(context,
|
||||
"https://git.amogus.cloud/Lea/feet/issues");
|
||||
},
|
||||
),
|
||||
]),
|
||||
],
|
||||
PopupMenuItem(
|
||||
value: "feedback",
|
||||
child: const Text("Feedback"),
|
||||
onTap: () async {
|
||||
await openUrl(context,
|
||||
"https://git.amogus.cloud/Lea/feet/issues");
|
||||
},
|
||||
),
|
||||
]),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: _index,
|
||||
|
|
Loading…
Reference in a new issue