Make demo warning appear correctly

This commit is contained in:
Lea 2023-02-05 17:53:09 +01:00
parent 93670f7c3d
commit 42423f50ec
Signed by: Lea
GPG key ID: 1BAFFE8347019C42

View file

@ -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,7 +217,8 @@ class _MyHomePageState extends State<MyHomePage> {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: [
actions: loggedIn
? [
_isDemoUser
? ElevatedButton(
onPressed: () {
@ -217,18 +226,20 @@ class _MyHomePageState extends State<MyHomePage> {
context: context,
builder: (context) => AlertDialog(
title: const Text("Connected to demo server"),
content: RichText(text: TextSpan(
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),
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."
),
text:
"button in the top right to log out and switch "
"to your own instance once you're done exploring."),
],
)),
actions: [
@ -241,15 +252,15 @@ class _MyHomePageState extends State<MyHomePage> {
);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 114, 77, 7),
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: () {
@ -259,7 +270,8 @@ class _MyHomePageState extends State<MyHomePage> {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Refreshing feeds',
style: TextStyle(color: theme.colorScheme.onBackground)),
style: TextStyle(
color: theme.colorScheme.onBackground)),
duration: const Duration(seconds: 2),
backgroundColor: theme.colorScheme.secondaryContainer,
),
@ -342,7 +354,8 @@ class _MyHomePageState extends State<MyHomePage> {
},
),
]),
],
]
: [],
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _index,