Reputation: 111
I tried everything but nothing seems to work. According to me, the path of the image is correct. (though I have attached an image for reference). This is the error I am getting -
════════ Exception caught by image resource service ════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: start.png
When the exception was thrown, this was the stack
#0 PlatformAssetBundle.load
package:flutter/…/services/asset_bundle.dart:225
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync
package:flutter/…/painting/image_provider.dart:668
#2 AssetBundleImageProvider.load
package:flutter/…/painting/image_provider.dart:651
#3 ImageProvider.resolveStreamForKey.<anonymous closure>
package:flutter/…/painting/image_provider.dart:504
...
Image provider: AssetImage(bundle: null, name: "start.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#2bd13(), name: "start.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════
this is **pubspec.yaml*-
name: foodfast description: A new Flutter project.
publish_to: 'none'
version: 1.0.0+1
environment: sdk: ">=2.7.0 <3.0.0"
dependencies: flutter: sdk: flutter
splashscreen: ^1.3.5
cupertino_icons: ^1.0.0 firebase_auth: ^0.20.0+1 cloud_firestore: ^0.16.0
dev_dependencies: flutter_test: sdk: flutter
flutter:
uses-material-design: true
assets: - assets/start.png
sign_in.dart
import 'package:flutter/material.dart';
class SignIn extends StatefulWidget {
@override
_SignInState createState() => _SignInState();
}
class _SignInState extends State<SignIn> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text('sign in'),
),
backgroundColor: Colors.white,
body: Center(
child: ListView(
children: <Widget>[
Image(image: AssetImage('start.png'), fit: BoxFit.cover),
new Text('text below image')
],
)),
);
}
}
Upvotes: 1
Views: 1826
Reputation: 1
Try changing the path from
AssetImage("/image/start.png")
to
AssetImage("./image/start.png")
(.
means go to the highest folder level)
This worked for me!
Upvotes: 0
Reputation: 6742
Use full path like 'assets/start.png' in your image path.
Image(image: AssetImage('assets/start.png'), fit: BoxFit.cover),
Upvotes: 1
Reputation: 521
Provide the full path even if you have already given it in pubspec.yaml.
Hence, it should be 'assets/start.png'
Upvotes: 2
Reputation: 2130
You need to add your path of image first i.e. assets and then add image name
Image(image: AssetImage('assets/start.png'), fit: BoxFit.cover),
Upvotes: 3