Flutter 如何在颤振应用程序中将边界半径设置为底部应用程序栏?

Flutter 如何在颤振应用程序中将边界半径设置为底部应用程序栏?,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我想将borderRadius设置为底部导航应用程序栏,如图所示。我曾尝试将底部导航应用程序栏置于ClipRRectborderRadius和容器中,但没有成功。那么,如何将左上角和右上角边界半径应用于底部导航栏呢。请帮忙让我知道我该怎么做 主飞镖 void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext contex

我想将borderRadius设置为底部导航应用程序栏,如图所示。我曾尝试将底部导航应用程序栏置于ClipRRectborderRadius和容器中,但没有成功。那么,如何将左上角和右上角边界半径应用于底部导航栏呢。请帮忙让我知道我该怎么做

主飞镖

    void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Food Ordering',
      theme: ThemeData(primarySwatch: Colors.blue, primaryColor: Colors.white),
      home: MyStatefulWidget(),
      routes: <String, WidgetBuilder>{
        '/detail-page': (BuildContext context) => MyDetailPage(),
      },
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

  @override
  _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int _selectedIndex = 0;
  static const TextStyle optionStyle =
      TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
  static List<Widget> _widgetOptions = <Widget>[
    HomePage(),
    HomePage(),
    HomePage(),
    HomePage(),
  ];

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        child: _widgetOptions.elementAt(_selectedIndex),
      ),
      bottomNavigationBar: BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Image.asset('assets/icon-home.png'),
              title: Text('Home'),
            ),
            BottomNavigationBarItem(
              icon: Image.asset('assets/icon-mentors.png'),
              title: Text('Mentors'),
            ),
            BottomNavigationBarItem(
              icon: Image.asset('assets/icon-messages.png'),
              title: Text('Messages'),
            ),
            BottomNavigationBarItem(
              icon: Image.asset('assets/icon-settings.png'),
              title: Text('Settings'),
            ),
          ],
          currentIndex: _selectedIndex,
          selectedItemColor: Colors.blue,
          onTap: _onItemTapped),
    );
  }
}
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:"食物订购",,
主题:主题数据(原色样本:Colors.blue,原色:Colors.white),
主页:MyStatefulWidget(),
路线:{
“/detail page”:(BuildContext上下文)=>MyDetailPage(),
},
);
}
}
类MyStatefulWidget扩展了StatefulWidget{
MyStatefulWidget({Key}):超级(Key:Key);
@凌驾
_MyStatefulWidgetState createState()=>\u MyStatefulWidgetState();
}
类_MyStatefulWidgetState扩展状态{
int _selectedIndex=0;
静态常量文本样式选项样式=
TextStyle(fontSize:30,fontWeight:fontWeight.bold);
静态列表\u widgetOptions=[
首页(),
首页(),
首页(),
首页(),
];
void\u未映射(整数索引){
设置状态(){
_selectedIndex=索引;
});
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:容器(
子项:_widgetOptions.elementAt(_selectedIndex),
),
底部导航栏:底部导航栏(
项目:[
底部导航气压计(
图标:Image.asset('assets/icon home.png'),
标题:文本(“主页”),
),
底部导航气压计(
图标:Image.asset('assets/icon-mentors.png'),
标题:文本(“导师”),
),
底部导航气压计(
图标:Image.asset('assets/icon messages.png'),
标题:文本(“消息”),
),
底部导航气压计(
图标:Image.asset('assets/icon settings.png'),
标题:文本(“设置”),
),
],
currentIndex:_selectedIndex,
选择编辑颜色:Colors.blue,
onTap:_onite已映射),
);
}
}

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

