0

I am trying to show Snackbar on a Firebase Cloud Message event, not on the push of a button as most examples are showing. I have a DefaultTabController like the one below. Where would I put my Snackbar in the tree to have the message display in any of the tabs?

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      initialIndex: 1,
      length: 3,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.black,
          flexibleSpace: new Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              new TabBar(
                tabs: [
                  Tab(icon: Icon(Icons.person)),
                  Tab(icon: Icon(Icons.open)),
                  Tab(icon: Icon(Icons.people)),
                ],
              ),
            ],
          ),
        ),
        body: TabBarView(physics: NeverScrollableScrollPhysics(), children: [
          MyForm(),
          MyWidget(),
          MyOtherForm(),
        ]),
      ),
    );
  }
}
giorgio79
  • 3,787
  • 9
  • 53
  • 85

1 Answers1

1

I believe that as long as it's below the Scaffold it doesn't matter where the call is done.

Christopher Moore
  • 15,626
  • 10
  • 42
  • 52
  • Thanks Christopher! That one is understood. But what kind of widget? A 0 size Container as a TabbarView children? – giorgio79 Apr 08 '20 at 03:24
  • From my understanding, I don't think you want to put it in the build method. [See this](https://flutter.dev/docs/cookbook/design/snackbars) for how to use Snackbar and let me know if there are any other questions or issues. – Christopher Moore Apr 08 '20 at 03:28