add keys to scaffolds so that snackbars work properly

This commit is contained in:
krawieck 2020-09-21 23:15:45 +02:00
parent 3ca16ccf21
commit 2c89534e2d
2 changed files with 11 additions and 6 deletions

View File

@ -12,9 +12,9 @@ import 'add_instance.dart';
class AddAccountPage extends HookWidget {
final String instanceUrl;
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
const AddAccountPage({@required this.instanceUrl})
: assert(instanceUrl != null);
AddAccountPage({@required this.instanceUrl}) : assert(instanceUrl != null);
@override
Widget build(BuildContext context) {
@ -84,7 +84,7 @@ class AddAccountPage extends HookWidget {
passwordController.text,
);
} on Exception catch (err) {
Scaffold.of(context).showSnackBar(SnackBar(
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(err.toString()),
));
}
@ -93,6 +93,7 @@ class AddAccountPage extends HookWidget {
}
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
leading: CloseButton(),
actionsIconTheme: theme.iconTheme,

View File

@ -9,6 +9,10 @@ import '../hooks/stores.dart';
import '../widgets/fullscreenable_image.dart';
class AddInstancePage extends HookWidget {
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
AddInstancePage();
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@ -44,20 +48,20 @@ class AddInstancePage extends HookWidget {
await accountsStore.addInstance(instanceController.text);
Navigator.of(context).pop(instanceController.text);
} on Exception catch (err) {
Scaffold.of(context).showSnackBar(SnackBar(
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(err.toString()),
));
} catch (err) {
Scaffold.of(context).showSnackBar(SnackBar(
scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text('UNKNOWN ERROR ${err.toString()}'),
));
}
delayedLoading.cancel();
loading.value = false;
Navigator.of(context).pop();
}
return Scaffold(
key: scaffoldKey,
appBar: AppBar(
backgroundColor: theme.scaffoldBackgroundColor,
brightness: theme.brightness,