Flutter 没有用于TabBarView颤振的TabController

Flutter 没有用于TabBarView颤振的TabController,flutter,dart,Flutter,Dart,我正在尝试使用以下代码添加TabBar: TabBarView( children: [ Icon(Icons.directions_car), Icon(Icons.directions_transit), Icon(Icons.directions_bike),

我正在尝试使用以下代码添加
TabBar

TabBarView(
                        children: [
                          Icon(Icons.directions_car),
                          Icon(Icons.directions_transit),
                          Icon(Icons.directions_bike),
                        ],
                      ),
但我发现了以下错误:

No TabController for TabBarView.
这就是全部代码:

import '../providers/properties.dart';
import '../providers/cities.dart';
import '../providers/property.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../widgets/properties_grid.dart';
import '../app_theme.dart';

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

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

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  int currentTab = 0;
  final PageStorageBucket bucket = PageStorageBucket();
  var _showOnlyFavorites = false;
  // List<HomeList> homeList = HomeList.homeList;
  AnimationController animationController;
  bool multiple = true;

  @override
  void initState() {
    animationController = AnimationController(
        duration: const Duration(milliseconds: 2000), vsync: this);
    super.initState();
  }

  Future<bool> getData() async {
    await Future<dynamic>.delayed(const Duration(milliseconds: 0));
    return true;
  }

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

  @override
  Widget build(BuildContext context) {
    // final properties = Provider.of<Properties>(context, listen: false);
    return Scaffold(
      extendBody: true,
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {},
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        elevation: 0,
        shape: CircularNotchedRectangle(),
        notchMargin: 10,
        child: Container(
          height: 60,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  MaterialButton(
                    padding: EdgeInsets.all(0),
                    minWidth: 155,
                    onPressed: () {
                      setState(() {
                        // currentScreen =
                        //     Chat(); // if user taps on this dashboard tab will be active
                        currentTab = 1;
                      });
                    },
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Icon(
                          Icons.home,
                          color: currentTab == 1 ? Colors.blue : Colors.grey,
                        ),
                        Text(
                          'Home',
                          style: TextStyle(
                            color: currentTab == 1 ? Colors.blue : Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  )
                ],
              ),

              // Right Tab bar icons

              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  MaterialButton(
                    padding: EdgeInsets.all(0),
                    minWidth: 60,
                    onPressed: () {
                      setState(() {
                        // currentScreen =
                        //     Settings(); // if user taps on this dashboard tab will be active
                        currentTab = 3;
                      });
                    },
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Icon(
                          Icons.view_list,
                          color: currentTab == 3 ? Colors.blue : Colors.grey,
                        ),
                        Text(
                          'Property List',
                          style: TextStyle(
                            color: currentTab == 3 ? Colors.blue : Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  ),
                  MaterialButton(
                    padding: EdgeInsets.all(0),
                    minWidth: 77,
                    onPressed: () {
                      setState(() {
                        // currentScreen =
                        //     Settings(); // if user taps on this dashboard tab will be active
                        currentTab = 4;
                      });
                    },
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Icon(
                          Icons.location_searching,
                          color: currentTab == 4 ? Colors.blue : Colors.grey,
                        ),
                        Text(
                          'Map',
                          style: TextStyle(
                            color: currentTab == 4 ? Colors.blue : Colors.grey,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              )
            ],
          ),
        ),
      ),
      backgroundColor: AppTheme.white,
      body: Stack(
        children: <Widget>[
          FutureBuilder<bool>(
            future: getData(),
            builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
              if (!snapshot.hasData) {
                return const SizedBox();
              } else {
                return Padding(
                  padding:
                      EdgeInsets.only(top: MediaQuery.of(context).padding.top),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      appBar(),
                      TabBarView(
                        children: [
                          Icon(Icons.directions_car),
                          Icon(Icons.directions_transit),
                          Icon(Icons.directions_bike),
                        ],
                      ),
                      Expanded(
                        child: FutureBuilder<bool>(
                          future: getData(),
                          builder: (BuildContext context,
                              AsyncSnapshot<bool> snapshot) {
                            if (!snapshot.hasData) {
                              return const SizedBox();
                            } else {
                              return ChangeNotifierProvider(
                                create: (context) => Properties(),
                                child: PropertiesGrid(_showOnlyFavorites),
                              );
                            }
                          },
                        ),
                      ),
                    ],
                  ),
                );
              }
            },
          ),
        ],
      ),
    );
  }

  Widget appBar() {
    return SizedBox(
      height: AppBar().preferredSize.height,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(top: 8, left: 8),
            child: Container(
              width: AppBar().preferredSize.height - 8,
              height: AppBar().preferredSize.height - 8,
            ),
          ),
          Expanded(
            child: Center(
              child: Padding(
                padding: const EdgeInsets.only(top: 4),
                child:
                    Image.asset('assets/images/logo.png', fit: BoxFit.contain),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 8, right: 8),
            child: Container(
              width: AppBar().preferredSize.height - 8,
              height: AppBar().preferredSize.height - 8,
              color: Colors.white,
              child: Material(
                color: Colors.transparent,
                child: InkWell(
                  borderRadius:
                      BorderRadius.circular(AppBar().preferredSize.height),
                  child: Icon(
                    Icons.location_on,
                    color: AppTheme.dark_grey,
                  ),
                  onTap: () {
                    setState(() {
                      multiple = !multiple;
                    });
                  },
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
import'../providers/properties.dart';
导入“../providers/cities.dart”;
导入“../providers/property.dart”;
进口“包装:颤振/材料.省道”;
导入“包:provider/provider.dart”;
导入“../widgets/properties_grid.dart”;
导入“../app_theme.dart”;
类MyHomePage扩展StatefulWidget{
constmyhomepage({Key}):超级(Key:Key);
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState使用TickerProviderStateMixin扩展状态{
int currentTab=0;
final PageStorageBucket bucket=PageStorageBucket();
var_showOnlyFavorites=false;
//List homeList=homeList.homeList;
动画控制器;
布尔倍数=真;
@凌驾
void initState(){
animationController=animationController(
持续时间:常量持续时间(毫秒:2000),vsync:this;
super.initState();
}
Future getData()异步{
等待未来。延迟(常量持续时间(毫秒:0));
返回true;
}
@凌驾
无效处置(){
animationController.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
//final properties=Provider.of(上下文,listen:false);
返回脚手架(
扩展体:是的,
浮动操作按钮:浮动操作按钮(
子:图标(Icons.add),
按下:(){},
),
floatingActionButtonLocation:floatingActionButtonLocation.centerDocked,
bottomNavigationBar:BottomAppBar(
海拔:0,
形状:CircularNotchedRectangle(),
notchMargin:10,
子:容器(
身高:60,
孩子:排(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
划船(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
材料按钮(
填充:边缘集。全部(0),
最小宽度:155,
已按下:(){
设置状态(){
//电流屏=
//Chat();//如果用户点击此仪表板选项卡,则该选项卡将处于活动状态
currentTab=1;
});
},
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
图标(
我的家,
颜色:currentTab==1?颜色。蓝色:颜色。灰色,
),
正文(
“家”,
样式:TextStyle(
颜色:currentTab==1?颜色。蓝色:颜色。灰色,
),
),
],
),
)
],
),
//右选项卡栏图标
划船(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
材料按钮(
填充:边缘集。全部(0),
最小宽度:60,
已按下:(){
设置状态(){
//电流屏=
//Settings();//如果用户点击此仪表板选项卡,则该选项卡将处于活动状态
currentTab=3;
});
},
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
图标(
Icons.view_列表,
颜色:currentTab==3?颜色。蓝色:颜色。灰色,
),
正文(
“财产清单”,
样式:TextStyle(
颜色:currentTab==3?颜色。蓝色:颜色。灰色,
),
),
],
),
),
材料按钮(
填充:边缘集。全部(0),
最小宽度:77,
已按下:(){
设置状态(){
//电流屏=
//Settings();//如果用户点击此仪表板选项卡,则该选项卡将处于活动状态
currentTab=4;
});
},
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
图标(
Icons.location\u搜索,
颜色:currentTab==4?颜色。蓝色:颜色。灰色,
),
正文(
“地图”,
样式:TextStyle(
颜色:currentTab==4?颜色。蓝色:颜色。灰色,
),
),
],
),
),
],
)
],
),
),
),
背景颜色:AppTheme.white,
主体:堆栈(
儿童:[
未来建设者(
future:getData(),
生成器:(BuildContext上下文,异步快照){
如果(!snapshot.hasData){
返回常量SizedBox();
}否则{
返回填充(
衬垫:
仅限EdgeInsets.only(顶部:MediaQuery.of(context.padding.top)),
子:列(
mainAxisAlignment:mainAxisAlignment.center,
横轴人
import 'package:flutter/material.dart';

void main() {
  runApp(TabBarDemo());
}

class TabBarDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(icon: Icon(Icons.directions_car)),
                Tab(icon: Icon(Icons.directions_transit)),
                Tab(icon: Icon(Icons.directions_bike)),
              ],
            ),
            title: Text('Tabs Demo'),
          ),
          body: TabBarView(
            children: [
              Icon(Icons.directions_car),
              Icon(Icons.directions_transit),
              Icon(Icons.directions_bike),
            ],
          ),
        ),
      ),
    );
  }
}
class MyTabbedPage extends StatefulWidget {
  const MyTabbedPage({ Key key }) : super(key: key);
  @override
  _MyTabbedPageState createState() => _MyTabbedPageState();
}

class _MyTabbedPageState extends State<MyTabbedPage> with SingleTickerProviderStateMixin {
  final List<Tab> myTabs = <Tab>[
    Tab(text: 'LEFT'),
    Tab(text: 'RIGHT'),
  ];

  TabController _tabController;

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

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        bottom: TabBar(
          controller: _tabController,
          tabs: myTabs,
        ),
      ),
      body: TabBarView(
        controller: _tabController,
        children: myTabs.map((Tab tab) {
          final String label = tab.text.toLowerCase();
          return Center(
            child: Text(
              'This is the $label tab',
              style: const TextStyle(fontSize: 36),
            ),
          );
        }).toList(),
      ),
    );
  }
}