image not displaying in flutter app. But I got some errors in debug console.
I/FlutterActivityDelegate(22603): onResume setting current activity to this
I/Fl
i mentioned images files in wrong way. i put space between '-' and image name instead of tab.
assets:
- assets/images/logo.png
Don't put spaces between the character instead of tab in pubspec.yaml file
There may be two issues:
1.) Either you pubspec.yaml file is not having proper indention. Attaching snippet for reference.
flutter:
uses-material-design: true
assets:
- assets/
- assets/
will consider all the images in the directory.
2.) If you are using .jpg image then please change it to .jpeg wherever you are calling it.
Attaching the snippet for you reference
class _UserLoginState extends State<UserLogin> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Image(image: AssetImage("assets/christmas.jpeg"),
fit: BoxFit.cover,
],
)
);
}
}
I assume you copied your files inside assets/images/
folder right?
Also you need to reference your images into the pubspec.yaml
file.
flutter:
...
assets:
- assets/images/logo.png
Refer https://api.flutter.dev/flutter/painting/AssetImage-class.html
Add assets images in pubspec.yaml file and in the asset mention the path from images and it works fine.
new AssetImage("images/logo.png")
For example
CircleAvatar(
radius: 80,
backgroundImage: AssetImage('images/logo.png'),
),
I just replaced
Image.asset("assets\images\_Lightweight.jpeg"),
To
Image.asset("assets/images/_Lightweight.jpeg"),