【问题标题】:Flutter, how to set TabBar height?Flutter,如何设置 TabBar 高度?
【发布时间】:2021-07-11 13:05:37
【问题描述】:

注意:我在 stackoverflow 上尝试过其他答案,但没有奏效。

我有一个 TabBar,想设置它的高度。

这是我的代码:

Widget getTabBar() {
    return TabBar(
      labelColor: LightTheme.TabIconColor,
      indicatorColor: LightTheme.TabIconColor,
      indicatorSize: TabBarIndicatorSize.tab,
      tabs: [
        Tab(
            text: "Collect",
            icon: Icon(
              Icons.add_location,
              size: 40,
            )),
        Tab(
            text: "Deliver",
            icon: Icon(
              Icons.tour,
              size: 40,
            )),
      ],
    );
  }

这是我的应用程序的屏幕截图。如您所见,标题被剪掉了(短语“底部溢出 22 像素”):

这是屏幕的其余代码:

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('Test'),
        backgroundColor: LightTheme.AppBarColor,
      ),
      body: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.white,
            automaticallyImplyLeading: false,
            flexibleSpace: getTabBar(),
          ),
          body: getTabBarView(),
        ),
      ),
      drawer: getDrawer(),
      // Disable opening the drawer with a swipe gesture.
      drawerEnableOpenDragGesture: false,
    );
  }

更新:我在控制台中收到以下消息。我尝试设置 BoxConstraint 但问题依然存在:

The specific RenderFlex in question is: RenderFlex#fe401 relayoutBoundary=up25 OVERFLOWING
...  parentData: offset=Offset(0.0, 0.0) (can use size)
...  constraints: BoxConstraints(0.0<=w<=173.7, 0.0<=h<=54.0)
...  size: Size(40.0, 54.0)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down

【问题讨论】:

    标签: flutter tabbar


    【解决方案1】:

    尝试将 Tab 包裹在 Container 中并设置容器的高度。这是一个例子:

       Container(
          height: 100,
          child: Tab(
            child: Column(
              children: [
                Icon(
                  Icons.add_location,
                  size: 40,
                ),
                Text("Tab A"),
              ],
            ),
          ),
        ),
    

    结果:

    【讨论】:

    • 它没有用。我什至像你一样在标签中添加了一列,但仍然遇到同样的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 2019-09-09
    • 2018-12-07
    • 2021-08-20
    • 2022-12-04
    相关资源
    最近更新 更多