为了得到简单的Row,当我将FutureBuilder包装在Column中时,我希望在另一个小部件中包含ListView.我得到这个错误:

The following assertion was thrown during performLayout():
I/flutter (13816): RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I/flutter (13816): When a column is in a parent that does not provide a finite height constraint, for example, if it is
I/flutter (13816): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a
I/flutter (13816): flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining
I/flutter (13816): space in the vertical direction.
I/flutter (13816): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child
I/flutter (13816): cannot simultaneously expand to fit its parent.
I/flutter (13816): Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible
I/flutter (13816): children (using Flexible rather than Expanded). This will allow the flexible children to size
I/flutter (13816): themselves to less than the infinite remaining space they would otherwise be forced to take, and
I/flutter (13816): then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum
I/flutter (13816): constraints provided by the parent.
I/flutter (13816): If this message did not help you determine the problem, consider using debugDumpRenderTree():

我的代码是:

class ActivityShowTicketReplies extends StatefulWidget {
  final Map<String, dynamic> ticketData;

  ActivityShowTicketReplies({@required this.ticketData});

  @override
  State<StatefulWidget> createState() => ActivityShowTicketRepliesState();
}

class ActivityShowTicketRepliesState extends State<ActivityShowTicketReplies> {
  TicketsTableData get _ticket => TicketsTableData.fromJson(json.decode(widget.ticketData.values.toList()[0][0].toString()));

  @override
  Widget build(BuildContext context) {
    return ScopedModel(
      model: CounterModel(),
      child: Directionality(
        textDirection: TextDirection.rtl,
        child: Scaffold(
          body: Column(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.symmetric(vertical: 20.0),
                    child: RaisedButton(
                      color: Colors.indigo,
                      onPressed: () => BlocProvider.of<AppPagesBloc>(context).dispatch(FragmentNavigateEvent(routeName: FRAGMENT_NEW_TICKET)),
                      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(50.0)),
                      child: Container(
                        child: Text(
                          'new ticket',
                          style: AppTheme(context).caption().copyWith(color: Colors.white),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
              FutureBuilder(
                future: Provider.of<TicketRepliesTableDao>(context).find(ticketId: _ticket.id),
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.done) {
                    if (snapshot.hasData) {
                      final List<TicketRepliesTableData> ticketReplies = snapshot.data;
                      if (ticketReplies.isNotEmpty) {
                        return Column(
                          children: <Widget>[
                            Card(
                              clipBehavior: Clip.antiAlias,
                              color: Colors.grey[50],
                              margin: EdgeInsets.all(10.0),
                              child: InkWell(
                                child: Stack(
                                  children: <Widget>[
                                    Column(
                                      children: <Widget>[
                                        Padding(
                                          padding: const EdgeInsets.symmetric(vertical: 12.0),
                                          child: ListTile(
                                            title: Padding(
                                              padding: const EdgeInsets.symmetric(vertical: 5.0),
                                              child: Text(
                                                'subject',
                                                style: AppTheme(context).caption().copyWith(fontFamily: 'ShabnamBold'),
                                              ),
                                            ),
                                            subtitle: Text(
                                              _ticket.subject,
                                              style: AppTheme(context).caption(),
                                            ),
                                          ),
                                        ),
                                        Container(
                                          height: 30.0,
                                          margin: EdgeInsets.zero,
                                          width: double.infinity,
                                          color: Colors.grey[200],
                                          child: Row(
                                            mainAxisAlignment: MainAxisAlignment.center,
                                            children: <Widget>[
                                              
                                            ],
                                          ),
                                        ),
                                      ],
                                    ),
                                    Align(
                                      alignment: Alignment.topLeft,
                                      child: Container(
                                          margin: EdgeInsets.only(top: 10.0),
                                          constraints: BoxConstraints(
                                            minWidth: 70.0,
                                          ),
                                          height: 20.0,
                                          width: 70.0,
                                          decoration: BoxDecoration(
                                              color: Colors.green[200],
                                              borderRadius: BorderRadius.only(
                                                topRight: Radius.circular(5.0),
                                                bottomRight: Radius.circular(5.0),
                                              )),
                                          child: Center(
                                            child: Text(
                                              'status',
                                              style: AppTheme(context).overLine().copyWith(fontFamily: 'ShabnamBold', color: Colors.black),
                                            ),
                                          )),
                                    ),
                                  ],
                                ),
                                onTap: () {},
                              ),
                            ),
                            Expanded(
                              child: ListView.builder(
                                itemBuilder: (context, index) {
                                  return Card(
                                    clipBehavior: Clip.antiAlias,
                                    child: Padding(
                                      padding: const EdgeInsets.all(20.0),
                                      child: Column(
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: <Widget>[
                                          Row(
                                            children: <Widget>[
                                              Text(
                                                ticketReplies[index].createdAt,
                                                style: AppTheme(context).caption().copyWith(fontFamily: 'ShabnamLight'),
                                              ),
                                            ],
                                          ),
                                          ListTile(
                                            title: Text(ticketReplies[index].reply),
                                          ),
                                        ],
                                      ),
                                    ),
                                  );
                                },
                                itemCount: ticketReplies.length,
                              ),
                            ),
                          ],
                        );
                      } else {
                        return Center(
                          child: Text(
                            'there isn't any reply message',
                            style: AppTheme(context).caption(),
                          ),
                        );
                      }
                    } else {
                      return _loader(context, 'no reply');
                    }
                  } else
                    return _loader(context, Strings.pleaseWait);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _loader(BuildContext context,String message) {
    return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            ColorLoader3(
              radius: 25.0,
              dotRadius: 5.0,
            ),
            Padding(
              padding: const EdgeInsets.all(3.0),
              child: Text(
                Strings.pleaseWait,
                style: AppTheme(context).caption().copyWith(color: Colors.red[900]),
              ),
            ),
          ],
        ));
  }
}

推荐答案

将你的Column包在ExpandedSizedBox内(约有height个),如下所示:

Expanded(
  child: Column(...)
)

OR

SizedBox(
  height: 200, // Some height
  child: Column(...),
)

Note Flex个类或子类(如Column)不应是其他Flex个类的子类,并且它们的父类需要是类型Flexible(即继承,如Expanded)、else, 100-class gets unbounded(并且剩余空间不能被计算),这在另一个子类try 计算和/或填充空间之前不会引起直接问题.

Flutter相关问答推荐

Flutter -修改子小部件中的AppBar

在Flutter中创建具有固定行的压缩水平列表

底部导航栏项目在抖动中不更改 colored颜色

Flutter API请求BadState响应

为什么我的PUT请求不能正常工作?

如何确定Flutter 中的文本 colored颜色 ?

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

DART:如何判断有时可以为空的泛型类型?

从图标启动器打开时,VSCode未检测到Web设备

Flutter 中的 setState() 内部是如何工作的?

如何在 Flutter 中设计像 zomato 应用程序一样的搜索字段?

如何从flutter中不同类别的列表中获取所有产品

Flutter屏幕适配 - 在模拟器和真实手机上文本尺寸不同

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

像图像一样Flutter 自定义标签

Flutter/Dart - 从外部类更新状态

如何从 Flutter Slider Widget 中移除发光效果?

如何在 SingleChildScrollView 小部件中管理自定义小部件状态

Flutter 小部件中的视图和逻辑分离

如何在 Flutter 中创建类似箭头标签的设计