Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何解决';RenderBox没有布局:';在卡片小部件中的颤振_Flutter_Dart_Flutter Layout - Fatal编程技术网

Flutter 如何解决';RenderBox没有布局:';在卡片小部件中的颤振

Flutter 如何解决';RenderBox没有布局:';在卡片小部件中的颤振,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我有一张有三个容器的卡片。前两个有文本,最后一个应该在一些文本旁边保存一个TextFormField。所以我有一排,让这两个人彼此站在一起。唯一的问题是,当我添加TextFormField小部件时,它不会出现,控制台抛出显示错误 ══╡ 呈现库捕获到异常 ╞═════════════════════════════════════════════════════════ I/flatter(14101):在 执行布局(): I/颤振(14101):BoxConstraints强制无限宽。 I/颤

我有一张有三个容器的卡片。前两个有文本,最后一个应该在一些文本旁边保存一个TextFormField。所以我有一排,让这两个人彼此站在一起。唯一的问题是,当我添加TextFormField小部件时,它不会出现,控制台抛出显示错误

══╡ 呈现库捕获到异常
╞═════════════════════════════════════════════════════════
I/flatter(14101):在
执行布局():
I/颤振(14101):BoxConstraints强制无限宽。
I/颤振(14101):这些无效约束被提供给
RenderPaintBoundary的layout()函数
I/颤振(14101):以下函数,可能计算了无效的
有关限制:
I/颤振(14101):\u渲染装饰。\u布局。布局框
(包装:颤振/src/material/input_decorator.省道:750:11)
I/颤振(14101):违规约束为:

I/flatter(14101):BoxConstraints(w=无穷大,0.0
TextFormField
导致问题。它需要宽度约束。
例如,用宽度将其包装到扩展的小部件或容器中。

我在回复增强贴子时,也遇到了下面同样的错误

════════ (2) 呈现库捕获到异常 ══════════════════════════ 输入装饰器, 它通常由文本字段创建,不能具有无界 当父窗口小部件不提供有限的 宽度约束。例如,如果InputDecorator包含在 行,则必须限制其宽度。展开的小部件或 SizedBox可用于约束InputDecorator的宽度 包含它的文本字段。 “package:flatter/src/material/input_decorator.dart”:断言失败: 第910行位置7:“layoutConstraints.maxWidth ════════ (3) 呈现库捕获到异常 ══════════════════════════ RenderBox不是 布局:_RenderDecoration#b1ce0 relayoutBoundary=up26 NEEDS-PAINT 需要-合成-比特-更新 “package:flatter/src/rendering/box.dart”:失败的断言:第1681行 pos 12:“hasSize”用户创建的出错小部件的祖先 was:TextField file:///C:/CommBack/My_Workplace/Flutter/wiremusic/wiremusic_dev/lib/wire/widgets/searchfield.dart:15:14 ══════════════════════════════════════════════════════════

由于这一点,下面是前面的源代码行

return Container(
  color: Colors.yellow,
  constraints: BoxConstraints(minWidth: 230.0, minHeight: 25.0),
  child: TextField(),
);
因为TextField需要显式地使用祖先
hasSize
,并且在向容器显式地提到宽度之后,错误像Thanos一样消失了


希望这对某人有所帮助。

错误原因:

在水平方向上展开,
文本字段
,因此我们需要限制
文本字段
的宽度,您可以尝试以下任一操作

  • 使用扩展的

     Row(
      children: <Widget>[
        Expanded(child: TextField()),
      ],
    )
    
  • 将其包装在
    容器中
    大小框中
    并提供
    宽度

    Row(
      children: <Widget>[
        SizedBox(width: 100, child: TextField()),
      ],
    )       
    
    行(
    儿童:[
    SizedBox(宽度:100,子项:TextField()),
    ],
    )       
    

  • 花了很多时间后,我发现解决方案如下:

    请在
    ListView.builder()中添加
    shrinkWrap:true


    这对我很有帮助。

    如果您使用ListView.builder并出现此错误,那么这就是解决方案

    在生成器中使用==包络处理:true

    ListView.builder(
       itemCount: historyList.length,
       shrinkWrap: true, ///////////////////////Use This Line 
       itemBuilder: (BuildContext context, int index) {
            return historyListItem(historyList[index]['text'], 60, () {}, false, size);
        },
     )
    

    虽然此解决方案可能有助于获得ListView,但OP在发布的代码中没有。在我的情况下,扩展是导致错误的原因。此答案已经提到。您可以删除您的帖子吗?
    Row(
      children: <Widget>[
        SizedBox(width: 100, child: TextField()),
      ],
    )       
    
    ListView.builder(
       itemCount: historyList.length,
       shrinkWrap: true, ///////////////////////Use This Line 
       itemBuilder: (BuildContext context, int index) {
            return historyListItem(historyList[index]['text'], 60, () {}, false, size);
        },
     )