flutter - 如何在小部件底部显示 TabBar

标签 flutter

  Widget build(BuildContext context) {
return Scaffold(
  body: SingleChildScrollView(
    child: Column(
      children: [
        Container(
          color:Colors.blueGrey.shade900,
          width: double.infinity,
          height: MediaQuery.of(context).size.height * 0.15,
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Row(
                   mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                Text("Available Balance     ₹ 10050", style: TextStyle(
                  color: Colors.white,
                  fontSize: 18,
                ),),
                ],),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Row(
                   mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                RaisedButton(onPressed: () {}, color: Colors.teal, child: Text("Recharge", style: TextStyle(
                  color: Colors.white
                ),),),
                RaisedButton(onPressed: () {}, color: Colors.teal, child: Text("Read Rule", style: TextStyle(
                  color: Colors.white
                ),),),
                Icon(Icons.refresh_rounded, color: Colors.white,)
                ],),
              ),
              SizedBox(
                height: 5,
              ),
              // I need to insert the tabBarHere
            ],
          ),
        ),
      ],
    ),
  ),
);

我已经从 flutter 创建了小部件,但我无法在该小部件之后显示 TabBar。我已经看到了使用 DefaultTabController() 创建选项卡的基本方法,但是当我们在应用程序栏的底部使用时它正在工作

enter image description here

最佳答案

您可以使用NestedScrollView:

Scaffold(
  body: SafeArea(
    child: DefaultTabController(
      length: 2,
      child: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxScrolled) {
          return <Widget>[
            SliverToBoxAdapter(
              child: Container(
                color: Colors.blueGrey.shade900,
                width: double.infinity,
                height: MediaQuery.of(context).size.height * 0.15,
                child: Column(
                  children: [
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          Text(
                            "Available Balance     ₹ 10050",
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 18,
                            ),
                          ),
                        ],
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceAround,
                        children: [
                          RaisedButton(
                            onPressed: () {},
                            color: Colors.teal,
                            child: Text(
                              "Recharge",
                              style: TextStyle(color: Colors.white),
                            ),
                          ),
                          RaisedButton(
                            onPressed: () {},
                            color: Colors.teal,
                            child: Text(
                              "Read Rule",
                              style: TextStyle(color: Colors.white),
                            ),
                          ),
                          Icon(
                            Icons.refresh,
                            color: Colors.white,
                          )
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 5,
                    ),
                  ],
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                color: Colors.blueGrey.shade900,
                child: TabBar(
                  tabs: <Widget>[
                    Padding(
                      padding: const EdgeInsets.symmetric(vertical: 10.0),
                      child: Icon(Icons.card_giftcard),
                    ),
                    Padding(
                      padding: const EdgeInsets.symmetric(vertical: 10.0),
                      child: Icon(Icons.store),
                    ),
                  ],
                ),
              ),
            ),
          ];
        },
        body: Column(
          children: <Widget>[
            Flexible(
              child: TabBarView(
                children: [
                  Center(child: Text('tab 1')),
                  Center(child: Text('tab 2')),
                ],
              ),
            ),
          ],
        ),
      ),
    ),
  )
)

结果:

res

关于flutter - 如何在小部件底部显示 TabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63604466/

相关文章:

Flutter - 如何制作具有固定高度的自定义圆形标签指示器?

firebase - Flutter Firebase Analytics 无数据

flutter - GetxControllers 是否会自动关闭 obs 流?

flutter - 可扩展的 AppBar (onPressed)

image - SVG 图片正在 flutter 中返回黑色图像,尽管从评估中给出了彩色图像

android - 在 Flutter 中按下后退按钮时关闭抽屉导航

flutter - 错误 : Cannot run with sound null safety, 因为以下依赖项(flutter_absolute_path)

animation - Flutter:Hero transition + widget animation 同时进行?

Flutter Bloc Design - 通知页面有关更改

forms - Flutter 应用程序默认在 Form 中的任何 TextField 的 Trim() 输入值