Как создать тень или возвышение на TabBar? - PullRequest
0 голосов
/ 26 мая 2020

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'),
              ],
            ),
          ),
        ],
      ),

Ответы [ 3 ]

1 голос
/ 31 мая 2020

Лучшее и простое решение, просто оберните 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'),
                    ],
                  ),
                ),
              ],
            ),
          )
0 голосов
/ 31 мая 2020

попробуйте неплохо

@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 голосов
/ 28 мая 2020

Вы можете обернуть свой предмет Контейнером и спроектировать его, вот пример. Очевидно, это взлом.

         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'),
                  ],
                ),
              ),
            ),

Здесь я меняю цвет фона в зависимости от выбранного индекса.

...