仅在重新运行后才加载图像(抖动)

时间:2020-05-13 20:38:56

标签: iphone image flutter assets hot-reload

在Android开发者IDE的IOS设备上加载flutter应用程序时,该应用程序将正常加载,但是直到再次单击“运行'main.dart'”按钮,图像才会加载到该应用程序上。将设备与计算机断开连接并重新启动应用程序后,图像将永远不会加载。

关于此问题,我唯一能找到的建议是“您的Yaml文件一定是错误的”。我向您保证,我已经检查了pubspec yaml一百万次,并且找不到任何错误。此外,当手机连接到我的计算机时,图像确实会加载,但仅在安装并第一次运行该应用程序后第二次运行该应用程序时才加载。任何帮助深表感谢!!我的pubspec.yaml文件和flutter doctor -v输出如下。再次感谢!

PUBSPEC.YAML:

name: billsplitter
description: Split bills easily between your friends!

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  intro_slider: ^2.2.9

flutter:
  uses-material-design: true
  assets:
    - ./images/Welcome to Bill.jpg
    - ./images/bill description.jpg
    - ./images/bill description2.jpg
    - ./images/bill description3.jpg

  fonts:
    - family: Suez
      fonts:
        - asset: fonts/SuezOne-Regular.ttf

颤抖医生-V:

[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287, locale en-US)
    • Flutter version 1.12.13+hotfix.9 at /Users/calebburbach/Documents/development/flutter
    • Framework revision f139b11009 (6 weeks ago), 2020-03-30 13:57:30 -0700
    • Engine revision af51afceb8
    • Dart version 2.7.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/calebburbach/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-29, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.4.1, Build version 11E503a
    • CocoaPods version 1.9.1

[✓] Android Studio (version 3.6)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 45.1.1
    • Dart plugin version 192.7761
    • Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)

[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.

3 个答案:

答案 0 :(得分:0)

像这样在images目录和pubspec.yaml文件中更改图像文件的名称:

assets:
    - images/welcome_to_Bill.jpg
    - images/bill_description.jpg
    - images/bill_description2.jpg
    - images/bill_description3.jpg

然后运行此命令flutter pub get

答案 1 :(得分:0)

您无需提供每个图像的定义,只需提供如下所示的文件夹路径:

    assets:
        - images/

答案 2 :(得分:0)

您是否检查了 initState() 函数?加载函数之一中可能缺少 setState() 调用。

setState() {
   // You can initialize a list here, if you have a list that images use.
}

当我在加载时尝试将元素添加到 setState() 函数中的列表时,这解决了这个问题。