Show snackbar after navigation

After the action, the user returns to another page in the application.

I want to show the snackbar on a new page, but I want this to be related to the save action (so as not to show when the user moves without the save action).

Here is my panel code that saves, but it does not show the snack bar - no matter where I place the snack bar (before or after navigation), it does not execute snacks.

Future<Null> saveThatThing() async {
  thing.save();
  thing = new Thing();
  Navigator.of(context).push(getSavedThingRoute());
  Scaffold.of(context).showSnackBar(
    new SnackBar(
      content: new Text('You saved the thing!'),
    ),
  );
}

What is the best way to do this?

+4
source share
2 answers

How about whether you create a key for a Scaffold screen like this (put this object in the screen state class):

final GlobalKey<ScaffoldState> scaffoldKey = new GlobalKey<ScaffoldState>();

and then set this variable like this:

return new Scaffold(
  key: scaffoldKey,
  appBar: new AppBar(
    .......,
  ),

, , SnackBar - :

scaffoldKey.currentState
    .showSnackBar(new SnackBar(content: new Text("Hello")));

:

void showInSnackBar(String value) {
scaffoldKey.currentState
    .showSnackBar(new SnackBar(content: new Text(value)));}

.

, - , .

,

+1

SackBar Scaffold, , - getSavedThingRoute(message: 'You saved the thing!'), .

, Navigation.pop({'message': 'You saved the thing!', 'error': false}) .

-2

Source: https://habr.com/ru/post/1691139/


All Articles