Flutter报错 Incorrect use of ParentDataWidget When the exception was thrown, this was the stack:

The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.

The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type StackParentData.

Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a Stack widget.

The ownership chain for the RenderObject that received the incompatible parent data was:
  ConstrainedBox ← Container ← Expanded ← Stack ← Column ← Padding ← ColoredBox ← ConstrainedBox ← Container ← Consumer<InvestmentModel> ← ⋯
When the exception was thrown, this was the stack: 
#0      RenderObjectElement._updateParentData.<anonymous closure> (package:flutter/src/widgets/framework.dart:5816:11)
#1      RenderObjectElement._updateParentData (package:flutter/src/widgets/framework.dart:5832:6)
#2      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5066:15)
#3      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4729:14)
#4      ParentDataElement._applyParentData.applyParentDataToChild (package:flutter/src/widgets/framework.dart:5069:15)
...
====================================================================================================
flutter: ViewStateModel---constructor--->DocumentaryModel

报错发现Stack布局中不知道什么报错,查看代码
最终发现是
Expanded组件,在“Container、Padding、Stack”组件中导致的。
Expanded、Flexible只在Row、Column等组件内,不在其他组件内使用。
修改方法去掉Expanded

      return Container(
          width: MediaQuery.of(context).size.width,
          padding: EdgeInsets.fromLTRB(16, 6, 16, 0),
          color: appWhite,
          child:
              Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
            Stack(children: [
              Expanded( //去掉这里
                child: Container(
                    width: MediaQuery.of(context).size.width,
                    child: _buildAmountTextField(model)),
              ),
              Positioned(
                  right: 1.0,
                  bottom: 0,
                  child: Container(
                    margin: EdgeInsets.only(bottom: 8),
                    child: Row(
                        crossAxisAlignment: CrossAxisAlignment.center,
                        children: [
                          Container(
                              height: 42,
                              child: CupertinoButtonWidget(
                                  radius: 4,
                                  color: appWhite,
                                  child: Text(
                                      S().string_documentary_investment_max,
                                      style: t14blue),
                                  onPressed: () {
                                    model.setMax(context);
                                  })),
                          SizedBox(
                            width: 4,
                          ),
                          Container(
                            width: 1,
                            height: 42,
                            color: colorD8D8D8,
                          ),
                          SizedBox(
                            width: 12,
                          ),
                          Text(data?.investmentCoinSymbol ?? "",
                              style: t16blackNormal),
                        ]),
                  ))
            ]),
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值