Reputation: 59
I am getting an error that flutter is unable to load my image which is stored in the Images directory.
I checked the indentation for the pubspec.yaml file,
and also checked the similar question for the solution to the error but nothing seems to work.
below are images for the pubspec.yaml file and code.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.greenAccent,
body: SafeArea(
child: Column(
children: [
CircleAvatar(
radius: 50.0,
backgroundImage: AssetImage('Images/xyz.jpg'),
)
],
),
),
),
);
}
}
if you could please let me know what am I doing wrong here, that would be very helpful.
Upvotes: 0
Views: 1300
Reputation: 1
if your yaml file is in the root of the project, you must include the lib directory in the path of the yaml file
assets:
in you class
placeholder: AssetImage('lib/Images/xyz.jepg'),
Upvotes: 0
Reputation: 59
As mentioned in the comment by Ameer Amjed the problem was not with the indentations or the code , it was the extension used for the image. the correct extension is important here, it was .jpeg.
Upvotes: 0
Reputation: 14775
Change your pubspecc.yaml file like below hope it help:
flutter:
assets:
- Images/
uses-material-design: true
Upvotes: 1