【问题标题】:Is there a way to curve the tabbar indicator down in the corners?有没有办法让标签栏指示器在角落里向下弯曲?
【发布时间】:2020-12-13 03:15:02
【问题描述】:

我在脚手架中的容器上放置了一个边界半径。我现在想要的是 TabBar 指示器与容器一起向下弯曲,而不是一条导致指示器漂浮在背景之上的直线。图片将显示我的意思。

我尝试过使用 TabBar 的指示器属性,但没有任何成功。

Picture of the app as example

Picture of result that I'm looking for (Photoshop)

包装器.dart

 Widget build(BuildContext context) => StoreConnector<AppState, Store<AppState>>(
  converter: (Store<AppState> store) => store,
  builder: (BuildContext context, Store<AppState> store) => Container(
      decoration: widget.decoration,
      child: Scaffold(
        drawer: widget.drawer ? _menuDrawer(context, store) : null,
        backgroundColor: Colors.transparent,
        appBar: PreferredSize(
            preferredSize: Size.fromHeight(widget.tabBar != null ? 110.0 : 60.0),
            child: Container(
                alignment: Alignment.center,
                child: AppBar(
                  actions: widget.actions,
                  backgroundColor: Colors.transparent,
                  iconTheme: IconThemeData(color: Colors.white),
                  title: widget.teamIsPremium != null
                      ? Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: <Widget>[
                            Icon(widget.teamIsPremium ? MdiIcons.star : MdiIcons.starOff),
                            Container(
                              width: 5,
                            ),
                            Text(widget.title),
                          ],
                        )
                      : Text(widget.title),
                  centerTitle: true,
                  elevation: 0,
                  bottom: widget.tabBar,
                ))),
        bottomNavigationBar: widget.selectedMenuItem == WrapperMenuItem.NONE
            ? null
            : Theme(
                data: Theme.of(context).copyWith(textTheme: Theme.of(context).textTheme),
                child: BottomNavigationBar(
                    selectedItemColor: Color(0xff2e2e2e),
                    unselectedItemColor: Color(0xff757575),
                    currentIndex: _getIdFromEnum(widget.selectedMenuItem),
                    onTap: (i) => {
                          if (i != _getIdFromEnum(widget.selectedMenuItem))
                            {widget.selectedMenuItem = _getWrapperMenuItemFromId(i), _moveToPage(context, i)}
                        },
                    showSelectedLabels: true,
                    items: [
                      BottomNavigationBarItem(icon: Icon(MdiIcons.home), title: Text('Start')),
                      BottomNavigationBarItem(icon: Icon(MdiIcons.trafficCone), title: Text('Trainingen')),
                      BottomNavigationBarItem(icon: Icon(MdiIcons.trophy), title: Text('Wedstrijden')),
                      BottomNavigationBarItem(icon: Icon(MdiIcons.accountGroup), title: Text('Spelers'))
                    ]),
              ),
        body: Container(
          margin: widget.small
              ? EdgeInsets.only(left: 5, right: 5, top: 5)
              : widget.tabBar != null ? EdgeInsets.only(top: 0) : EdgeInsets.only(top: 0),
          decoration: BoxDecoration(
              color: widget.transparent ? Colors.transparent : Color.fromRGBO(240, 240, 240, 1),
              borderRadius: BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15))),
          constraints: BoxConstraints.expand(),
          alignment: Alignment(-1, -1),
          child: ClipRRect(
            child: widget.child,
            borderRadius: BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
          ),
        ),
        floatingActionButton: widget.floatingActionButton,
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
      )));

match.dart

    return DefaultTabController(
        length: 2,
        child: Wrapper(
          title: 'Wedstrijden',
          drawer: true,
          selectedMenuItem: WrapperMenuItem.MATCH,
          tabBar: TabBar(
            tabs: [
              Tab(text: 'Overzicht'),
              Tab(text: 'Statistieken'),
            ],
          ),
          child: TabBarView(
            children: [
              MatchOverviewTab(),
              MatchStatsTab(),
            ],
          ),
        ),
      );

【问题讨论】:

  • 可能提供一些愚蠢的东西,但也许它会有所帮助)您知道哪个屏幕将显示 MatchOverviewTab() 或 MatchStatsTab(),因此您实际上可以尝试在它们上绘制橙色曲线 [左边一个,右边一个]

标签: flutter flutter-layout


【解决方案1】:

这是你可以尝试的,记住一切都是颤振中的小部件,所以首先,在你的脚手架内创建 Stack ,放置你的 TabBar() 和 Container() 使用 Positioned 或任何其他方法使它们重叠到所需的程度,那么您应该将 Custom Indicator (在您的情况下这将是一个带有圆边的容器)添加到 TabBar()


为了更清楚,这是一张图片。

当然,有几种可能的方法可以做到这一点,但这是我能想到的,你也会看到相同的指示动画。 想知道它是否有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-29
    • 2014-07-19
    • 1970-01-01
    • 1970-01-01
    • 2019-08-12
    • 2018-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多