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();
|
super.initState();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
|
print("Demo: ${widget.prefs.getBool("isDemo")}");
|
||||||
_isDemoUser = widget.prefs.getBool("isDemo") ?? false;
|
_isDemoUser = widget.prefs.getBool("isDemo") ?? false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -149,6 +150,13 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var isDemo = widget.prefs.getBool("isDemo");
|
||||||
|
if (isDemo != _isDemoUser) {
|
||||||
|
setState(() {
|
||||||
|
_isDemoUser = isDemo ?? false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var loggedIn = widget.api.loggedIn();
|
var loggedIn = widget.api.loggedIn();
|
||||||
var posts = widget.api.cache.items.getAll().values.where((element) =>
|
var posts = widget.api.cache.items.getAll().values.where((element) =>
|
||||||
_feedFilter.isEmpty || _feedFilter.contains(element.feedId));
|
_feedFilter.isEmpty || _feedFilter.contains(element.feedId));
|
||||||
|
@ -209,140 +217,145 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(widget.title),
|
title: Text(widget.title),
|
||||||
actions: [
|
actions: loggedIn
|
||||||
_isDemoUser
|
? [
|
||||||
? ElevatedButton(
|
_isDemoUser
|
||||||
onPressed: () {
|
? ElevatedButton(
|
||||||
showDialog(
|
onPressed: () {
|
||||||
context: context,
|
showDialog(
|
||||||
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(
|
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: const Text("Log out"),
|
title: const Text("Connected to demo server"),
|
||||||
content: const Text(
|
content: RichText(
|
||||||
"Are you sure you want to log out?"),
|
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: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
Navigator.pop(context);
|
child: const Text("Got it!"),
|
||||||
},
|
|
||||||
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!")),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
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
|
||||||
PopupMenuItem(
|
? "Filter..."
|
||||||
value: "filter",
|
: "Filter (${_feedFilter.length}/${widget.api.cache.feeds.size})"),
|
||||||
child: Text(_feedFilter.isEmpty
|
onTap: () {
|
||||||
? "Filter..."
|
Future.delayed(
|
||||||
: "Filter (${_feedFilter.length}/${widget.api.cache.feeds.size})"),
|
Duration.zero,
|
||||||
onTap: () {
|
() => showDialog(
|
||||||
Future.delayed(
|
context: context,
|
||||||
Duration.zero,
|
barrierDismissible: false,
|
||||||
() => showDialog(
|
builder: (context) => FilterMenu(
|
||||||
context: context,
|
api: widget.api,
|
||||||
barrierDismissible: false,
|
initData: _feedFilter,
|
||||||
builder: (context) => FilterMenu(
|
onConfirm: (items) {
|
||||||
api: widget.api,
|
setState(() {
|
||||||
initData: _feedFilter,
|
_feedFilter = items;
|
||||||
onConfirm: (items) {
|
});
|
||||||
setState(() {
|
},
|
||||||
_feedFilter = items;
|
),
|
||||||
});
|
),
|
||||||
},
|
);
|
||||||
),
|
},
|
||||||
),
|
),
|
||||||
);
|
PopupMenuItem(
|
||||||
},
|
value: "feedback",
|
||||||
),
|
child: const Text("Feedback"),
|
||||||
PopupMenuItem(
|
onTap: () async {
|
||||||
value: "feedback",
|
await openUrl(context,
|
||||||
child: const Text("Feedback"),
|
"https://git.amogus.cloud/Lea/feet/issues");
|
||||||
onTap: () async {
|
},
|
||||||
await openUrl(context,
|
),
|
||||||
"https://git.amogus.cloud/Lea/feet/issues");
|
]),
|
||||||
},
|
]
|
||||||
),
|
: [],
|
||||||
]),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
currentIndex: _index,
|
currentIndex: _index,
|
||||||
|
|
Loading…
Reference in a new issue