No TabController for TabBar. code example

Example 1: No TabController for TabBarView.

import 'package:flutter/material.dart';void main() {  runApp(StartPage());}class StartPage extends StatelessWidget {  @override  Widget build(BuildContext context) {    return new MaterialApp(      title: "New Task",      debugShowCheckedModeBanner: false,      home: new HomePage(),    );  }}class HomePage extends StatefulWidget {  @override  _HomePageState createState() => _HomePageState();}class _HomePageState extends State with SingleTickerProviderStateMixin{  TabController _tabController;  @override  void initState() {    _tabController = new TabController(length: 3, vsync: this);    super.initState();  }  @override  Widget build(BuildContext context) {    return new Scaffold(      appBar: new AppBar(        title: new Text("GrubX"),        bottom: TabBar(          unselectedLabelColor: Colors.white,          labelColor: Colors.amber,          tabs: [          new Tab(icon: new Icon(Icons.call)),          new Tab(            icon: new Icon(Icons.chat),          ),          new Tab(            icon: new Icon(Icons.notifications),          )        ],        controller: _tabController,        indicatorColor: Colors.white,        indicatorSize: TabBarIndicatorSize.tab,),        bottomOpacity: 1,      ),      body: TabBarView(          children: [        new Text("This is call Tab View"),        new Text("This is chat Tab View"),        new Text("This is notification Tab View"),      ],      controller: _tabController,),    );  }}

Example 2: No TabController for TabBar.

As The Error is Stating you need - TabController Edit Your Code as Below.

@override
  Widget build(BuildContext context) {
    // TODO: implement build
    return DefaultTabController(  // Added
      length: 4,  // Added
      initialIndex: 0, //Added
      child: Scaffold(
          appBar: AppBar(
            title: new Text("Tab App."),
          ),
          drawer: sideDrawer(context),  // Passed BuildContext in function.
          bottomNavigationBar: bottomTabBar()),
    );
  }

Widget sideDrawer(BuildContext context){ ......

Example 3: No TabController for TabBarView.

body: TabBarView(    children: [  new Text("This is call Tab View"),  new Text("This is chat Tab View"),  new Text("This is notification Tab View"),],controller: _tabController,),

Tags: