singlechildscrollview和堆栈的布局问题



为什么这个代码不正确?

我有这个错误:

RenderBox未布局:RenderRepaintBoundary#681d3 relayoutBoundary=up1 NEEDS-PAINT'package:flatt/src/rendering/box.dart':断言失败:第1930行位置12:"hasSize">

导致相关错误的小部件为断头台lib…\rank\rankView.dart:23

我应该定义脚手架的尺寸吗?

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

为什么在安全区域内使用脚手架。如果你有一个屏幕。您可以简单地返回一个scaffold并添加safearea作为scaffold的子级。

return Scaffold(
body: SafeArea(), ); 

像这个

  1. 您正在使用堆栈在滚动视图中定位。我认为这不是个好办法。因为堆栈中只有一个小部件

因此,您可以更好地根据使用容器位置,然后将子column添加到容器中。

所以你的代码可能是这样的,

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

这应该非常有效。

最新更新