繁体   English   中英

singlechildscrollview 和堆栈的布局问题

[英]Layout issue with singlechildscrollview and stack

为什么这段代码不正确?

我有这个错误:

RenderBox 未布局:RenderRepaintBoundary#681d3relayoutBoundary=up1 NEEDS-PAINT 'package:flutter/src/rendering/box.dart':断言失败:第 1930 行 pos 12:'hasSize'

导致错误的相关小部件是 Scaffold 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为构架的孩子。

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

那应该完美地工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM