flutter - 为什么我的扩展容器没有占据我设备的剩余高度?
问题描述
我正在按照本教程进行操作,但遇到了问题。我有一个主容器,在主容器内有一列。在列内部,有各种元素,最后有一个扩展的容器,可以产生重叠的效果。但是,问题是扩展容器没有覆盖设备高度的剩余部分,并且它在显示父容器背景的末端留下了空间。我是新来的,所以我现在正在学习语法,我尝试将扩展容器的高度加倍,但没有奏效。我怎样才能解决这个问题?
import 'package:flutter/material.dart';
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.symmetric(vertical: 30.0),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
Colors.blue[900],
Colors.blue[500],
Colors.blue[400],
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 40.0),
Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Eazy",
style: TextStyle(
color: Colors.white,
fontSize: 40.0,
fontWeight: FontWeight.w400,
),
),
Text(
"Bank",
style: TextStyle(
color: Colors.white,
fontSize: 40.0,
fontWeight: FontWeight.w400,
),
),
],
),
),
SizedBox(
height: 10.0,
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
),
),
),
],
),
),
);
}
}
解决方案
问题在于padding: EdgeInsets.symmetric(vertical: 30.0)
,两个垂直方向(顶部和向下)padding
的值30.0 logical pixels
都是 。
您可以通过使用仅对容器进行padding: EdgeInsets.only(top: 30.0)
填充来解决此问题。top
我以您的小部件树为例添加了一个演示:
import 'package:flutter/material.dart';
class LoginScreen extends StatefulWidget {
@override
_LoginScreenState createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.only(top: 30.0), // new line
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
Colors.blue[900],
Colors.blue[500],
Colors.blue[400],
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 40.0),
Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Eazy",
style: TextStyle(
color: Colors.white,
fontSize: 40.0,
fontWeight: FontWeight.w400,
),
),
Text(
"Bank",
style: TextStyle(
color: Colors.white,
fontSize: 40.0,
fontWeight: FontWeight.w400,
),
),
],
),
),
SizedBox(
height: 10.0,
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
),
),
),
],
),
),
);
}
}
推荐阅读
- arrays - 如何打印数组中所有增加索引的三元组?
- php - 我的其他项目中使用的会话信息
- python - 更新数据时如何自动刷新pyqt5表
- php - 如何使用 Codeigniter() 获取所选 chebox 的 id 并将所选记录导出为 CSV?
- go - 在 VSCode 中编辑 Go 模板时出现错误“属性值预期 css”和“at-rule 或选择器预期 css”
- php - 重复规则无效?
- javascript - 在Javascript中合并一个数组中的多个数组
- python - 引导我尝试使用 twitter 机器人将两个用户连接在一起的正确方向
- android - 不确定如何处理插入方法的返回类型
- java - 滚动文件没有在第二天创建,前一天的文件正在用新日志写入