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(); 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,7 +217,8 @@ 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 _isDemoUser
? ElevatedButton( ? ElevatedButton(
onPressed: () { onPressed: () {
@ -217,18 +226,20 @@ class _MyHomePageState extends State<MyHomePage> {
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
title: const Text("Connected to demo server"), title: const Text("Connected to demo server"),
content: RichText(text: TextSpan( content: RichText(
text: TextSpan(
children: [ children: [
const TextSpan( const TextSpan(
text: "You are currently connected to the demo server.\n" text:
"Use the" "You are currently connected to the demo server.\n"
), "Use the"),
WidgetSpan(child: Icon(Icons.adaptive.more, size: 20), WidgetSpan(
child: Icon(Icons.adaptive.more, size: 20),
), ),
const TextSpan( const TextSpan(
text: "button in the top right to log out and switch " text:
"to your own instance once you're done exploring." "button in the top right to log out and switch "
), "to your own instance once you're done exploring."),
], ],
)), )),
actions: [ actions: [
@ -241,15 +252,15 @@ class _MyHomePageState extends State<MyHomePage> {
); );
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 114, 77, 7), backgroundColor:
const Color.fromARGB(255, 114, 77, 7),
foregroundColor: Colors.amber, foregroundColor: Colors.amber,
), ),
child: Row(children: const [ child: Row(children: const [
Icon(Icons.warning), Icon(Icons.warning),
SizedBox(width: 8), SizedBox(width: 8),
Text("Demo"), Text("Demo"),
]) ]))
)
: Container(), : Container(),
IconButton( IconButton(
onPressed: () { onPressed: () {
@ -259,7 +270,8 @@ class _MyHomePageState extends State<MyHomePage> {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(
content: Text('Refreshing feeds', content: Text('Refreshing feeds',
style: TextStyle(color: theme.colorScheme.onBackground)), style: TextStyle(
color: theme.colorScheme.onBackground)),
duration: const Duration(seconds: 2), duration: const Duration(seconds: 2),
backgroundColor: theme.colorScheme.secondaryContainer, backgroundColor: theme.colorScheme.secondaryContainer,
), ),
@ -342,7 +354,8 @@ class _MyHomePageState extends State<MyHomePage> {
}, },
), ),
]), ]),
], ]
: [],
), ),
bottomNavigationBar: BottomNavigationBar( bottomNavigationBar: BottomNavigationBar(
currentIndex: _index, currentIndex: _index,