【发布时间】:2019-09-20 14:13:46
【问题描述】:
在我的颤振项目中,我有一个容器,下面有一些图标和文本。我希望将整个容器固定在屏幕底部,而不使用像下图这样的底部导航栏-
所以,我需要一个完整的示例来修复底部的容器,并使用滚动视图将我的其他组件保留在主体内。
【问题讨论】:
-
你试过了吗??
-
其实我是使用底部导航栏做到这一点的,但我不知道如何只使用容器来做到这一点
在我的颤振项目中,我有一个容器,下面有一些图标和文本。我希望将整个容器固定在屏幕底部,而不使用像下图这样的底部导航栏-
所以,我需要一个完整的示例来修复底部的容器,并使用滚动视图将我的其他组件保留在主体内。
【问题讨论】:
好的, 给你....
return Scaffold(
appBar: AppBar(
title: Text("Header"),
),
body: Column(
children: <Widget>[
Expanded(
child: Container(
alignment: Alignment.center,
child: Text("Hello"),
),
),
Container(
height: 50,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
],
),
)
],
),
);
【讨论】:
Expanded 中的Container 替换为ListView
如果你想在正文部分创建一个可滚动的项目/列表视图并想要一个固定的底部容器,你可以按照下面给出的代码:
重要提示:确保使用 Expanded 包装列表视图
导入'package:flutter/material.dart';
class ShoppingCart extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[200],
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
),
actions: <Widget>[
GestureDetector(
onTap: () {
//your code
},
child: Padding(
padding: const EdgeInsets.only(right: 15.0),
child: Icon(
Icons.delete_outline_sharp,
color: Colors.black,
size: 30,
),
)),
//Add more icon here
],
elevation: 0,
centerTitle: false,
title:
Text("Shopping Cart", style: TextStyle(color: Colors.black))),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: shoppingCartItems.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(
top: 15.0, left: 12.0, right: 12.0),
child: Container(
decoration: BoxDecoration(
// color: Color(0xffF3F3F3),
color: Colors.red,
shape: BoxShape.rectangle,
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
height: 120,
width: 360,
),
);
},
),
),
Container(
height: 150,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange[200],
borderRadius:
BorderRadius.vertical(top: Radius.circular(20.0))),
)
],
));
}
}
更新:
这是现在内置的。您可以使用 bottomNavigationBar 并自定义如下:
bottomNavigationBar: BottomAppBar(
child: Container(
height: //set your height here
width: double.maxFinite, //set your width here
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){
//on Presses functionaluty goes here
},),
//add as many tabs as you want here
],
),
),
),
【讨论】:
bottomNavigationBar: BottomAppBar(
child: Container(
height: 50.0,
width: double.maxFinite,
decoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))
),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(icon: Icon(Icons.arrow_forward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_downward), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_left), onPressed: (){},),
IconButton(icon: Icon(Icons.arrow_upward), onPressed: (){},),
],
),
),
),
【讨论】: