如何在颤振中在屏幕中央创建标签栏?

2024-01-10

我正在尝试使用 flutter 在屏幕中心创建一个选项卡栏,同时尝试在列中给出 TabBarView ,但我陷入了这个错误。请解决这个问题。

I/flutter ( 3983): ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
I/flutter ( 3983): The following assertion was thrown during performResize():
I/flutter ( 3983): Horizontal viewport was given unbounded height.
I/flutter ( 3983): Viewports expand in the cross axis to fill their container and constrain their children to match
I/flutter ( 3983): their extent in the cross axis. In this case, a horizontal viewport was given an unlimited amount of
I/flutter ( 3983): vertical space in which to expand.

源代码是

class profilePage extends StatefulWidget {
  @override
  profilePageState createState() => profilePageState();
}

class profilePageState extends State<profilePage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  @override
  void initState() {
    _tabController = new TabController(length: 2, vsync: this);
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: [
          Container(
            child: Column(crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                SizedBox(
                  height: 40,
                ),DefaultTabController(
                  length: 2,
                  child: Column(children: [TabBar(
                      unselectedLabelColor: Colors.black,
                      labelColor: Colors.red,
                      tabs: <Widget>[
                        Tab(
                          icon: Icon(Icons.people),
                        ),
                        Tab(
                          icon: Icon(Icons.person),
                        )
                      ],controller: _tabController,
                      indicatorSize: TabBarIndicatorSize.tab,
                    ),TabBarView(
                      children: <Widget>[Text('people'), Text('Person')],
                      controller: _tabController,
                    ),
                  ]),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

您可以看到我想要实现的图像的上述模型。我尝试了很多事情,但我一直停留在这里。

如何纠正此错误以及如何在屏幕中央创建标签栏?


我添加了您想要获得的演示(我按照您发布的图片进行操作):

NOTE:我必须对您排列小部件树的方式进行一些更改。

class profilePage extends StatefulWidget {
  @override
  profilePageState createState() => profilePageState();
}

class profilePageState extends State<profilePage> {
 
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: Text(
            'My Profile',
          ),
          centerTitle: true,
          backgroundColor: Colors.grey[700].withOpacity(0.4),
          elevation: 0,
          // give the app bar rounded corners
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.only(
              bottomLeft: Radius.circular(20.0),
              bottomRight: Radius.circular(20.0),
            ),
          ),
          leading: Icon(
            Icons.menu,
          ),
        ),
        body: Column(
          children: <Widget>[
            // construct the profile details widget here
            SizedBox(
              height: 180,
              child: Center(
                child: Text(
                  'Profile Details Goes here',
                ),
              ),
            ),

            // the tab bar with two items
            SizedBox(
              height: 50,
              child: AppBar(
                bottom: TabBar(
                  tabs: [
                    Tab(
                      icon: Icon(Icons.directions_bike),
                    ),
                    Tab(
                      icon: Icon(
                        Icons.directions_car,
                      ),
                    ),
                  ],
                ),
              ),
            ),

            // create widgets for each tab bar here
            Expanded(
              child: TabBarView(
                children: [
                  // first tab bar view widget
                  Container(
                     color: Colors.red,
                    child: Center(
                      child: Text(
                        'Bike',
                      ),
                    ),
                  ),

                  // second tab bar viiew widget
                  Container(
                     color: Colors.pink,
                    child: Center(
                      child: Text(
                        'Car',
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

OUTPUT:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在颤振中在屏幕中央创建标签栏? 的相关文章

随机推荐

  • Symfony5 使用 AJAX 表单多选(选择列表)数据自动更新

    我有一个位置表单 其中包含三个 选择 选择列表 国家 地区和部门 这些 选择 默认包含所有国家 地区和部门的列表 我想让我的用户首先选择一个国家或地区或部门 我想做的事 当用户选择一个国家时 区域中的数据会根据该国家 地区而变化 地区和部门
  • 类是原始类型。对泛型类型 Class 的引用应该参数化

    我有以下课程 来自简单的 Spring 教程 public class CarValidator implements Validator public boolean supports Class aClass return Car cl
  • 有没有办法在 Flask WTForms 中创建数据列表字段?

    有谁知道一种方法来创建datalist在 Flask 中使用 WTForms 字段 我知道如何创建一个SelectField但如果列表中没有 我需要允许用户输入自己的值 这就是我想做的http www w3schools com tags
  • 引用Java属性文件中的其他变量[重复]

    这个问题在这里已经有答案了 可能的重复 如何引用java util Properties中的另一个属性 https stackoverflow com questions 872272 how to reference another pr
  • 无法禁用日志消息

    我在摆脱 Spring 生成的调试消息时遇到了一些麻烦 类似于以下消息 有数千个这样的条目 19 58 08 380 main DEBUG o s b f s DefaultListableBeanFactory Creating shar
  • “为什么运行时异常是不可恢复的?”

    在Java文档中 我看到了定义 如果可以合理地预期客户端会从异常中恢复 则将其设为受检查的异常 如果客户端无法执行任何操作来从异常中恢复 请将其设为未经检查的异常 未经检查的异常 争议 https docs oracle com javas
  • 如何使用 ProcessBuilder 与 CLI 程序持续交互

    我经常使用通过 docker 容器访问的 CLI 程序 进入容器后 我就可以开始使用相关的 CLI 程序 我遇到的问题是我想继续与同一个命令行实例交互 基本上我正在尝试创建一个将在 CLI 程序 之上 运行的 GUI 程序 我只是不知道如何
  • 为 AWS 设置“Stackdriver Kubernetes 监控”

    Google Cloud Platform 在 Kubecon 2018 上宣布了 Stackdriver Kubernetes Monitoring 看起来棒极了 我是一名运行着几个 Kubernetes 集群的 AWS 用户 我立即羡慕
  • 使用HMS Toolkit添加HMS和GMS时找不到com.huawei.hms:hwid:5.3.0.301 &推送套件

    我正在尝试将 HMS 添加到我们的 GMS 第一个应用程序中 这是一个庞大的应用程序 因此我们决定尝试 HMS Toolkit 转换软件 该工具包添加了必要的依赖项和模块 并在需要时进行了适当的替换 但是当我尝试构建我们的应用程序时 我收到
  • 异常:类型错误:无法设置未定义的属性“消息”

    在升级旧的 Angular 2 项目的许多依赖项后 我在运行时收到以下错误 EXCEPTION TypeError Cannot set property message of undefined ErrorHandler handleEr
  • gSoap EWS“错误 500:内部服务器错误”

    我在使用 ews gSoap 时遇到一些问题 我有下一个代码 ExchangeServiceBindingProxy proxy new ExchangeServiceBindingProxy endpoint c str soap pSo
  • 如何使用 Spark 数据框评估 Spark Dstream 对象

    我正在编写一个 Spark 应用程序 我需要根据历史数据评估流数据 这些数据位于 SQL Server 数据库中 现在的想法是 spark 将从数据库中获取历史数据并将其保存在内存中 并根据它评估流数据 现在我得到的流数据为 import
  • 如何在R中动态插入带有模式的列?

    这是一个跟进问题 https stackoverflow com questions 73938635 rename a column based on the original columns name r 73938710 noredi
  • 有没有办法在浏览器中编译代码(C/C++)?

    这个问题可能听起来很疯狂 有没有基于浏览器的编译器 本地客户端 https developer chrome com native client是一个沙箱 用于在浏览器中高效运行已编译的 C 和 C 代码 你可以探索这个
  • ReactJS:来自 State 的动态复选框

    我有一个动态元素的集合 所以我事先不知道该集合的内容是什么 我想动态渲染这些复选框 并默认将它们全部选中 您应该能够取消选中这些框 这会在渲染中触发另一个地图功能 所以基本上这是我的过滤器 我在国家设置上苦苦挣扎 我正在考虑以下内容 我想通
  • “此应用程序正在从后台线程修改自动布局引擎”

    我遇到以下错误 此应用程序正在从后台线程修改自动布局引擎 这可能会导致引擎损坏和奇怪的崩溃 每当我尝试将图像视图加载到表视图中时 相关代码如下 override func tableView tableView UITableView ce
  • 在 Gnuplot 中自定义颜色范围

    我有一个运行良好的等值线图 它为不同的值生成等量的颜色 我想要的是在右侧生成标签 以便为每个块提供正确的颜色 当前结果 我想要的是每个块都有这个值 300 100 70 30 10 1 0 编辑 当我添加这段代码时 set cbtics 3
  • 在 C++ 中使用 new 分配大于 2GB 的单个对象(在 Windows 上)

    我使用的是 Windows x64 模式 在 Visual Studio 上使用 MSVC 编译 这new当我这样做时 运算符似乎没有按预期工作 char buf new char 1LLU lt lt 32 但是如果我传入一个变量而不是直
  • 如何在两个PHP文件之间传递变量?

    我在名为 one php 的文件中有以下代码 a href two php Click here for 1 a a href two php Click here for 2 a 现在 当我单击锚标记链接之一时 它会将我带到two php
  • 如何在颤振中在屏幕中央创建标签栏?

    我正在尝试使用 flutter 在屏幕中心创建一个选项卡栏 同时尝试在列中给出 TabBarView 但我陷入了这个错误 请解决这个问题 I flutter 3983 EXCEPTION CAUGHT BY RENDERING LIBRAR