[英]Layout issue with singlechildscrollview and stack
Why this code is not correct?为什么这段代码不正确?
I have this error:我有这个错误:
RenderBox was not laid out: RenderRepaintBoundary#681d3 relayoutBoundary=up1 NEEDS-PAINT 'package:flutter/src/rendering/box.dart': Failed assertion: line 1930 pos 12: 'hasSize' RenderBox 未布局:RenderRepaintBoundary#681d3relayoutBoundary=up1 NEEDS-PAINT 'package:flutter/src/rendering/box.dart':断言失败:第 1930 行 pos 12:'hasSize'
The relevant error-causing widget was Scaffold lib…\\rank\\rankView.dart:23导致错误的相关小部件是 Scaffold lib...\\rank\\rankView.dart:23
Should I define size for scaffold?我应该定义脚手架的尺寸吗?
SafeArea(
child: Scaffold(
resizeToAvoidBottomInset: false,
body: SingleChildScrollView(
child: Stack(children: <Widget>[
Positioned(
top: 550,
left: 8,
right: 8,
bottom: 0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
for (final result in controller.results)
Container(height: 50, color: Colors.black),
]))
Why you are using scaffold inside a safearea.为什么要在安全区域内使用脚手架。 If you have this as a screen.
如果你有这个作为屏幕。 they you can simply return a
scaffold
and add safearea
as a child of scaffold.他们可以简单地返回一个
scaffold
,并添加safearea
为构架的孩子。
return Scaffold(
body: SafeArea(), );
like this像这样
So better you can use container position it according to.所以你可以更好地使用容器来定位它。 and then add a child
column
to the container.然后将子
column
添加到容器中。
So your code might look like this,所以你的代码可能看起来像这样,
Scaffold(
resizeToAvoidBottomInset: false,
body: SafeArea(
child: SingleChildScrollView(
child: Container(
//you need to position from the top 550 and left right 8 units
//that you can do by the margin or padding:
margin: EdgeInsets.only(top: 550, left: 8, right: 8),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
for (final result in controller.results)
Container(height: 50, color: Colors.black),
],
),
),
),
),
);
That should work perfectly.那应该完美地工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.