Flutter 我的颤振应用程序的Tabbar视图不工作

Flutter 我的颤振应用程序的Tabbar视图不工作,flutter,flutter-layout,flutter-animation,flutter-web,visual-web-developer,Flutter,Flutter Layout,Flutter Animation,Flutter Web,Visual Web Developer,这是我的密码。更改选项卡栏视图内容不会更改内容 我已经尝试将tabbar视图的子视图更改为文本,但仍然没有效果 import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp(

这是我的密码。更改选项卡栏视图内容不会更改内容

我已经尝试将tabbar视图的子视图更改为文本,但仍然没有效果

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        backgroundColor: Colors.white,
        body: SafeArea(
          child: Column(
            children: <Widget>[
              Container(
                height: 60,
                width: 500,
                color: Colors.teal,
                margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
                child: Text(
                  'Choose Your Topic',
                  textAlign: TextAlign.left,
                  style: TextStyle(
                    fontFamily: 'BalooBhaina2-Regular',
                    fontWeight: FontWeight.normal,
                    fontSize: 35,
                    letterSpacing: 0.5,
                    wordSpacing: 2.0,
                    shadows: [
                      Shadow(
                        blurRadius: 50.0,
                        color: Colors.black,
                        offset: Offset(5.0, 5.0),
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                height: 50,
                width: 800,
                margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
                child: DefaultTabController(
                  length: 4,
                  child: Scaffold(
                    appBar: AppBar(
                      bottom: TabBar(tabs: [
                        Tab(icon: Icon(Icons.touch_app)),
                        Tab(icon: Icon(Icons.directions_bike)),
                        Tab(icon: Icon(Icons.movie)),
                        Tab(icon: Icon(Icons.music_video)),
                      ]),
                    ),
                    body: TabBarView(
                      children: [
                        Icon(Icons.touch_app),
                        Icon(Icons.directions_bike),
                        Icon(Icons.movie),
                        Icon(Icons.music_video),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“材料应用程序”,
家:脚手架(
背景颜色:Colors.white,
正文:安全区(
子:列(
儿童:[
容器(
身高:60,
宽度:500,
颜色:Colors.teal,
边距:从LTRB(0,0,0,0)开始的边距集,
填充:从LTRB(10,0,0,0)开始的边缘设置,
子:文本(
“选择你的主题”,
textAlign:textAlign.left,
样式:TextStyle(
fontFamily:“BalooBhaina2常规”,
fontWeight:fontWeight.normal,
尺码:35,
字母间距:0.5,
字间距:2.0,
阴影:[
影子(
半径:50.0,
颜色:颜色,黑色,
偏移量:偏移量(5.0,5.0),
),
],
),
),
),
容器(
身高:50,
宽度:800,
边距:从LTRB(0,0,0,5)开始的边距集,
子级:DefaultTabController(
长度:4,
孩子:脚手架(
appBar:appBar(
底部:选项卡栏(选项卡:[
选项卡(图标:图标(Icons.touch_app)),
选项卡(图标:图标(图标方向)),
选项卡(图标:图标(Icons.movie)),
选项卡(图标:图标(图标、音乐和视频)),
]),
),
正文:选项卡视图(
儿童:[
图标(图标。触摸应用程序),
图标(图标、方向和自行车),
图标(图标。电影),
图标(图标、音乐和视频),
],
),
),
),
),
],
),
),
),
);
}
}

您可以复制粘贴运行下面的完整代码
步骤1:您不需要
Scaffold
Appbar

步骤2:您可以使用
容器包装
选项卡栏
选项卡栏视图

代码片段

Container(
    color: Colors.blue,
    height: 50,
    width: 800,
    margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
    child: TabBar(controller: _tabController, tabs: [
      Tab(icon: Icon(Icons.touch_app)),
      Tab(icon: Icon(Icons.directions_bike)),
      Tab(icon: Icon(Icons.movie)),
      Tab(icon: Icon(Icons.music_video)),
    ]),
  ),
  Expanded(
    child: Container(
      //height: 50,
      //width: 800,
      margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
      child: TabBarView(
        controller: _tabController,
        children: [
          Icon(Icons.touch_app),
工作演示

完整代码

import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
  TabController _tabController;

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        backgroundColor: Colors.white,
        body: SafeArea(
          child: Column(
            children: <Widget>[
              Container(
                height: 60,
                width: 500,
                color: Colors.teal,
                margin: EdgeInsets.fromLTRB(0, 0, 0, 0),
                padding: EdgeInsets.fromLTRB(10, 0, 0, 0),
                child: Text(
                  'Choose Your Topic',
                  textAlign: TextAlign.left,
                  style: TextStyle(
                    fontFamily: 'BalooBhaina2-Regular',
                    fontWeight: FontWeight.normal,
                    fontSize: 35,
                    letterSpacing: 0.5,
                    wordSpacing: 2.0,
                    shadows: [
                      Shadow(
                        blurRadius: 50.0,
                        color: Colors.black,
                        offset: Offset(5.0, 5.0),
                      ),
                    ],
                  ),
                ),
              ),
              Container(
                color: Colors.blue,
                height: 50,
                width: 800,
                margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
                child: TabBar(controller: _tabController, tabs: [
                  Tab(icon: Icon(Icons.touch_app)),
                  Tab(icon: Icon(Icons.directions_bike)),
                  Tab(icon: Icon(Icons.movie)),
                  Tab(icon: Icon(Icons.music_video)),
                ]),
              ),
              Expanded(
                child: Container(
                  //height: 50,
                  //width: 800,
                  margin: EdgeInsets.fromLTRB(0, 0, 0, 5),
                  child: TabBarView(
                    controller: _tabController,
                    children: [
                      Icon(Icons.touch_app),
                      Icon(Icons.directions_bike),
                      Icon(Icons.movie),
                      Icon(Icons.music_video),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类_MyAppState使用SingleTickerProviderStateMixin扩展状态{
TabController\u TabController;
@凌驾
void initState(){
super.initState();
_tabController=tabController(vsync:this,长度:4);
}
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“材料应用程序”,
家:脚手架(
背景颜色:Colors.white,
正文:安全区(
子:列(
儿童:[
容器(
身高:60,
宽度:500,
颜色:Colors.teal,
边距:从LTRB(0,0,0,0)开始的边距集,
填充:从LTRB(10,0,0,0)开始的边缘设置,
子:文本(
“选择你的主题”,
textAlign:textAlign.left,
样式:TextStyle(
fontFamily:“BalooBhaina2常规”,
fontWeight:fontWeight.normal,
尺码:35,
字母间距:0.5,
字间距:2.0,
阴影:[
影子(
半径:50.0,
颜色:颜色,黑色,
偏移量:偏移量(5.0,5.0),
),
],
),
),
),
容器(
颜色:颜色,蓝色,
身高:50,
宽度:800,
边距:从LTRB(0,0,0,5)开始的边距集,
子项:选项卡栏(控制器:\选项卡控制器,选项卡:[
选项卡(图标:图标(Icons.touch_app)),
选项卡(图标:图标(图标方向)),
选项卡(图标:图标(Icons.movie)),
选项卡(图标:图标(图标、音乐和视频)),
]),
),
扩大(
子:容器(
//身高:50,
//宽度:800,
边距:从LTRB(0,0,0,5)开始的边距集,
子项:选项卡视图(
控制器:\ tab控制器,
儿童:[
图标(图标。触摸应用程序),
图标(图标、方向和自行车),
图标(图标。电影),
图标(图标、音乐和视频),
],
),
),
),
],
),
),
),
);
}
}

嗯,你征求了意见。请不要把所有的文字都加粗,而且大部分的代码检查都没有,这样你的问题就会变得杂乱无章。