如何在TabBar上创建阴影或高程?

问题描述 投票:0回答:3

enter image description here

我尝试了其他选项,但无法添加图像中的阴影:

TabBar(
        indicatorColor: Colors.transparent,
        indicatorSize: TabBarIndicatorSize.tab,
        unselectedLabelColor: inActiveColor,
        // Using BoxDecoration there is PADDING issue in Tabs 
         indicator: BoxDecoration(
           borderRadius: BorderRadius.circular(50),
           color: hexToColor(primaryColorDark),
           boxShadow: [
             BoxShadow(
               color: Colors.grey.withOpacity(0.5),
               spreadRadius: 10,
               blurRadius: 10,
               offset: Offset(0, 10), // changes position of shadow
             ),
           ],
         ),
        tabs: <Tab>[
          Tab(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Icon(
                  Icons.create,
                  size: 20,
                ),
                Text('   ' + 'Form'),
              ],
            ),
          ),
          Tab(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Icon(
                  Icons.remove_red_eye,
                  size: 20,
                ),
                Text('   ' + 'Preview'),
              ],
            ),
          ),
        ],
      ),
flutter flutter-layout shadow tabbar
3个回答
0
投票

您可以使用容器包装商品并进行设计,这可能是一个示例。它显然是一个hack。

         Tab(
              child: Container(
                width: 100,
                padding: EdgeInsets.all(5),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(50),
                  color: index == 0 ? Colors.red : null,
                  boxShadow: [
                    if (index == 0)
                      BoxShadow(
                        color: Colors.red.withOpacity(0.5),
                        spreadRadius: 2,
                        blurRadius: 10,
                      ),
                  ],
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Icon(Icons.create, size: 20),
                    SizedBox(width: 10),
                    Text('Form'),
                  ],
                ),
              ),
            ),

这里我正在根据所选索引更改背景色。


0
投票

尝试一下还不错

@override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: SafeArea(
        child: Scaffold(
            appBar: PreferredSize(
              preferredSize: Size(MediaQuery.of(context).size.width, 500),
              child: Container(
                color: Colors.white,
                padding: const EdgeInsets.all(16),
                child: Row(
                  children: <Widget>[
                    Icon(Icons.arrow_back_ios,size: 30,),
                    SizedBox(
                      width: 16,
                    ),
                    Expanded(
                      child: TabBar(
                        indicatorColor: Colors.transparent,
                        indicatorSize: TabBarIndicatorSize.tab,
                        unselectedLabelColor: Colors.grey[400],
                        // Using BoxDecoration there is PADDING issue in Tabs
                        indicator: BoxDecoration(
                          borderRadius: BorderRadius.circular(50),
                          color: Colors.blueAccent,
                          boxShadow: [
                            BoxShadow(
                              color: Colors.deepPurple
                                  .withOpacity(0.3)
                                  .withBlue(150),
                              blurRadius: 25,
                              offset:
                                  Offset(0, 20), // changes position of shadow
                            ),
                          ],
                        ),
                        tabs: <Tab>[
                          Tab(
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(
                                  Icons.create,
                                  size: 20,
                                ),
                                Text('   ' + 'Form'),
                              ],
                            ),
                          ),
                          Tab(
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: <Widget>[
                                Icon(
                                  Icons.remove_red_eye,
                                  size: 20,
                                ),
                                Text('   ' + 'Preview'),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            body: Container()),
      ),
    );
  }

enter image description here


0
投票

最佳和简便的解决方案,只需将TabBar与具有固定高度的容器包装在一起,例如:

enter image description here

         Container(
            height: 35,
            child: TabBar(
              indicatorColor: Colors.transparent,
              indicatorSize: TabBarIndicatorSize.tab,
              unselectedLabelColor: inActiveColor,

              indicator: BoxDecoration(
                borderRadius: BorderRadius.circular(50),
                color: Colors.blueAccent,
                boxShadow: [
                  BoxShadow(
                    color: Colors.blueAccent.withOpacity(0.3),
                    blurRadius: 25,
                    offset: Offset(0, 20), // changes position of shadow
                  ),
                ],
              ),
              tabs: <Tab>[
                Tab(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Icon(
                        Icons.create,
                        size: 20,
                      ),
                      Text('   ' + 'Form'),
                    ],
                  ),
                ),
                Tab(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Icon(
                        Icons.remove_red_eye,
                        size: 20,
                      ),
                      Text('   ' + 'Preview'),
                    ],
                  ),
                ),
              ],
            ),
          )
© www.soinside.com 2019 - 2024. All rights reserved.