无法加载资源:图像/L.jpg



[主要问题] => 在构建时,我收到此错误,但它在热重载后出现。

════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: images/L.jpg
When the exception was thrown, this was the stack: 
#0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1      AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
#2      AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
#3      ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
...
Image provider: AssetImage(bundle: null, name: "images/L.jpg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#dcad6(), name: "images/L.jpg", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════

主飞镖

import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Scaffold(
backgroundColor: Colors.teal,
appBar: AppBar(
title: Center(child: Text('Mi Card')),
backgroundColor: Colors.teal[300],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
backgroundImage: AssetImage('images/L.jpg'),
radius: 50.0,
),
Text(
'Jack Lee',
style: TextStyle(
fontFamily: 'Pacifico',
fontSize: 40.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'FLUTTER DEVELOPER',
style: TextStyle(
fontFamily: 'Source Sans Pro',
fontSize: 13,
color: Colors.white,
letterSpacing: 10.0,
),
),
SizedBox(
height: 10,
width: 300,
child: Divider(
color: Colors.white,
),
),
Card(
margin: EdgeInsets.all(20),
child: ListTile(
leading: Icon(
Icons.phone,
color: Colors.teal,
),
trailing: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Text(
'+91-1234567890',
style: TextStyle(
fontFamily: 'Source Sans Pro',
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.teal,
letterSpacing: 8,
),
),
),
),
),
Card(
margin: EdgeInsets.symmetric(vertical: 5, horizontal: 20),
child: ListTile(
leading: Icon(
Icons.email,
color: Colors.teal,
),
trailing: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 20),
child: Text(
'test@gmail.com',
style: TextStyle(
fontFamily: 'Source Sans Pro',
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.teal,
letterSpacing: 1.0,
),
),
),
),
),
],
),
),
),
);
}
}

Pubspec.yaml

name: Mi_Card
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: '>=2.7.0 <3.0.0'
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- images/L.jpg
fonts:
- family: Pacifico
fonts:
- asset: fonts/Pacifico-Regular.ttf
- family: Source Sans Pro
fonts:
- asset: fonts/SourceSansPro-Regular.ttf

[次要问题] => 此外,我的应用程序在模拟器上运行良好,但是当我尝试在物理设备上运行它时,它出现了很多错误。

使用以下步骤

  1. 在应用程序中创建图像文件夹
  2. 在此文件夹中添加图像
  3. 在pubspec.yaml中添加您的路径

资产:

- images/folder.png
  1. 运行颤振获取
  2. 热重启您的应用程序

最新更新