【问题标题】:How do I get the gradient and asset image to work together?如何让渐变和资产图像协同工作?
【发布时间】:2021-03-26 15:50:25
【问题描述】:

我得到的唯一错误是“未定义命名参数'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'),
            ),
          ),
        ),
  );
}

【问题讨论】:

  • 您需要清楚地解释您的问题。代码当前已编辑且格式正确...您可以编辑问题以正确解释您的问题吗?

标签: flutter dart gradient


【解决方案1】:

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

           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'))
              ),
            )

【讨论】:

    猜你喜欢
    • 2013-10-06
    • 2020-01-17
    • 2017-11-15
    • 2020-01-13
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多