类主页扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“某些文本”),
),
主体:堆栈(
儿童:[
身体内容,
定位(
左:0,,
右:0,,
底部:0,
子项:底部导航栏,
),
],
),
);
}
小部件获取bodyContent{
返回容器(颜色:Colors.red);
}
小部件获取底部导航栏{
返回ClipRRect(
borderRadius:仅限borderRadius(
右上角:半径。圆形(40),
左上:半径。圆形(40),
),
子项:底部导航栏(
项目:[
BottomNavigationBarItem(图标:icon(Icons.home),标题:Text('1'),
BottomNavigationBarItem(图标:icon(Icons.usb),标题:Text('2')),
底部导航气压计(
图标:图标(Icons.assignment\u ind),标题:文本('3'),
底部导航气压计(
图标:图标(图标.多行图表),标题:文本('4'),
],
unselectedItemColor:Colors.grey,
选择编辑颜色:Colors.black,
showUnselectedLabels:true,
),
);
}
}
输出


或者,如果您的目标是只放置borderRadius,则可以使用ClipRect并对其应用所需的borderRadius。 以下是我对解决方案的实现:


  ClipRRect _getBtmNavBar() {
    return ClipRRect(
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(25),
        topRight: Radius.circular(25),
      ),
      child: BottomNavigationBar(
        currentIndex: _selectedIndex,
        onTap: _onTabTapped,
        selectedLabelStyle: TextStyle(
          color: Colors.black87,
          fontSize: 16,
        ),
        iconSize: 35,
        selectedItemColor: Colors.white,
        unselectedItemColor: Colors.black54,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            backgroundColor: kBottomNavBarBgColor,
            icon: Icon(Icons.home),
            title: Text('Home'),
          ),
// more BottomNavigationBarItem() goes here.

只需将底部导航栏包含在主体内,一个圆形边框容器内

小部件构建(构建上下文){
返回材料PP(
家:脚手架(
主体:容器(
装饰:盒子装饰(
图像:装饰图像(
图像:新资产图像(“assets/images/background.jpg”),
安装:BoxFit.盖),
子:堆栈(
对齐:对齐.bottomCenter,
儿童:[
扩大(
子:列(
儿童:[
扩展(子项:_子项[_currentIndex]),
],
),
),
容器(
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:仅限borderRadius(
左上:半径。圆形(20),
右上角:半径。圆形(20),
左下角:半径。圆形(0),
右下角:半径。圆形(0)),
boxShadow:[
箱形阴影(
偏移量:偏移量(0.0,1.00),/(x,y)
半径:4.00,
颜色:颜色。灰色,
扩展半径:1.00),
],
),
身高:70,
孩子:ClipRRect(
clipBehavior:Clip.hardEdge,
borderRadius:仅限borderRadius(
左上:半径。圆形(25),
右上角:半径。圆形(25),
左下角:半径。圆形(0),
右下角:半径。圆形(0)),
子:容器(
子项:底部导航栏(
背景颜色:颜色。来自RGBO(255,255,255,50),
showSelectedLabels:false,
显示未选择的标签:false,
return Scaffold(
// more Scaffold code goes here

//bottom navigationBar
      bottomNavigationBar: _getBtmNavBar(),
);
    Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      body: Container(
          decoration: BoxDecoration(
              image: DecorationImage(
                  image: new AssetImage("assets/images/background.jpg"),
                  fit: BoxFit.cover)),
          child: Stack(
            alignment: Alignment.bottomCenter,
            children: <Widget>[
              Expanded(
                child: Column(
                  children: <Widget>[
                    Expanded(child: _children[_currentIndex]),
                  ],
                ),
              ),
              Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(20),
                      topRight: Radius.circular(20),
                      bottomLeft: Radius.circular(0),
                      bottomRight: Radius.circular(0)),
                  boxShadow: [
                    BoxShadow(
                        offset: Offset(0.0, 1.00), //(x,y)
                        blurRadius: 4.00,
                        color: Colors.grey,
                        spreadRadius: 1.00),
                  ],
                ),
                height: 70,
                child: ClipRRect(
                    clipBehavior: Clip.hardEdge,
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(25),
                        topRight: Radius.circular(25),
                        bottomLeft: Radius.circular(0),
                        bottomRight: Radius.circular(0)),
                    child: Container(
                      child: BottomNavigationBar(
                        backgroundColor: Color.fromRGBO(255, 255, 255, 50),
                        showSelectedLabels: false,
                        showUnselectedLabels: false,
                        onTap: onTabTapped,
                        // new
                        currentIndex: _currentIndex,
                        // new
                        items: [
                          new BottomNavigationBarItem(
                            icon: Icon(
                              Icons.phone,
                              size: 30,
                            ),
                            title: Text('Calls'),
                          ),
                          new BottomNavigationBarItem(
                            icon: Icon(
                              Icons.mail,
                              size: 30,
                            ),
                            title: Text('Messages'),
                          ),
                          new BottomNavigationBarItem(
                              icon: Icon(
                                Icons.person,
                                size: 30,
                              ),
                              title: Text('Profile'))
                        ],
                      ),
                    )),
              )
            ],
          )),
    ));
  }
        import 'package:flutter/material.dart';

    class BottomTab extends StatefulWidget {
      @override
      State<StatefulWidget> createState() {
        return _BottomTab();
      }
    }

    class _BottomTab extends State<BottomTab> {
      int _selectedTabIndex = 0;

      List _pages = [
        Text("Home"),
        Text("Order"),
        Text("Notfication"),
        Text("More"),
      ];

      _changeIndex(int index) {
        setState(() {
          _selectedTabIndex = index;
          print("index..." + index.toString());
        });
      }

      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('bottom nav bar'),
          ),
          body: Center(child: _pages[_selectedTabIndex]),
          bottomNavigationBar: bottomNavigationBar,
        );
      }

      Widget get bottomNavigationBar {
        return 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(
                currentIndex: _selectedTabIndex,
                onTap: _changeIndex,
                type: BottomNavigationBarType.fixed,
                selectedFontSize: 12,
                unselectedFontSize: 12,
                selectedItemColor: Colors.amber[800],
                unselectedItemColor: Colors.grey[500],
                showUnselectedLabels: true,
                items: <BottomNavigationBarItem>[
                  BottomNavigationBarItem(
                    icon: new Icon(Icons.home),
                    title: new Text('Home'),
                  ),
                  BottomNavigationBarItem(
                    icon: new Icon(Icons.shopping_cart_outlined),
                    title: new Text('Order'),
                  ),
                  BottomNavigationBarItem(
                    icon: new Icon(Icons.mail),
                    title: new Text('Messages'),
                  ),
                  BottomNavigationBarItem(
                      icon: Icon(Icons.more_horiz_rounded), title: Text('More')),
                ],
              ),
            ));
      }
    }