0
votes

I am Working with tab bars in Flutter. I have 3 Tabs inside the Bottom navigation bar and when ever the app starts the first tab will be selected by default. enter image description here

I want the app to open With the Center tab as the Default tab.

enter image description here

How Can I achieve that?

my Code

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

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

class _MyStatefulWidgetState extends State<MyStatefulWidget>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: 3);
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: TabBarView(
        controller: _tabController,
        physics: NeverScrollableScrollPhysics(),
        children: <Widget>[
          WallpaperLandingPage(),
          SetUpLandingPage(),
          SettingPage(),
        ],
      ),
      bottomNavigationBar: Container(
        height: 65.0,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.only(
              topRight: Radius.circular(30), topLeft: Radius.circular(30)),
          boxShadow: [
            BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),
          ],
        ),
        child: ClipRRect(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(30.0),
            topRight: Radius.circular(30.0),
          ),
          child: BottomAppBar(
            child: Container(
              child: TabBar(
                indicatorSize: TabBarIndicatorSize.label,
                isScrollable: false,
                indicator: BoxDecoration(
                  shape: BoxShape.circle,
                  color: Colors.green,
                ),
                tabs: <Widget>[
                  Container(
                    height: 45.0,
                    width: 45.0,
                    child: Icon(AntDesign.picture),
                  ),
                  Container(
                    height: 45.0,
                    width: 45.0,
                    child: Icon(AntDesign.home),
                  ),
                  Container(
                    height: 45.0,
                    width: 45.0,
                    child: Icon(Entypo.grid),
                  ),
                ],
                controller: _tabController,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

1

1 Answers

0
votes

try this:

_tabController = TabController(initialIndex: 1, vsync: this, length: 3);