我想添加Column个小部件到Row个小部件.

我有一个如下的数据 struct :

Scaffold
 - Padding
    - SingleChildScrollView
       - Column
          - Row
             - CircleAvatar
             - Column (The Column I am talking about below)
                - Text
                - Row
                   - Expanded
                      - MaterialButton
                   - Expanded
                      - Container
                   - Expanded
                      - MaterialButton
          - ListTile

在将ColumnRow相加时,我收到错误:

════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
RenderFlex children have non-zero flex but incoming width constraints are unbounded.

When a row is in a parent that does not provide a finite width constraint, for example if it is in a horizontal scrollable, it will try to shrink-wrap its children along the horizontal axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the horizontal direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.

Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.

If this message did not help you determine the problem, consider using debugDumpRenderTree():
  https://flutter.dev/debugging/#rendering-layer
  http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is: RenderFlex#acbae relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
    constraints: BoxConstraints(unconstrained)
    size: MISSING
    direction: horizontal
    mainAxisAlignment: start
    mainAxisSize: max
    crossAxisAlignment: center
    textDirection: ltr
    verticalDirection: down
    child 1: RenderConstrainedBox#404ec NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
        constraints: MISSING
        size: MISSING
        additionalConstraints: BoxConstraints(w=180.0, h=50.0)
        child: RenderSemanticsAnnotations#4f838 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: <none>
            constraints: MISSING
            semantic boundary
            size: MISSING
            child: _RenderInputPadding#04251 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                child: RenderConstrainedBox#3337d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                    parentData: offset=Offset(0.0, 0.0)
                    constraints: MISSING
                    size: MISSING
                    additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
    child 2: RenderLimitedBox#593aa NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
        constraints: MISSING
        size: MISSING
        maxWidth: 0.0
        maxHeight: 0.0
        child: RenderConstrainedBox#d1172 NEEDS-LAYOUT NEEDS-PAINT
            parentData: <none>
            constraints: MISSING
            size: MISSING
            additionalConstraints: BoxConstraints(biggest)
    child 3: RenderConstrainedBox#42764 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
        constraints: MISSING
        size: MISSING
        additionalConstraints: BoxConstraints(w=180.0, h=50.0)
        child: RenderSemanticsAnnotations#7ec96 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: <none>
            constraints: MISSING
            semantic boundary
            size: MISSING
            child: _RenderInputPadding#6aa1f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                child: RenderConstrainedBox#e1f60 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                    parentData: offset=Offset(0.0, 0.0)
                    constraints: MISSING
                    size: MISSING
                    additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
