1

尝试在颤动中加载图像但无法做到这一点,出现以下错误

I/颤振(3214):══╡图像资源服务发现异常╞══════════════════════╕═══════════════ ═══════════════════ I/flutter(3214):抛出以下断言解析图像编解码器:I/flutter(3214):无法加载资产:资产/ test.jpg I/flutter (3214): I/flutter (3214): 当异常被抛出时,这是堆栈: I/flutter (3214): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle .dart:221:7) I/flutter (3214): I/flutter (3214): #1
AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:429:44) I/flutter (3214):我/颤动(3214):#2
AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:414:14) I/flutter (3214): #3 ImageProvider.resolve.. (package:flutter/src/painting/image_provider.dart:267:86 ) I/flutter (3214): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:143:20) I/flutter (3214): #5 ImageProvider.resolve。(包:flutter/src/painting/image_provider.dart:267:63)I/flutter(3214):(从包 dart:async 中省略了 8 帧)I/flutter(3214):I/flutter(3214):图像提供程序: AssetImage(bundle: null, name: "assets/test.jpg") I/flutter (3214): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#81de5(), name: "assets/test.jpg", scale: I /颤动(3214):1.0)我/颤动(3214):

主要.dart

lass MyApp extends StatelessWidget {
Widget build(BuildContext context) {
    return MaterialApp(
    home: Scaffold(
    appBar: AppBar(
      title: Text('EasyList'),
    ),
    body: Card(child: Column(children: < Widget > [
      Image.asset('assets/test.jpg'),
    ],),),
   ),
  );
 }
}

发布规范.yaml

flutter:
  uses-material-design: true

assets:
  - assets/test.jpg
4

2 回答 2

8

您需要在单词前面有assets:两个空格,在破折号前面需要两个额外的空格(总共 4 个)。

flutter:
  uses-material-design: true

  assets:
    - assets/test.jpg
于 2019-02-05T19:18:16.517 回答
4

或者,如果您正在使用 Android Studio IDE,则pubspec.yaml只需在文件中按 CTRL+ALT+L重新排列代码即可。然后点击包获取。

于 2019-04-06T14:50:51.590 回答