【问题标题】:How can I create a curved bottomBar in Flutter?如何在 Flutter 中创建弯曲的底栏?
【发布时间】:2019-12-20 05:05:21
【问题描述】:

我想要一个像这样的弯曲底栏,后面有阴影:

我尝试创建类似的东西,但是当我将 bottomBar 放在 Scaffold 上时,当我向下滚动时它会切割身体。如果我尝试将 Scaffold 主体部分的边缘变圆,那么我将没有 Shadow。有谁知道这是怎么做到的吗 ?提前致谢

【问题讨论】:

  • 请尝试使用屏幕截图和代码来解释您期望得到什么以及已经得到什么,以便有人可以帮助您。

标签: flutter flutter-layout


【解决方案1】:

将其放入堆栈中。不要直接将底部导航栏添加到脚手架。

尝试你自己的方式给你 eg.

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Some Text'),
      ),
      body: Stack(
        children: <Widget>[
          bodyContent,
          Positioned(
            left: 0,
            right: 0,
            bottom: 0,
            child: bottomNavigationBar,
          ),
        ],
      ),
    );
  }

  Widget get bodyContent {
    return Container(color: Colors.red);
  }

  Widget get bottomNavigationBar {
    return ClipRRect(
      borderRadius: BorderRadius.only(
        topRight: Radius.circular(40),
        topLeft: Radius.circular(40),
      ),
      child: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('1')),
          BottomNavigationBarItem(icon: Icon(Icons.usb), title: Text('2')),
          BottomNavigationBarItem(
              icon: Icon(Icons.assignment_ind), title: Text('3')),
          BottomNavigationBarItem(
              icon: Icon(Icons.multiline_chart), title: Text('4')),
        ],
        unselectedItemColor: Colors.grey,
        selectedItemColor: Colors.black,
        showUnselectedLabels: true,
      ),
    );
  }
}

【讨论】:

  • 感谢您的回复,但我想要的是一个底部栏弯曲到另一边,如图所示
  • 我理解,但我认为您应该尝试自己的方式/逻辑并使用我的代码
猜你喜欢
  • 2021-11-29
  • 2021-12-07
  • 2017-10-31
  • 1970-01-01
  • 1970-01-01
  • 2016-09-26
  • 2021-05-14
  • 2020-02-15
  • 1970-01-01
相关资源
最近更新 更多