The creator information is set to: Row ← Column ← Row ← Column ← _SingleChildViewport ← IgnorePointer-[GlobalKey#10aed] ← Semantics ← Listener ← _GestureSemantics ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#23575] ← Listener ← _ScrollableScope ← ⋯
The nearest ancestor providing an unbounded width constraint is: RenderFlex#ede32 relayoutBoundary=up13 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE

See also: https://flutter.dev/layout/

If none of the above helps enough to fix this problem, please don't hesitate to file a bug:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md
The relevant error-causing widget was
Row
When the exception was thrown, this was the stack
#0      RenderFlex.performLayout.<anonymous closure>
#1      RenderFlex.performLayout
#2      RenderObject.layout
#3      RenderBox.layout
#4      ChildLayoutHelper.layoutChild
#5      RenderFlex._computeSizes
#6      RenderFlex.performLayout
#7      RenderObject.layout
#8      RenderBox.layout
#9      ChildLayoutHelper.layoutChild
#10     RenderFlex._computeSizes
#11     RenderFlex.performLayout
#12     RenderObject.layout
#13     RenderBox.layout
#14     ChildLayoutHelper.layoutChild
#15     RenderFlex._computeSizes
#16     RenderFlex.performLayout
#17     RenderObject.layout
#18     RenderBox.layout
#19     _RenderSingleChildViewport.performLayout
#20     RenderObject.layout
#21     RenderBox.layout
#22     RenderProxyBoxMixin.performLayout
#23     RenderObject.layout
#24     RenderBox.layout
#25     RenderProxyBoxMixin.performLayout
#26     RenderObject.layout
#27     RenderBox.layout
#28     RenderProxyBoxMixin.performLayout
#29     RenderObject.layout
#30     RenderBox.layout
#31     RenderProxyBoxMixin.performLayout
#32     RenderObject.layout
#33     RenderBox.layout
#34     RenderProxyBoxMixin.performLayout
#35     RenderObject.layout
#36     RenderBox.layout
#37     RenderProxyBoxMixin.performLayout
#38     RenderObject.layout
#39     RenderBox.layout
#40     RenderProxyBoxMixin.performLayout
#41     RenderObject.layout
#42     RenderBox.layout
#43     RenderProxyBoxMixin.performLayout
#44     RenderCustomPaint.performLayout
#45     RenderObject.layout
#46     RenderBox.layout
#47     RenderProxyBoxMixin.performLayout
#48     RenderObject.layout
#49     RenderBox.layout
#50     RenderPadding.performLayout
#51     RenderObject.layout
#52     RenderBox.layout
#53     MultiChildLayoutDelegate.layoutChild
#54     _ScaffoldLayout.performLayout
#55     MultiChildLayoutDelegate._callPerformLayout
#56     RenderCustomMultiChildLayoutBox.performLayout
#57     RenderObject._layoutWithoutResize
#58     PipelineOwner.flushLayout
#59     RendererBinding.drawFrame
#60     WidgetsBinding.drawFrame
#61     RendererBinding._handlePersistentFrameCallback
#62     SchedulerBinding._invokeFrameCallback
#63     SchedulerBinding.handleDrawFrame
#64     SchedulerBinding._handleDrawFrame
#68     _invoke (dart:ui/hooks.dart:150:10)
#69     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:318:5)
#70     _drawFrame (dart:ui/hooks.dart:115:31)
(elided 3 frames from dart:async)
The following RenderObject was being processed when the exception was fired: RenderFlex#acbae relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderFlex#acbae relayoutBoundary=up15 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
    parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
    constraints: BoxConstraints(unconstrained)
    size: MISSING
    direction: horizontal
    mainAxisAlignment: start
    mainAxisSize: max
    crossAxisAlignment: center
    textDirection: ltr
    verticalDirection: down
    child 1: RenderConstrainedBox#404ec NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
        constraints: MISSING
        size: MISSING
        additionalConstraints: BoxConstraints(w=180.0, h=50.0)
        child: RenderSemanticsAnnotations#4f838 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: <none>
            constraints: MISSING
            semantic boundary
            size: MISSING
            child: _RenderInputPadding#04251 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                child: RenderConstrainedBox#3337d NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                    parentData: offset=Offset(0.0, 0.0)
                    constraints: MISSING
                    size: MISSING
                    additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
    child 2: RenderLimitedBox#593aa NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=1; fit=FlexFit.tight
        constraints: MISSING
        size: MISSING
        maxWidth: 0.0
        maxHeight: 0.0
        child: RenderConstrainedBox#d1172 NEEDS-LAYOUT NEEDS-PAINT
            parentData: <none>
            constraints: MISSING
            size: MISSING
            additionalConstraints: BoxConstraints(biggest)
    child 3: RenderConstrainedBox#42764 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
        parentData: offset=Offset(0.0, 0.0); flex=3; fit=FlexFit.tight
        constraints: MISSING
        size: MISSING
        additionalConstraints: BoxConstraints(w=180.0, h=50.0)
        child: RenderSemanticsAnnotations#7ec96 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
            parentData: <none>
            constraints: MISSING
            semantic boundary
            size: MISSING
            child: _RenderInputPadding#6aa1f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                parentData: <none>
                constraints: MISSING
                size: MISSING
                child: RenderConstrainedBox#e1f60 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
                    parentData: offset=Offset(0.0, 0.0)
                    constraints: MISSING
                    size: MISSING
                    additionalConstraints: BoxConstraints(88.0<=w<=Infinity, 36.0<=h<=Infinity)
════════════════════════════════════════════════════════════════════════════════

…

我的代码是:

Row(
  children: [
    CircleAvatar(
      backgroundImage: NetworkImage(userAvatarUrl),
    ),
    Column(
      children: [
        Text(userName),
        Row(
          children: …,
        ),
      ],
    ),
  ],
),

如果您需要更多信息,请随时留言.

如何将Column个小部件添加到Row个小部件中?如果有任何帮助,我将不胜感激.提前谢谢您!

推荐答案

如果Column内的Row中的children可以是Expanded,则可以考虑将Column包装在Expanded中,如下所示:

Row(
  children: [
    CircleAvatar(
      backgroundImage: NetworkImage(userAvatarUrl),
    ),
    Expanded(
      child: Column(
        children: [
          Text(userName),
          Row(
            children: …,
          ),
      ],
    ),
    )
  ],
),

Flutter相关问答推荐

Flutter FireRestore:如何从特定/实际领域获取数据

Flutter bloc -如何使用BlocBuilder?

如何从模型列表中生成DropdownButtonFormField?

try 在Flutter应用程序中传递变量到FirebaseFirestore Where子句

无法让Riverpod Stream发出新值

如何在2024年使用Ffltter将用户数据保存在云FireStore中?

在选项卡栏视图中搜索和筛选不起作用

我怎样才能go 掉这个底部导航栏上的白色背景

如何让两个展开的Widget根据其子窗口的屏幕大小

在 Flutter 中滑动关闭 PageView.builder 时出现问题

带有命名参数的回调函数不起作用

点击后,将按钮的 colored颜色 禁用/更改一段时间

使用Flutter项目设置Firebase遇到困难?这些解决方案或许能帮到你!

为什么我们需要使用ChangeNotifierProvider而不是仅仅使用ChangeNotifier?

切换 Firebase 项目后 Flutter FirebaseAuthException 'configuration-not-found'

如何与 PostgreSQL 和外部网站交互 flutter apk?

Flutter可滚动定位列表支持rtl方向吗?

如何在 Flutter 中测试动画图标

如何在 flutter 中同时使用 ButtonStyle() 和 ElevatedButton.styleFrom() ?

配置项目:firebase_core时出现问题