为什么PNG文件在Flutter Web应用程序中带有落下阴影?

发布于 2025-02-13 16:37:25 字数 1598 浏览 1 评论 0原文

我刚刚开始学习幻想以构建 Web应用程序,我无法弄清楚为什么在应用程序中包含的PNG图像是颗粒状的。以下是在Chrome中的外观:

”输入图像描述在此处”

这是我的应用的整体:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Test App'),
      ),
      body: Container(
        color: Colors.black,
        child: Image.asset(
          'circle.png',
          width: 208,
          height: 208,
        ),
      ),
    );
  }
}

这是我是图像使用: circle.png?dl = 0

我尝试了一些不同的PNG文件,这些文件已从无花果中导出。当我在MacOS Finder或直接在Chrome中打开它们时,它们似乎具有透明度和落下阴影。但是,当颤抖呈现它们时,会发生一些事情。

我是否缺少图像小部件上的属性?还是不支持图像上的落下阴影?

I just started to learn Flutter to build a web app, and I can't figure out why the PNG images I include in the app are grainy. Here's how it looks in Chrome:

enter image description here

Here is the entirety of my app:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Test App'),
      ),
      body: Container(
        color: Colors.black,
        child: Image.asset(
          'circle.png',
          width: 208,
          height: 208,
        ),
      ),
    );
  }
}

Here is the image I am using: https://www.dropbox.com/s/barf3lcj80fqbqg/circle.png?dl=0

I've tried a few different PNG files and these are exported from Figma. They appear to have transparency and a drop shadow when I open them in macOS Finder or in Chrome directly. But something happens when Flutter renders them.

Am I missing a property on the Image widget? Or is a drop shadow on an Image not supported?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云雾 2025-02-20 16:37:25

我只是将filterqualigal设置为filterquality.high,它在3.0.5:

Image.asset(
  'circle.png',
  width: 208,
  height: 208,
  filterQuality: FilterQuality.high,
),

I just set the filterQuality to FilterQuality.high, and it worked on 3.0.5:

Image.asset(
  'circle.png',
  width: 208,
  height: 208,
  filterQuality: FilterQuality.high,
),

╭ゆ眷念 2025-02-20 16:37:25

版本3.0.x具有此错误,但是如果您使用Flutter的实际主分支(3.1.0-0.0.pre.2481),则问题已经修复。因此,它也应该在下一个稳定版本中固定。

Version 3.0.x has this bug, but if you use the actual master branch(3.1.0-0.0.pre.2481) of flutter the issue is fixed already. Therefore it should be fixed in next stable release too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文