Flutter 颤振:我的Listview.builder消失在我的固定底部容器下
我正在构建一个购物车用户界面,我想在其中显示我的购物车项目列表和一个固定底部的小部件,它将显示购物车摘要详细信息 我希望购物车摘要容器固定在底部,ListView.builder可以滚动,但要位于底部小部件的顶部,而不是消失在其中 这是我的密码。我知道一定是我忽略了什么。我需要帮助 谢谢Flutter 颤振:我的Listview.builder消失在我的固定底部容器下,flutter,listview,flutter-layout,Flutter,Listview,Flutter Layout,我正在构建一个购物车用户界面,我想在其中显示我的购物车项目列表和一个固定底部的小部件,它将显示购物车摘要详细信息 我希望购物车摘要容器固定在底部,ListView.builder可以滚动,但要位于底部小部件的顶部,而不是消失在其中 这是我的密码。我知道一定是我忽略了什么。我需要帮助 谢谢 class CheckoutScreen extends StatelessWidget { static const String id = 'checkout_screen'; @override
class CheckoutScreen extends StatelessWidget {
static const String id = 'checkout_screen';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.black26,
),
onPressed: () => Navigator.pop(context),
),
title: Text(
'Shopping cart',
style: TextStyle(
fontSize: 21.0,
color: Colors.black26,
fontWeight: FontWeight.bold,
),
),
elevation: 0.0,
backgroundColor: Colors.white,
),
// bottomNavigationBar: _buildCartSummary(context),
body: Stack(
children: <Widget>[
Container(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: ListView.builder(
itemCount: 5,
itemBuilder: (context, index) {
return _buildCartItems();
},
),
),
SizedBox(height: 30),
Container(
child: Align(
alignment: Alignment.bottomCenter,
child: _buildCartSummary(context),
),
),
],
),
// Align(
// alignment: Alignment.center,
// child: Text('Your cart is empty.')),
);
}
_buildCartItems() {
return Container(
color: Colors.white,
margin: EdgeInsets.symmetric(vertical: 6.0),
child: Row(
children: <Widget>[
Expanded(
child: Container(
width: 80.0,
height: 80.0,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(20.0),
),
child: Center(
child: Container(
padding: EdgeInsets.all(4.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://s2.r29static.com/bin/entry/ebd/0,675,2000,1050/x,80/1929471/image.jpg'),
),
),
),
),
),
),
SizedBox(width: 12.0),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 100.0,
child: Text(
'Nike Air max',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
SizedBox(height: 8.0),
Row(
children: <Widget>[
Container(
width: 20.0,
height: 20.0,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadiusDirectional.circular(4.0),
),
child: Icon(
Icons.remove,
color: Colors.white,
size: 15.0,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: Text(
'1',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15.0),
),
),
Container(
width: 20.0,
height: 20.0,
decoration: BoxDecoration(
color: kThemeStyleButtonFillColour,
borderRadius: BorderRadiusDirectional.circular(4.0),
),
child: Icon(
Icons.add,
color: Colors.white,
size: 15.0,
),
),
],
),
],
),
),
Spacer(),
Expanded(
child: Text(
'\u20b9 6,000',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
),
],
),
);
}
_buildCartSummary(BuildContext context) {
return Container(
padding: EdgeInsets.fromLTRB(15.0, 8.0, 15.0, 0.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Sub Total',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
Text(
'\u20b9 480',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
],
),
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Taxes (absorbed by you)',
style: TextStyle(fontSize: 15.0),
),
Text(
'\u20b9 40',
style: TextStyle(fontSize: 15.0),
),
],
),
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Total',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
Text(
'\u20b9 520',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
],
),
MaterialButton(
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: true,
builder: (context) => SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: ShowPaymentOptionsScreen(),
),
),
);
},
height: 40.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
minWidth: double.infinity,
child: Text(
'PROCESS PAYMENT',
style: TextStyle(
color: Colors.white,
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
color: kThemeStyleButtonFillColour,
),
SizedBox(height: 15.0),
],
),
);
}
}
class CheckoutScreen扩展了无状态小部件{
静态常量字符串id='checkout_screen';
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
领先:IconButton(
图标:图标(
Icons.arrow\u back\u ios,
颜色:颜色。黑色,
),
onPressed:()=>Navigator.pop(上下文),
),
标题:正文(
“购物车”,
样式:TextStyle(
字体大小:21.0,
颜色:颜色。黑色,
fontWeight:fontWeight.bold,
),
),
标高:0.0,
背景颜色:Colors.white,
),
//底部导航栏:_buildCartSummary(上下文),
主体:堆栈(
儿童:[
容器(
填充:常量边集。对称(水平:16.0),
子项:ListView.builder(
物品计数:5,
itemBuilder:(上下文,索引){
返回_buildCartItems();
},
),
),
尺寸箱(高度:30),
容器(
子对象:对齐(
对齐:对齐.bottomCenter,
子项:_buildCartSummary(上下文),
),
),
],
),
//对齐(
//对齐:对齐.center,
//孩子:文本('你的购物车是空的'),
);
}
_buildCartItems(){
返回容器(
颜色:颜色,白色,
边缘:边缘组。对称(垂直:6.0),
孩子:排(
儿童:[
扩大(
子:容器(
宽度:80.0,
身高:80.0,
装饰:盒子装饰(
颜色:颜色。灰色[300],
边界半径:边界半径。圆形(20.0),
),
儿童:中心(
子:容器(
填充:所有边缘设置(4.0),
装饰:盒子装饰(
边界半径:边界半径。圆形(20.0),
图像:装饰图像(
适合:BoxFit.cover,
图片:NetworkImage(
'https://s2.r29static.com/bin/entry/ebd/0,67520001050/x,80/1929471/image.jpg'),
),
),
),
),
),
),
尺寸箱(宽度:12.0),
扩大(
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
容器(
宽度:100.0,
子:文本(
“Nike Air max”,
样式:TextStyle(fontWeight:fontWeight.bold),
),
),
尺寸箱(高度:8.0),
划船(
儿童:[
容器(
宽度:20.0,
身高:20.0,
装饰:盒子装饰(
颜色:颜色。灰色[200],
边界半径:边界半径方向。圆形(4.0),
),
子:图标(
图标。删除,
颜色:颜色,白色,
尺寸:15.0,
),
),
填充物(
填充:常量边集。对称(水平:15.0),
子:文本(
'1',
样式:TextStyle(
fontWeight:fontWeight.bold,fontSize:15.0),
),
),
容器(
宽度:20.0,
身高:20.0,
装饰:盒子装饰(
颜色:KThemestyleButtonFillColor,
边界半径:边界半径方向。圆形(4.0),
),
子:图标(
Icons.add,
颜色:颜色,白色,
尺寸:15.0,
),
),
],
),
],
),
),
垫片(),
扩大(
子:文本(
“\u20b9 6000”,
样式:TextStyle(fontWeight:fontWeight.bold,fontSize:15.0),
),
),
],
),
);
}
_buildCartSummary(BuildContext上下文){
返回容器(
填充:来自LTRB(15.0,8.0,15.0,0.0)的边缘设置,
子:列(
mainAxisAlignment:mainAxisAlignment.end,
儿童:[
分隔符(),
划船(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
正文(
“小计”,
样式:TextStyle(fontWeight:fontWeight.bold,fontSize:15.0),
),
正文(
“\u20b9 480”,
样式:TextStyle(fontWeight:fontWeight.bold,fontSize:15.0),
),
],
),
尺寸箱(高度:10.0),
划船(
mainAxisAlignment:mainAxisAlignment.spaceBetween,
儿童:[
正文(
“税款(由您吸收)”,
样式:TextStyle(fontSize:15.0),
),
正文(
body: Stack(
children: <Widget>[
Container(
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 30),
child: ListView.builder(
itemCount: 5,
itemBuilder: (context, index) {
return _buildCartItems();
},
),
),
Container(
height: 30,
child: Align(
alignment: Alignment.bottomCenter,
child: _buildCartSummary(context),
),
),
],
),
Positioned(
bottom: 0.0,
right: 0.0,
left: 0.0,
child: Container(
color: Colors.white,
child: Align(
alignment: Alignment.bottomCenter,
child: _buildCartSummary(context),
),
),
),
class CheckoutScreen extends StatelessWidget {
static const String id = 'checkout_screen';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.black26,
),
onPressed: () => Navigator.pop(context),
),
title: Text(
'Shopping cart',
style: TextStyle(
fontSize: 21.0,
color: Colors.black26,
fontWeight: FontWeight.bold,
),
),
elevation: 0.0,
backgroundColor: Colors.white,
),
// bottomNavigationBar: _buildCartSummary(context),
body: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height - 225,
child: ListView.builder(
shrinkWrap: true,
itemCount: 6,
itemBuilder: (context, index) {
return _buildCartItems();
},
),
),
Expanded(
// height: 300,
// color: Colors.white,
child: Align(
alignment: Alignment.bottomCenter,
child: _buildCartSummary(context),
),
)
],
),
);
}
_buildCartItems() {
return Container(
color: Colors.white,
margin: EdgeInsets.symmetric(vertical: 6.0),
child: Row(
children: <Widget>[
Container(
width: 80.0,
height: 80.0,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(20.0),
),
child: Center(
child: Container(
padding: EdgeInsets.all(4.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://s2.r29static.com/bin/entry/ebd/0,675,2000,1050/x,80/1929471/image.jpg'),
),
),
),
),
),
SizedBox(width: 12.0),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
width: 100.0,
child: Text(
'Nike Air max',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
SizedBox(height: 8.0),
Row(
children: <Widget>[
Container(
width: 20.0,
height: 20.0,
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadiusDirectional.circular(4.0),
),
child: Icon(
Icons.remove,
color: Colors.white,
size: 15.0,
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: Text(
'1',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15.0),
),
),
Container(
width: 20.0,
height: 20.0,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadiusDirectional.circular(4.0),
),
child: Icon(
Icons.add,
color: Colors.white,
size: 15.0,
),
),
],
),
],
),
Spacer(),
Text(
'\u20b9 6,000',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
],
),
);
}
_buildCartSummary(BuildContext context) {
return Container(
height: 200,
color: Colors.white,
padding: EdgeInsets.fromLTRB(15.0, 8.0, 15.0, 0.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Divider(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Sub Total',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
Text(
'\u20b9 480',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
],
),
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Taxes (absorbed by you)',
style: TextStyle(fontSize: 15.0),
),
Text(
'\u20b9 40',
style: TextStyle(fontSize: 15.0),
),
],
),
SizedBox(height: 10.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Total',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
Text(
'\u20b9 520',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
),
],
),
MaterialButton(
onPressed: () {
showModalBottomSheet(
context: context,
isScrollControlled: false,
builder: (context) => SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
// child: ShowPaymentOptionsScreen(),
),
),
);
},
height: 40.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
minWidth: double.infinity,
child: Text(
'PROCESS PAYMENT',
style: TextStyle(
color: Colors.white,
fontSize: 14.0,
fontWeight: FontWeight.bold,
),
),
color: Colors.red,
),
SizedBox(height: 15.0),
],
),
);
}
}