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

Flutter代码求助:移除Expanded后child字段出现波浪线报错

问题:移除Expanded后Container的child字段报错

你的代码报错和移除Expanded无关,核心问题是同一个Container组件重复定义了两次child属性——Flutter里每个Widget的属性都是唯一的,不能重复声明同一个属性。

看你代码里的Container部分:

Container(
  color: Color.fromARGB(255, 255, 255, 255),
  child: Column(mainAxisAlignment: MainAxisAlignment.start), // 第一个child
  child: const Center( // 第二个重复的child,这是错误根源
      child: Image(
          height: 1000,
          width: 1000,
          image: AssetImage("lib/images/instruction.png"))),
)

修正方案

根据你的需求二选一:

方案1:只保留图片的child

如果你不需要那个空的Column,直接删掉重复的child声明即可:

import 'package:flutter/material.dart';

class Introduction extends StatefulWidget {
  const Introduction({super.key});

  @override
  State<Introduction> createState() => _IntroductionState();
}

class _IntroductionState extends State<Introduction> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(children: [
      Container(
        color: Color.fromARGB(255, 255, 255, 255),
        child: const Center(
            child: Image(
                height: 1000,
                width: 1000,
                image: AssetImage("lib/images/instruction.png"))),
      )
    ]));
  }
}

方案2:嵌套Column和图片

如果需要保留Column布局,把图片放到Column的children列表里,而不是重复定义child:

import 'package:flutter/material.dart';

class Introduction extends StatefulWidget {
  const Introduction({super.key});

  @override
  State<Introduction> createState() => _IntroductionState();
}

class _IntroductionState extends State<Introduction> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(children: [
      Container(
        color: Color.fromARGB(255, 255, 255, 255),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: const [
            Center(
              child: Image(
                  height: 1000,
                  width: 1000,
                  image: AssetImage("lib/images/instruction.png")),
            )
          ],
        ),
      )
    ]));
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 10:05:32