简体   繁体   English

如何解决:Flutter 中的物理设备上不显示图像背景

[英]How to fix: Image background doesn't show up on physical device in Flutter

I'm learning Flutter and I want to display a background image in my app but it's not showing up on the physical device.我正在学习 Flutter,我想在我的应用程序中显示背景图像,但它没有显示在物理设备上。

I added an image background to the application.我向应用程序添加了图像背景。 It's showing up on Android emulator.它显示在 Android 模拟器上。 But when I use a physical device then there is no image (only white background).但是当我使用物理设备时,没有图像(只有白色背景)。

I tried flutter clean , flutter pub get and then flutter build apk --release to create APK file.我尝试flutter cleanflutter pub get然后flutter build apk --release来创建APK文件。 Then I installed this on the device.然后我在设备上安装了它。

I also tried to use a device with the debugging (debug console doesn't show any errors or warnings).我还尝试使用调试设备(调试控制台不显示任何错误或警告)。

In both cases, I have a white background.在这两种情况下,我都有白色背景。

My pubspec.yaml file:我的pubspec.yaml文件:

flutter:
  assets:
    - assets/images/background.jpg

MyHomePageState class where I use this image:我在其中使用此图像的MyHomePageState类:

...
          body: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/images/background.jpg'),
                fit: BoxFit.contain,
              ),
...

The output of the flutter doctor -v command: flutter doctor -v命令的输出:

[√] Flutter (Channel stable, v1.7.8+hotfix.3, on Microsoft Windows [Version 10.0.18362.239], locale en-US)
    • Flutter version 1.7.8+hotfix.3 at C:\AndroidFlutter\flutter
    • Framework revision b712a172f9 (3 weeks ago), 2019-07-09 13:14:38 -0700
    • Engine revision 54ad777fd2
    • Dart version 2.4.0


[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at C:\AndroidFlutter
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = C:\AndroidFlutter
    • ANDROID_SDK_ROOT = C:\Program Files (x86)\Android\android-sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
    • All Android licenses accepted.

[!] Android Studio (version 3.4)
    • Android Studio at C:\Program Files\Android\Android Studio
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[√] VS Code (version 1.36.1)
    • VS Code at C:\Users\Cyber\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.2.0

[√] Connected device (1 available)
    • LG V500 • LGV500d21491fe • android-arm • Android 7.1.2 (API 25)

Here is my repository .这是我的存储库

I expected the screen to look like this (and this is from Android emulator):我希望屏幕看起来像这样(这是来自 Android 模拟器):

在此处输入图片说明

but instead, I have a white background (all controls are rendered properly.但相反,我有一个白色背景(所有控件都正确呈现。

Ok, I managed to solve my problem.好的,我设法解决了我的问题。

There are steps that helped me:有一些步骤对我有帮助:

  1. Delete local repository.删除本地存储库。
  2. Clone repository from GitHub.从 GitHub 克隆存储库。
  3. Run flutter upgrade command to have the newest version of the Flutter framework.运行flutter upgrade命令以获得最新版本的 Flutter 框架。
  4. Run flutter run command to run the application on the connected physical device.运行flutter run命令在连接的物理设备上运行应用程序。

I have found the solution with the following two links;我通过以下两个链接找到了解决方案;

  1. flutter issues颤振问题

  2. internet permission 互联网许可

<uses-permission android:name="android.permission.INTERNET" />

I have added the above line into the file AndroidManifest.xml under android/app/src/main/我已将上述行添加到 android/app/src/main/ 下的文件 AndroidManifest.xml 中

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

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