Jack Spicy
Jack Spicy

Reputation: 93

How to remove Snackbar when navigating to another view

@override
  void initState() {
    super.initState();
    _showFlushbar();
  }

  _showFlushbar() async {
    await Future.delayed(Duration(milliseconds: 500));
    defaultFlushbar(
      context: context,
      message:
          'Success',
      padding: 50.0,
    );
  }

When I navigate to screen, it shows me Flushbar as I expected. But since it have Future.delayed duration, I can't remove it when navigating to another view. How I can remove it without changing duration.

Thanks

Upvotes: 1

Views: 1119

Answers (1)

griffins
griffins

Reputation: 8274

in flutter initState

Called when this object is inserted into the tree.The framework will call this method exactly once for each State object it creates.

hence your _showFlushbar is only called once when you create object. Unless you're refrencing it elsewhere it should only be displayed once.

Due to the delay,it will display later after widget was created

you can always dispose

@override
  void dispose() {
    FlashHelper.dispose();
    super.dispose();
  }

Upvotes: 1

Related Questions