dart 底部导航栏圆角

sirbozc5  于 12个月前  发布在  其他
关注(0)|答案(7)|浏览(126)

我想给我的底部导航栏给予一些圆角,为此,我必须使其容器的背景透明,但我不知道如何。
这就是我在Scaffold中所做的:

bottomNavigationBar: ClipRRect(
        borderRadius: BorderRadius.only(topLeft: Radius.circular(30.0), topRight: Radius.circular(30.0), ),
        child:BottomNavigationBar(
          //elevation: 0.0,
          type: BottomNavigationBarType.fixed,
          backgroundColor: Colors.white10,

字符串
结果是:


的数据
默认情况下仍然有一个白色背景。我试图将我的ClipRRect Package 在一个透明背景的容器中,但没有成功。
你知道吗?

mwngjboj

mwngjboj1#

需要一点阴影,

bottomNavigationBar: Container(                                             
  decoration: BoxDecoration(                                                   
    borderRadius: BorderRadius.only(                                           
      topRight: Radius.circular(30), topLeft: Radius.circular(30)),            
    boxShadow: [                                                               
      BoxShadow(color: Colors.black38, spreadRadius: 0, blurRadius: 10),       
    ],                                                                         
  ),                                                                           
  child: ClipRRect(                                                            
    borderRadius: BorderRadius.only(                                           
    topLeft: Radius.circular(30.0),                                            
    topRight: Radius.circular(30.0),                                           
    ),                                                                         
    child: BottomNavigationBar(                                                
      items: <BottomNavigationBarItem>[                                        
        BottomNavigationBarItem(                                               
          icon: Icon(Icons.favorite), title: Text('Favourite')),               
        BottomNavigationBarItem(                                               
          icon: Icon(Icons.favorite), title: Text('Favourite'))                
      ],                                                                       
    ),                                                                         
  )                                                                            
)

字符串
没有影子:


的数据
影子:


mo49yndu

mo49yndu2#

在Scaffold中,将extendBody属性设置为true。这将使body扩展到Scaffold的底部,而不是仅扩展到bottomNavigationBar的顶部。这应该可以解决您的问题。
范例:

Widget build(BuildContext context) {
    return Scaffold(
      body: bodyOfApp(),
      extendBody: true,
      backgroundColor: Colors.transparent,
      bottomNavigationBar: BottomNavBar(),
    );
   }

字符串

vlju58qv

vlju58qv3#

上述所有答案都以某种方式使用ClipRRect,这是非常昂贵的计算方式。因此,作为替代使用Material Widget,以下是如何:

bottomNavigationBar: Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
            topRight: Radius.circular(30), topLeft: Radius.circular(30)),
      ),
      child: Material(
        elevation: 0.0,
        shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(30.0)),
        child: BottomNavigationBar(
          elevation: 0,
          backgroundColor: Colors.transparent,
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
                icon: Icon(Icons.favorite), title: Text('Favourite')),
            BottomNavigationBarItem(
                icon: Icon(Icons.favorite), title: Text('Favourite'))
          ],
        ),
      )),
)

字符串

31moq8wy

31moq8wy4#

Theme中的canvasColor更改为透明。

return MaterialApp(
  theme: ThemeData(
    canvasColor: Colors.transparent
  ),
);

字符串

sqougxex

sqougxex5#


的数据

class _DashBoardActivityState extends State<DashBoardActivity> {
  int _selectedIndex = 0;
  static const TextStyle optionStyle =
  TextStyle(fontSize: 30, fontWeight: FontWeight.bold);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("BottomNavigationBar"),
      backgroundColor: PrimaryColor,),
      body: Container(child: Center(child: _widgetOptions.elementAt(_selectedIndex),),),
      bottomNavigationBar: CreateBottombar(context),
    );
  }

  final _widgetOptions = [
    new ListFragScreen(),
    new ConsultationFragScreen(),
    new LabFragScreen(),
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  Container CreateBottombar(BuildContext context) {
    return Container(
      //add ClipRRect widget for Round Corner
      child: ClipRRect(
        borderRadius: const BorderRadius.only(
          topRight: Radius.circular(24),
          topLeft: Radius.circular(24),
        ),
        child: BottomNavigationBar(
          //add background color
          backgroundColor: PrimaryColor,
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: 'Home',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.business),
              label: 'Business',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.school),
              label: 'School',
            ),
          ],
          currentIndex: _selectedIndex,
          selectedItemColor: Colors.white,
          onTap: _onItemTapped,
        ),
      ),
    );
  }
}

字符串

polhcujo

polhcujo6#

@CoderMonk建议的method应该可以工作。如果它不工作,那么我认为你可能在你的Scaffold()的主体中使用了类似SafeArea()的小部件,如果是这样,你应该完全删除它,或者做一些类似的事情。

Scaffold(
  body: SafeArea(
    bottom: false,
    child: ...
  ),
);

字符串

t9aqgxwy

t9aqgxwy7#

该解决方案与extendBody,有助于删除背景的酒吧:

@override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true, // Important: to remove background of bottom navigation (making the bar transparent doesn't help)
      bottomNavigationBar: Container(
        decoration: const BoxDecoration(
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(12.0), // adjust to your liking
              topRight: Radius.circular(12.0), // adjust to your liking
            ),
            color: your_bar_color, // put the color here
          ),
          child: BottomNavigationBar(backgroundColor: Colors.transparent), // don't forget to put it
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            // widget
            // widget
            const SizedBox(height: kBottomNavigationBarHeight) // add space at the bottom due to extendBody property for proper scrolling
          ],
        ),
      ),
    );
  }

字符串

相关问题