[主要问题] =>在构建时,我收到此错误,但在热重载后会发生。
════════ 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)
════════════════════════════════════════════════════════════════════════════════════════════════════
main.dart
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
[第二个问题] =>我的应用程序在模拟器上也可以正常工作,但是在尝试在物理设备上运行它时出现了很多错误。*
答案 0 :(得分:0)
使用此步骤
资产:
- images/folder.png