Flutter踩坑之RenderCustomMultiChildLayoutBox object was given an infinite size during layout

踩坑报错如下:

The following assertion was thrown during performLayout():
RenderCustomMultiChildLayoutBox object was given an infinite size during layout.

This probably means that it is a render object that tries to be as big as possible, but it was put inside another render object that allows its children to pick their own size.
The nearest ancestor providing an unbounded height constraint is: RenderFlex#6fa90 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  needs compositing
...  parentData: offset=Offset(0.0, 100.0); id=_ScaffoldSlot.body (can use size)
...  constraints: BoxConstraints(0.0<=w<=414.0, 0.0<=h<=796.0)
...  size: Size(414.0, 796.0)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
The constraints that applied to the RenderCustomMultiChildLayoutBox were: BoxConstraints(0.0<=w<=414.0, 0.0<=h<=Infinity)
The exact size it was given was: Size(414.0, Infinity)

See https://flutter.dev/docs/development/ui/layout/box-constraints for more information.

The relevant error-causing widget was: 
  Scaffold file:///Users/hello/Desktop/xzlcorp/AndroidStudioProjects/xzl-patient/lib/page/medic/medic_scan/medic_add_view.dart:109:16
When the exception was thrown, this was the stack: 
#0      RenderBox.debugAssertDoesMeetConstraints.<anonymous closure> (package:flutter/src/rendering/box.dart:1967:9)
#1      RenderBox.debugAssertDoesMeetConstraints (package:flutter/src/rendering/box.dart:2035:6)
#2      RenderBox.size=.<anonymous closure> (package:flutter/src/rendering/box.dart:1752:7)
#3      RenderBox.size= (package:flutter/src/rendering/box.dart:1754:6)
#4      RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:398:5)

布局如下

  Widget build(BuildContext context) {
    List<Suggestions> suggestions =
        provider.getAllMedicSuggestions(medicNameTypeBean);
    return Scaffold(
      appBar: _titleAppBar(),
      body: Column(
        children: <Widget>[
          _backMedicScanView(),
          _medicSearchInputItem(),
          _medicSelectNameType(suggestions)
        ],
      ),
    );
  }

定位到Column中第三个child报错,第三个child布局如下

Widget _medicSelectNameType(List<Suggestions> suggestions) {
    return Container(
      child: DefaultTabController(
        length: suggestions.length,
        initialIndex: 1,
        child: Scaffold(
            body: Column(
          children: <Widget>[
            TabBar(
                indicatorSize: TabBarIndicatorSize.label,
                unselectedLabelColor: AppColors.color_2c2f32,
                labelColor: AppColors.color_3592de,
                indicatorColor: AppColors.color_3592de,
                labelStyle: TextStyle(height: 2),
                tabs: _medicTabTitleList(suggestions)),
            Expanded(
                flex: 1,
                child: Container(
                  width: double.infinity,
                  child: TabBarView(
                      children: suggestions.map((element) {
                    return _medicSelectDisplayView(element);
                  }).toList()),
                ))
          ],
        )),
      ),
    );
  }

解决办法:把第三个child包在一个Expanded布局里,然后设置flex:1,将Column展开,就解决了这个问题。

如下:

  Widget build(BuildContext context) {
    List<Suggestions> suggestions =
        provider.getAllMedicSuggestions(medicNameTypeBean);
    return Scaffold(
      appBar: _titleAppBar(),
      body: Column(
        children: <Widget>[
          _backMedicScanView(),
          _medicSearchInputItem(),
          Expanded(
            flex: 1,
            child: _medicSelectNameType(suggestions),
          )
        ],
      ),
    );
  }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值