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),
                        ]),
                  ))
            ]),
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在触发异常时,正在处理的渲染对象如下所示: 渲染对象是Flutter框架中用于构建用户界面的核心概念之一。当我们使用Flutter开发应用程序时,我们可以使用各种各样的渲染对象来构建不同类型的UI元素。 上述异常信息表明,当应用程序运行时,某个渲染对象出现了问题并触发了异常。异常是指在程序执行过程中出现的错误或意外情况,会中断正常的程序流程。 异常信息中指出了导致问题的具体渲染对象。这可以帮助我们更快地定位并解决错误。我们可以通过查看渲染对象的相关代码来了解问题所在。 在调试过程中,我们可以检查与该渲染对象相关的代码,例如对应的Widget或布局。我们应该仔细审查该渲染对象所涉及的属性、方法和其他相关因素,以找出导致异常的原因。 常见的渲染对象异常可能包括属性缺失、不正确的布局、没有正确处理状态变化等问题。我们可以通过修改代码、添加错误处理机制或者调整布局来解决这些异常。 在定位和解决渲染对象异常问题时,我们可以使用调试工具、日志记录和异常捕获机制等技术来帮助我们更好地理解程序执行过程和发现问题所在。 总之,异常信息告诉我们正在处理的渲染对象在出现异常时出现了问题。通过仔细查看相关代码和使用适当的调试技术,我们可以找到异常的原因并解决它,以确保应用程序能够正常运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值