I’m new to flutter and learning by video’s on youtube.
And following the video I did small projects, added images, texts and etc.
While I add images it appeared at first time. But now suddenly I get the following warning on emulator:
Unable to load asset "assets/images/image_1.jpg" Exception: Asset not found
I did the pubspec.yaml file settings.
Please help to resolve this problem.
Here is my code
class MyFoodPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
onPressed: () {
print('Clicked 1');
},
child: Image.asset('assets/images/corba_1.jpg')),
)),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
onPressed: () {
print('Clicked 2');
},
child: Image.asset('assets/images/yemek_1.jpg')),
),
)),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
onPressed: () {
print('Clicked 3');
},
child: Image.asset('assets/images/tatli_1.jpg')),
)),
],
),
);
}
}
and pubspec.yaml settings
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/
# - images/a_dot_ham.jpeg
2
Answers
There is a little miss on your asset declaration, I fixed it, please try. this part : – assets/images/
so I fixed the directory access above for your asset so you do not need to declare them one by one the asset. <–
in flutter when use any audio or images or any external file you must be to add into pubspec.yamel in assets section like this :