【问题标题】:custom tabbar tabs in flutter颤动中的自定义标签栏标签
【发布时间】:2021-05-11 08:47:17
【问题描述】:

我正在做一个项目,我需要这样的标签栏标签。我尝试过使用标签->图标、文本,但它更小

我想要的东西:

我当前的代码:

  List<Tab> getTabs(int count, AsyncSnapshot snapshot) {
_tabs.clear();
for (int i = 0; i < count; i++) {
  categoriesmodel categ = snapshot.data[i];
  _tabs.add(
    getTab(
      categ.categories_name.toString(),
          categ.icon_of_category.toString(),
    ),
  );
}
return _tabs;
}


Tab getTab(String tabtitle, String imagepath) {
return Tab(
  icon: Image.network(
    imagepath,
    height: 40,
    width: 40,
  ),
  child: Text(
    tabtitle,
    style: TextStyle(color: Colors.black),
  ),
);}

应用栏内

bottom: PreferredSize(
            preferredSize: Size(120, 120),
            child: Container(
              height: 120,
              color: Colors.white,
              child: TabBar(
                isScrollable: true,
                indicatorColor: mainaccent,
                tabs: _tabs,
                controller: _tabController,
              ),
            ),
          ),

我的代码结果

【问题讨论】:

    标签: flutter dart flutter-layout tabbar


    【解决方案1】:

    这个例子可以帮助你:

     DefaultTabController(
          length: 3,
          child: Scaffold(
           appBar: AppBar(
             backgroundColor: Colors.white,
              title: Text('Flutter is Awesome' , style: TextStyle(color: Colors.black),),
              centerTitle: true,
              bottom: TabBar(
                tabs: [
                CircleAvatar(backgroundImage: AssetImage('assets/image1.png')),
                CircleAvatar(backgroundImage: AssetImage('assets/image2.png')),
                CircleAvatar(backgroundImage:  AssetImage('assets/image3.png')),
                ],
              ),
            ),
            body: TabBarView(children: [
              Center(child: Text('First Tab')),
              Center(child: Text('Second Tab')),
              Center(child: Text('Third Tab'))
            ])
          ),
        );
    

    输出:

    理想情况下,不要忘记用DefaultTabController 包裹你的脚手架。
    您也可以直接使用 TabBar 代替 AppBar,如下所示:appBar : TabBar()。但请确保您有SafeArea

    【讨论】:

    • 尝试用 DefaultTabController 包装它,但标签栏标签的高度并没有改变。我不知道这里的钻头是什么,也许标签高度是固定的
    • 使用 toolbarHeight 属性设置工具栏高度。示例:toolbarHeight:70。我认为它可以帮助你。
    • 也试过了,但它只改变了应用栏的高度,而不是它的标签栏
    • 在 TabBar 中使用这些属性。 indicatorSize: TabBarIndicatorSize.label 和 isScrollable: true,
    猜你喜欢
    • 2022-01-23
    • 2020-08-09
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    相关资源
    最近更新 更多