如何让渐变和资产图像协同工作?

How do I get the gradient and asset image to work together?

我得到的唯一错误是“未定义命名参数 'body'”。 ...我该如何解决?

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
            begin: Alignment.topCenter, 
            end: Alignment.bottomCenter, 
            colors: [const Color(0xFF50658C), const Color(0xFF2D4067)]
       ),
     ),
    ),
          body: Center(
            child: Image(
                image: AssetImage('assets/space.png'),
            ),
          ),
        ),
  );
}

您的图片应该放在容器的装饰内,以便应用渐变。当您将图像分配给容器的子项时,它将出现在所有装饰的顶部。 你会希望你的容器看起来像这样。

           Container(
              decoration: BoxDecoration(
                gradient: LinearGradient(
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter,
                    colors: [const Color(0xFF50658C), const Color(0xFF2D4067)]
                ),
                image: DecorationImage(image: AssetImage('assets/space.png'))
              ),
            )