图像未在Flutter中加载

问题描述 投票:0回答:3

尝试加载图像但不能这样做,导致跟随错误

I / flutter(3214):══╡图像资源服务的例外情况╞═​​════════════════════════════════════════════════════════════════════════════════════════════════ ═════════════════════════════════════════════════════════════════════════════════════════════════════════>> test.jpg I / flutter(3214):I / flutter(3214):当抛出异常时,这就是堆栈:I / flutter(3214):#0 PlatformAssetBundle.load(包: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):I / flutter(3214):#2 AssetBundleImageProvider.load(包:flutter / src / painting / image_provider.dart:414:14)I / flutter(3214):#3 ImageProvider.resolve ..(包: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中删除8帧:async)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 / flutter(3214):1.0)I / flutter(3214):

main.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'),
    ],),),
   ),
  );
 }
}

pubspec.yaml

flutter:
  uses-material-design: true

assets:
  - assets/test.jpg
flutter flutter-dependencies flutter-image
3个回答
3
投票

你需要在单词assets:前面有两个空格,在短划线前需要两个额外的空格(总共4个)。

flutter:
  uses-material-design: true

  assets:
    - assets/test.jpg

1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.