简体   繁体   English

flutter 在初始屏幕中不显示图标图像 android 12

[英]flutter doesn't show icon image in splash screen android 12

I want to set a splash screen for android 12 in flutter我想在 flutter 中为 android 12 设置启动画面

I used flutter_native_splash package but it doesn't show my icon我使用flutter_native_splash package 但它没有显示我的图标

I added it to the pybspec.yaml file:我将它添加到pybspec.yaml文件中:

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  flutter_native_splash: ^2.2.8

dev_dependencies:
  flutter_test:
    sdk: flutter
  
flutter_native_splash:
  color: "#ffff00"
  image: assets/splash.png
  android_12:
    image: assets/splash.png

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^2.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter packages.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/

and created a separated file splash.yaml :并创建了一个单独的文件splash.yaml

flutter_native_splash:
  color: "#ffff00"
  image: assets/splash.png
  android_12:
    image: assets/splash.png

the I ran this command flutter pub run flutter_native_splash:create --path=splash.yaml我运行了这个命令flutter pub run flutter_native_splash:create --path=splash.yaml

it change the background color but it doesn't change the icon它改变了背景颜色,但它不改变图标

I read the doc of the package and read this but I found nothing我阅读了 package 的文档并阅读了这个但我什么也没发现

flutter_native_splash flutter_native_splash

Installation guide (by the author of the package):安装指南(由包的作者提供):

1. Setting the splash screen 1.设置启动画面

Add your settings to your project's pubspec.yaml file or create a file in your root project folder named flutter_native_splash.yaml with your settings.将您的设置添加到项目的pubspec.yaml文件中,或使用您的设置在名为flutter_native_splash.yaml的根项目文件夹中创建一个文件。

flutter_native_splash:
  image: assets/images/splash.png
  color: "42a5f5"

image must be a png file.图片必须是 png 文件。

You can use # in color as well.您也可以在颜色中使用#。 color: "#42a5f5" You can also set android or ios to false if you don't want to create a splash screen for a specific platform. color: "#42a5f5" 如果您不想为特定平台创建启动画面,也可以将 android 或 ios 设置为 false。

flutter_native_splash:
  image: assets/images/splash.png
  color: "42a5f5"
  android: false

In case your image should use all available screen (width and height) you can use fill property.如果您的图像应该使用所有可用的屏幕(宽度和高度),您可以使用填充属性。

flutter_native_splash:
  image: assets/images/splash.png
  color: "42a5f5"
  fill: true

Note: fill property is not yet implemented for iOS splash screens.注意:尚未为 iOS 启动屏幕实现填充属性。

If you want to disable full screen splash screen on Android you can use android_disable_fullscreen property.如果你想在 Android 上禁用全屏闪屏,你可以使用 android_disable_fullscreen 属性。

flutter_native_splash:
  image: assets/images/splash.png
  color: "42a5f5"
  android_disable_fullscreen: true

2. Run the package 2.运行package

After adding your settings, run the package with添加设置后,运行 package

flutter pub run flutter_native_splash:create When the package finishes running your splash screen is ready. flutter pub run flutter_native_splash:create当 package 完成运行时,您的启动画面就准备好了。

UPDATED更新

Android 12 Support Android 12 支持

Android 12 has a new method of adding splash screens, which consists of a window background, icon, and the icon background. Android 12 新增了一种添加闪屏的方法,由window背景、图标和图标背景组成。 Note that a background image is not supported.请注意,不支持背景图像。

The package provides Android 12 support while maintaining the legacy splash screen for previous versions of Android. package 提供 Android 12 支持,同时保留以前版本的 Android 的旧启动屏幕。

PLEASE NOTE: The splash screen may not appear when you launch the app from Android Studio.请注意:当您从 Android Studio 启动应用程序时,可能不会出现启动画面。 However, it should appear when you launch by clicking on the launch icon in Android.但是,当您通过单击 Android 中的启动图标启动时,它应该会出现。

PLEASE NOTE: There are a number of reports that non-Google launchers do not display the launch image correctly.请注意:有许多报告称非 Google 启动器无法正确显示启动图像。 If the launch image does not display correctly, please try the Google launcher to confirm that this package is working.如果启动图像无法正确显示,请尝试使用 Google 启动器确认此 package 是否正常工作。

Looking over your pubpsec.yaml file, under the assets key, you put the same key (a folder called assets).查看您的 pubpsec.yaml 文件,在 assets 键下,放置相同的键(称为 assets 的文件夹)。

 # To add assets to your application, add an assets section, like this:
  assets:
    - assets/

I would try and rename your assets directory to something else to make sure there isn't a problem there.我会尝试将您的资产目录重命名为其他目录,以确保那里没有问题。

Also, since I do not know what your assets directory contains or where in your project it is located, I would try and explicitly add your splash image in the pubspec.yaml:另外,由于我不知道您的资产目录包含什么或它在您的项目中的位置,我会尝试在 pubspec.yaml 中明确添加您的启动图像:

 # To add assets to your application, add an assets section, like this:
      assets:
        - images/splash.png

Make sure your assets directory is located in the correct place确保您的资产目录位于正确的位置

Documentation文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM