Flutter 使用底部导航栏构建可滚动页面时出现问题
当我向页面添加底部导航栏时,页面主体将消失。我相信这个问题是从我读过的其他帖子中使用SingleChildScrollView得到的 我在底部导航栏中的什么位置调用页面停止工作似乎无关紧要Flutter 使用底部导航栏构建可滚动页面时出现问题,flutter,dart,Flutter,Dart,当我向页面添加底部导航栏时,页面主体将消失。我相信这个问题是从我读过的其他帖子中使用SingleChildScrollView得到的 我在底部导航栏中的什么位置调用页面停止工作似乎无关紧要 -homeScreen.dart import 'package:flutter/material.dart'; import 'package:second_try/Widgets/headerHome.dart'; import 'package:second_try/Widgets/menuHome.d
-homeScreen.dart
import 'package:flutter/material.dart';
import 'package:second_try/Widgets/headerHome.dart';
import 'package:second_try/Widgets/menuHome.dart';
import 'package:second_try/Widgets/businessesList.dart';
class homeScreen extends StatefulWidget {
homeScreen({Key key, this.title}) : super(key: key);
final String title;
@override
_homeScreen createState() => _homeScreen();
}
class _homeScreen extends State<homeScreen> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(body: bodyHomePage()),
);
}
}
class bodyHomePage extends StatelessWidget {
const bodyHomePage({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(children: <Widget>[
headerHome(),
homeMenu(),
businessesList(),
businessesList(),
]),
),
// bottomNavigationBar: bottomNavigation(),
),
);
}
}
-------------------------------------------------------------------------------------
headerHome
import 'package:flutter/material.dart';
class headerHome extends StatelessWidget {
const headerHome({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: Container(
height: 140,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Container(
height: 140,
color: Colors.white,
),
Container(
height: 120,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.deepPurple,
Colors.deepPurpleAccent,
],
),
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 10,
),
]),
),
Positioned(
top: 98,
child: Container(
width: 340,
height: 40,
decoration: BoxDecoration(
boxShadow: [
new BoxShadow(
color: Colors.blueGrey[900],
offset: new Offset(0.0, 8.0),
blurRadius: 20.0,
)
],
borderRadius: BorderRadius.all(Radius.circular(20)),
color: Colors.white,
),
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Padding(
padding:
const EdgeInsets.only(top: 8, left: 10),
child: TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "What are you looking for?",
hintStyle:
TextStyle(color: Colors.grey[700]),
),
),
),
),
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Align(
alignment: Alignment.centerRight,
child: Icon(Icons.search,
color: Colors.deepPurple)),
),
),
])),
),
Container(
height: 100,
padding: EdgeInsets.only(top: 25),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 30),
height: 35,
/* child: Image(
image: AssetImage(
'lib/assets/white-boardwalk-icon.png',
),
),*/
),
],
),
),
Container(
height: 100,
padding: EdgeInsets.only(top: 25),
child: Row(
children: <Widget>[
Expanded(
child: Center(
child: Container(
child: Text(
'Boardwalk',
style:
TextStyle(fontSize: 30, color: Colors.white),
),
),
),
),
],
),
),
],
),
],
),
),
);
}
}
-----------------------------------------------------------------------------------------------
businessList.dart
import 'package:flutter/material.dart';
class businessesList extends StatelessWidget {
const businessesList({Key key}) : super(key: key);
Padding businessCard(String category, IconData categoryIcon) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Container(
margin: EdgeInsets.only(left: 21),
width: 200,
child: InkWell(
child: Column(
children: <Widget>[
Center(
child: Container(
height: 140,
width: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(14)),
gradient: LinearGradient(
colors: [Colors.deepPurple, Colors.deepPurpleAccent],
),
),
child: Icon(
categoryIcon,
size: 40.0,
color: Colors.white,
),
),
),
Padding(
padding: const EdgeInsets.only(top: 12),
child: Align(
alignment: Alignment.topLeft,
child: Text(
category,
style: TextStyle(
fontSize: 22,
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 6),
child: Row(
children: <Widget>[
Container(
alignment: Alignment.topLeft,
child: Icon(Icons.star, size: 16,)),
Container(
alignment: Alignment.topLeft,
child: Icon(Icons.star, size: 16,)),
Container(
alignment: Alignment.topLeft,
child: Icon(Icons.star, size: 16,)),
Container(
alignment: Alignment.topLeft,
child: Icon(Icons.star, size: 16,)),
Container(
alignment: Alignment.topLeft,
child: Icon(Icons.star, size: 16,)),
Padding(
padding: const EdgeInsets.only(left:6.0),
child: Text(
'(356)',
style: TextStyle(
fontSize: 14,
),
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 6),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Sed ut perspiciatis unde omnis iste natus error sit',
style: TextStyle(
fontSize: 16,
),
),
),
),
],
),
),
));
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 5.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 6, bottom: 12.0),
child: Container(
height: 40,
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 35),
alignment: Alignment.centerLeft,
child: Text(
'List Header',
style: TextStyle(fontSize: 24),
)),
Expanded(
child: SizedBox(),
),
Container(
margin: EdgeInsets.only(right: 35),
alignment: Alignment.centerRight,
child: Text(
'View All',
style: TextStyle(fontSize: 16),
))
],
),
),
),
Container(
height: 260,
width: 400,
child:
ListView(scrollDirection: Axis.horizontal, children: <Widget>[
businessCard('Home', Icons.home),
businessCard('Eat', Icons.restaurant_menu),
businessCard('Shop', Icons.store),
businessCard('Travel', Icons.airplanemode_active),
businessCard('Play', Icons.local_activity),
businessCard('Service', Icons.business),
]),
),
],
),
);
}
--------------------------------------------------------------------------------
bottomNavigation.dart
import 'package:flutter/material.dart';
class bottomNavigation extends StatelessWidget {
const bottomNavigation ({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: 1,
items: [
BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up,), title: Text("GLO",
style: TextStyle(color: Colors.black),),),
BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up), title:
Text("MTN"),),
BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up), title:
Text("Airtel"),),
BottomNavigationBarItem(icon: Icon(Icons.arrow_drop_up), title:
Text("Airtel"),),
],
),
),
);
}
}
I am expecting both the Pages Screen and the navigation bar to be view-able but the two are not working together at the moment
-homeScreen.dart
进口“包装:颤振/材料.省道”;
导入“package:second_try/Widgets/headerHome.dart”;
导入“package:second_try/Widgets/menuHome.dart”;
导入“package:second_try/Widgets/businessesList.dart”;
类主屏幕扩展StatefulWidget{
主屏幕({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_主屏幕createState();
}
类_主屏幕扩展状态{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主页:脚手架(正文:bodyHomePage()),
);
}
}
类bodyHomePage扩展了无状态小部件{
const bodyHomePage({Key}):超级(Key:Key);
@凌驾
小部件构建(构建上下文){
返回材料PP(
家:脚手架(
正文:SingleChildScrollView(
子项:列(子项:[
头枕(),
homeMenu(),
businessesList(),
businessesList(),
]),
),
//bottomNavigationBar:bottomNavigation(),
),
);
}
}
-------------------------------------------------------------------------------------
头巾
进口“包装:颤振/材料.省道”;
类headerHome扩展了无状态小部件{
const headerHome({Key}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
返回填充(
填充:仅限常量边集(底部:10.0),
子:容器(
身高:140,
子:列(
mainAxisSize:mainAxisSize.min,
儿童:[
堆叠(
对齐:alignment.topCenter,
儿童:[
容器(
身高:140,
颜色:颜色,白色,
),
容器(
身高:120,
装饰:盒子装饰(
梯度:线性梯度(
颜色:[
颜色,深紫色,
颜色。深紫色,
],
),
boxShadow:[
箱形阴影(
颜色:颜色,黑色,
半径:10,
),
]),
),
定位(
排名:98,
子:容器(
宽度:340,
身高:40,
装饰:盒子装饰(
boxShadow:[
新盒影(
颜色:颜色。蓝灰色[900],
偏移量:新偏移量(0.0,8.0),
半径:20.0,
)
],
borderRadius:borderRadius.all(半径圆形(20)),
颜色:颜色,白色,
),
孩子:排(
mainAxisSize:mainAxisSize.min,
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
扩大(
孩子:填充(
衬垫:
仅限常数边集(顶部:8,左侧:10),
子项:TextFormField(
装饰:输入装饰(
边框:InputBorder.none,
hintText:“你在找什么?”,
辛茨风格:
TextStyle(颜色:Colors.grey[700]),
),
),
),
),
容器(
孩子:填充(
填充:常数边集全部(8.0),
子对象:对齐(
对齐:alignment.centerRight,
子:图标(Icons.search,
颜色:颜色。深紫色),
),
),
])),
),
容器(
身高:100,
填充:仅限边缘设置(顶部:25),
孩子:排(
儿童:[
容器(
填充:仅限边缘设置(左:30),
身高:35,
/*孩子:图像(
图片:资产评估(
'lib/assets/white boardwalk icon.png',
),
),*/
),
],
),
),
容器(
身高:100,
填充:仅限边缘设置(顶部:25),
孩子:排(
儿童:[
扩大(
儿童:中心(
子:容器(
子:文本(
“木板路”,
风格:
TextStyle(字体大小:30,颜色:Colors.white),
),
),
),
),
],
),