在 Flutter 中使用“bottomNavigationBar”后 'body' 部分不可见
The 'body' part is not visible after using ' bottomNavigationBar' in Flutter
每当我使用 bottomNavigationBar: 它不会在屏幕上显示 body: 部分但是当我删除 bottomNavigationBar: 然后显示 body:
这是 代码
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Home', textAlign: TextAlign.center),
actions: <Widget>[],
backgroundColor: Color(0xffd81b60),
),
bottomNavigationBar: _getNavBar(context),
body: ListView(children: <Widget>[
SizedBox(height: 300.0),
Container(
height: 50,
width: 10,
child: Center(
child: RaisedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => mealwisePage()));
},
color: Colors.pink,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Meal Wise',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, color: Colors.white),
),), ), ), ), ]),);}
_getNavBar(context) {
return Stack(
children: <Widget>[
Positioned(
bottom: 0,
child: ClipPath(
clipper: NavBarClipper(),
child: Container(
height: 50,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.pink,
Colors.pink.shade800,
])), ),),),],);}
No error is showing just body is invisible on the screen
有什么解决办法吗?
底部导航是脚手架构造函数的一部分 Widget bottomNavigationBar
而不是正文,因此重构您的代码如下所示
Scaffold(
appBar: AppBar(
title: const Text('Home', textAlign: TextAlign.center),
backgroundColor: Color(0xffd81b60),
),
resizeToAvoidBottomPadding: false,
body: ListView(children: <Widget>[
Container(
child:Column(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(15.0, 40.0, 40.0, 25.0),
child: Center(
child: Text(
'Home',
textAlign: TextAlign.center,
),),), ], ),),
SizedBox(height: 200.0),
]),//listview
bottomNavigationBar: _getNavBar(context),
);//scaffold
更新编辑
child: Container(
height: 50,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
你必须给这个 width: MediaQuery.of(context).size.width,
例子一个值 width: MediaQuery.of(context).size.width * .98,
我发现是因为使用了Stack它和body重叠所以我改了
来自:
return Stack(
children: <Widget>[
Positioned(
bottom: 0,
child: ClipPath(
clipper: NavBarClipper(),
child: Container(),),)],)
至
return Container(
height: 90,
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Positioned(
bottom: 0,
child: ClipPath(
clipper: NavBarClipper(),
child: Container(),),),],),)
每当我使用 bottomNavigationBar: 它不会在屏幕上显示 body: 部分但是当我删除 bottomNavigationBar: 然后显示 body: 这是 代码
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Home', textAlign: TextAlign.center),
actions: <Widget>[],
backgroundColor: Color(0xffd81b60),
),
bottomNavigationBar: _getNavBar(context),
body: ListView(children: <Widget>[
SizedBox(height: 300.0),
Container(
height: 50,
width: 10,
child: Center(
child: RaisedButton(
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => mealwisePage()));
},
color: Colors.pink,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Meal Wise',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20, color: Colors.white),
),), ), ), ), ]),);}
_getNavBar(context) {
return Stack(
children: <Widget>[
Positioned(
bottom: 0,
child: ClipPath(
clipper: NavBarClipper(),
child: Container(
height: 50,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.pink,
Colors.pink.shade800,
])), ),),),],);}
No error is showing just body is invisible on the screen
有什么解决办法吗?
底部导航是脚手架构造函数的一部分 Widget bottomNavigationBar
而不是正文,因此重构您的代码如下所示
Scaffold(
appBar: AppBar(
title: const Text('Home', textAlign: TextAlign.center),
backgroundColor: Color(0xffd81b60),
),
resizeToAvoidBottomPadding: false,
body: ListView(children: <Widget>[
Container(
child:Column(
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(15.0, 40.0, 40.0, 25.0),
child: Center(
child: Text(
'Home',
textAlign: TextAlign.center,
),),), ], ),),
SizedBox(height: 200.0),
]),//listview
bottomNavigationBar: _getNavBar(context),
);//scaffold
更新编辑
child: Container(
height: 50,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
你必须给这个 width: MediaQuery.of(context).size.width,
例子一个值 width: MediaQuery.of(context).size.width * .98,
我发现是因为使用了Stack它和body重叠所以我改了 来自:
return Stack(
children: <Widget>[
Positioned(
bottom: 0,
child: ClipPath(
clipper: NavBarClipper(),
child: Container(),),)],)
至
return Container(
height: 90,
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Positioned(
bottom: 0,
child: ClipPath(
clipper: NavBarClipper(),
child: Container(),),),],),)