gpt4 book ai didi

flutter - 为什么我的扩展容器不占用设备的剩余高度?

转载 作者:行者123 更新时间:2023-12-03 04:41:00 25 4
gpt4 key购买 nike

我按照本教程进行操作,遇到了一个问题。我有一个主容器,并且在主容器中有一列。列内有各种元素,最后是一个扩展的容器,可产生重叠效果。但是,问题在于扩展的容器无法覆盖设备高度的其余部分,并且会在末尾留下空间,以显示父容器的背景。我是新手,所以我现在正在学习语法,我尝试将扩展容器的高度加倍,但这没有用。我怎样才能解决这个问题?
image showing how the expanded container is displaying on the screen

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),
),
),
),
),
],
),
),
);
}
}

关于flutter - 为什么我的扩展容器不占用设备的剩余高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63225087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com