You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter报错Incorrect use of ParentDataWidget根源排查求助

错误根源

Expanded 组件只能作为 Row、Column、Flex 这三类 Flex 容器的直接子组件使用,不能嵌套在其他非 Flex 组件内部。
错误日志已经明确指出了问题位置:你的代码中 Expanded 的父组件是 Padding,属于不兼容的父容器,完全匹配组件链 Column ← Expanded ← Padding 的报错信息。

修复方案

直接删除包裹在 Column 外层的多余 Expanded 即可。你的外层 Container 已经固定高度为270,Column 作为 Padding 的直接子组件,可自动适配父容器的可用空间,不需要额外套 Expanded。
注意:代码内部放在 Row 直接子节点位置的 Expanded 用法符合规则,无需修改。

修正后的代码片段
Positioned(
    left: 0.0,
    right: 0.0,
    bottom: 0.0,
    child: Container(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
                topLeft: Radius.circular(16.0),
                topRight: Radius.circular(16.0)),
            boxShadow: [
                BoxShadow(
                    color: Colors.black38,
                    blurRadius: 16.0,
                    spreadRadius: 0.5,
                    offset: Offset(0.7, 0.7))
            ],
        ),
        height: 270.0,
        child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 24.0, vertical: 18.0),
            // 仅删除了此处多余的Expanded,其余代码完全保留
            child: Column(
                children: [
                    Text(
                        arrivalDropText + durationRide,
                        style: TextStyle(
                            fontSize: 17.0,
                            fontFamily: "Brand-Bold",
                            color: Colors.deepPurple),
                    ),
                    SizedBox(
                        height: 6.0,
                    ),
                    Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                            Text(
                                widget.rideDetails.rider_name,
                                style: TextStyle(
                                    fontFamily: "Brand-Bold", fontSize: 24.0),
                            ),
                            Padding(
                                padding: EdgeInsets.only(right: 10.0),
                                child: Icon(Icons.phone),
                            ),
                        ],
                    ),
                    SizedBox(
                        height: 22.0,
                    ),
                    Row(
                        children: [
                            Image.asset(
                                "images/images/pickicon.png",
                                height: 16.0,
                                width: 16.0,
                            ),
                            SizedBox(
                                width: 18.0,
                            ),
                            Expanded(
                                child: Container(
                                    child: Text(
                                        widget.rideDetails.pickup_address,
                                        style: TextStyle(fontSize: 18.0),
                                        overflow: TextOverflow.ellipsis,
                                    ),
                                ),
                            ),
                        ],
                    ),
                    SizedBox(
                        height: 16.0,
                    ),
                    Row(
                        children: [
                            Image.asset(
                                "images/images/desticon.png",
                                height: 16.0,
                                width: 16.0,
                            ),
                            SizedBox(
                                width: 18.0,
                            ),
                            Expanded(
                                child: Container(
                                    child: Text(
                                        widget.rideDetails.dropoff_address,
                                        style: TextStyle(fontSize: 18.0),
                                        overflow: TextOverflow.ellipsis,
                                    ),
                                ),
                            ),
                        ],
                    ),
                    SizedBox(
                        height: 22.0,
                    ),
                    Padding(
                        padding: EdgeInsets.symmetric(horizontal: 16.0),
                        child: RaisedButton(
                            onPressed: () async {

                            },
                            color: btnClr,
                            child: Padding(
                                padding: EdgeInsets.all(17.0),
                                child: Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                        Text(
                                            btnTitle,
                                            style: TextStyle(
                                                fontSize: 20.0,
                                                fontWeight: FontWeight.bold,
                                                color: Colors.white),
                                        ),
                                        Icon(
                                            Icons.directions_car,
                                            color: Colors.white,
                                            size: 26.0,
                                        )
                                    ],
                                ),
                            ),
                        ),
                    )
                ],
            ),
        ),
    ),
),

内容的提问来源于stack exchange,提问作者Pannam T

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 15:00:02