android - Flutter - 底部溢出 81 像素的 RenderFlex
问题描述
下午好,我是 android 编程新手。我想问一下我的代码中的错误。错误是“在布局期间引发了以下断言:RenderFlex 在底部溢出了 81 个像素。” . 我试图找到一个解决方案,但仍然没有任何效果。这是我的代码。谢谢你
class berita_secondpage extends StatelessWidget {
final String title;
berita_secondpage({
this.title,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30)),
image: DecorationImage(
image: AssetImage("assets/images/aquaman.jpg"),
fit: BoxFit.cover,
))),
),
Container(
height: 260,
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
title,
style: TextStyle(
// color: Colors.lightBlueAccent,
fontSize: 25,
fontWeight: FontWeight.w600,
),
),
Text(
"diupload pada : 20 Agustus 2021",
style: TextStyle(
// color: Colors.lightBlueAccent,
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
SizedBox(
width: 15,
),
Text(
"testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing",
style: TextStyle(
// color: Colors.lightBlueAccent,
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
],
),
)
],
),
)
],
));
}
}
解决方案
您的问题是由于您的第二个容器高度而发生的。你给容器高度 260,但你的文本需要更多的空间来显示。 记住,'A RenderFlex overflowed ......'想告诉你你的数据(图像/文本)需要更多空间,但你给他的空间很小。
class SecondPage extends StatelessWidget {
final String title;
SecondPage({required this.title});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Container(
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30)),
image: DecorationImage(
image: NetworkImage('https://picsum.photos/250?image=9'),
fit: BoxFit.cover,
),
),
),
),
Container(
height: 360,
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
title,
style: const TextStyle(
// color: Colors.lightBlueAccent,
fontSize: 25,
fontWeight: FontWeight.w600,
),
),
const Text(
"diupload pada : 20 Agustus 2021",
style: TextStyle(
color: Colors.lightBlueAccent,
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
const SizedBox(
width: 15,
),
const Text(
"testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing testing",
style: TextStyle(
// color: Colors.lightBlueAccent,
fontSize: 17,
fontWeight: FontWeight.w600,
),
),
],
),
)
],
),
)
],
),
));
}
}
推荐阅读
- sql - 从平均数中选择最低 2 分
- ios - 如何从 Storyboard 创建 init VC?
- php - 如何使用 PHP 从子域获取根域 cookie?
- 2sxc - 2sxc 新闻应用程序:显示超过 1 个类别和角色相关类别
- r - 如何修复'错误:位置1的大小(1)不正确,期望'在R中?
- google-chrome - Chrome(和 chromecast)播放在几秒钟后停止
- django - 从 django 模型字段中检索整数并将其添加到字典中,如果它符合条件
- c# - 如何在 Crystal Report 中显示从 mysql 检索为 blob 的图像?
- javascript - Zapier 中的 JavaScript - “IF”语句的不正确行为
- ionic-framework - 无法使用离子载玻片方法(没有 ChangeDetectorRef 提供者)