1

I am using the below code. I got the bottom navigation bar to give an overflow exception. Please anyone help me to solve this problem.

return DefaultTabController(
        length: 2,
        child: Scaffold(
          backgroundColor: Colors.white,
          appBar: AppBar(
            backgroundColor: Theme.of(context).primaryColor,
            actions: [
              IconButton(
                onPressed: () {
                  openUrl("https://www.trustdidi.com/help");
                },
                icon: Icon(Icons.help_outline),
              ),
              IconButton(
                onPressed: () {
                  showComingSoonToast();
                },
                icon: Icon(Icons.notifications),
              ),
            ],
            bottom: TabBar(
              tabs: [
                Tab(
                    icon: Icon(
                  Icons.directions_car,
                  color: Colors.white,
                )),
                Tab(icon: Icon(Icons.directions_transit)),
              ],
            ),
          ),
          body: SafeArea(
            child: TabBarView(
              children: [
                Icon(
                  Icons.directions_car,
                  color: Colors.redAccent,
                ),
                Icon(Icons.directions_transit),
              ],
            ),
          ),
        ));

Buts it gives below error

enter image description here

1 Answer 1

1

you should try with tabbar controller.And then initial it

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>  with TickerProviderStateMixin {

  TabController _tabController;

  @override
  void initState() {
    _tabController = new TabController(length: 2, vsync: this, initialIndex: 0);
    super.initState();
  }
  

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 2,
        child: Scaffold(
          backgroundColor: Colors.white,
          appBar: AppBar(
            backgroundColor: Theme.of(context).primaryColor,
            actions: [
              IconButton(
                onPressed: () {
                 // openUrl("https://www.trustdidi.com/help");
                },
                icon: Icon(Icons.help_outline),
              ),
              IconButton(
                onPressed: () {
                 // showComingSoonToast();
                },
                icon: Icon(Icons.notifications),
              ),
            ],
            bottom: TabBar(
              controller: _tabController,
              tabs: [
                Tab(
                    icon: Icon(
                  Icons.directions_car,
                  color: Colors.white,
                )),
                Tab(icon: Icon(Icons.directions_transit)),
              ],
            ),
          ),
          body: SafeArea(
            child: TabBarView(
              children: [
                Icon(
                  Icons.directions_car,
                  color: Colors.redAccent,
                ),
                Icon(Icons.directions_transit),
              ],
            ),
          ),
        ));
  }
}

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Which version of flutter you are using ? I copy pasted your code still I get same error. My version is 2.2.3
My version is 2.0.5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.