栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

flutter如何在BottomNavigationBar中添加边距或填充

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

flutter如何在BottomNavigationBar中添加边距或填充

您需要将Body和BottomNavigationBar放在Stack下,以便可以将BottomNavigationBar放在主体内容的顶部。

您的完整代码将是:

import 'package:flutter/material.dart';class App extends StatelessWidget {  @override  Widget build(BuildContext context) {    final List<Widget> _children = [      Center(        child: Container(          height: 850, // use 'MediaQuery.of(context).size.height' to fit the screen height,          color: Colors.red,        ),      )    ];    return MaterialApp(        debugShowCheckedModeBanner: false,        home: Scaffold(          body: Stack( children: <Widget>[   _children[0],   Positioned(     left: 0,     right: 0,     bottom: 0,     child: bottomNavigationBar(),   ), ],          ),        ));  }}Widget bottomNavigationBar() {  return Container(    margin: EdgeInsets.only(left: 16, right: 16),    decoration: BoxDecoration(      color: Colors.amber,      borderRadius: BorderRadius.only(          topLeft: Radius.circular(200), topRight: Radius.circular(200)),    ),    child: BottomNavigationBar(      backgroundColor: Colors.transparent,      showUnselectedLabels: true,      type: BottomNavigationBarType.fixed,      elevation: 0,      items: [        BottomNavigationBarItem(icon: Icon(Icons.home), title: Text('Home')),        BottomNavigationBarItem( icon: Icon(Icons.local_activity), title: Text('Activity')),        BottomNavigationBarItem(icon: Icon(Icons.inbox), title: Text('Inbox')),        BottomNavigationBarItem( icon: Icon(Icons.person), title: Text('Profile')),      ],    ),  );}

来自的部分代码:如何在Flutter应用中将边框半径设置为底部应用栏?

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

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,      ),    );  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/437255.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号