Hi Guys,
currently i am doing my first Flutter Project with Android Studio.
And everything went good until i tried to load an image into my App, it never shows up on the Emulator.
I tried a few steps to solve the problem.
- i checked my pubspec.yami folder and it seems to be ok.
assets:
- lib/images/japanflag.png
-
I did run "Flutter Clean"
-
i did run "flutter pub outdated"
And after all that it is stil not working and i made sure that my images folder is in the right place.
import 'package:flutter/material.dart';
class StartPage extends StatelessWidget {
const StartPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255,215,165,187),
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [Text("JAPAN JOURNEY",
style: TextStyle(
fontSize: 38,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Image.asset("lib/images/japanflag.png", height: 30,)
],
)
I hope that someone can help me tho :D, thanks.
3
Answers
I would follow the flutter way and create an assets folder for all the assets.
But in your case you should add lib and lib/images also to your assets.
From the docs:
https://docs.flutter.dev/ui/assets/assets-and-images
You should specify your assets in the pubspec.yaml file for that scenario.
Solution 1:
If you added the image and you didn’t stop the app,
try to stop the app and build it again, this can solve the issue.
If it does not work, try solution 2.
Solution 2
Create an
assets
folder inside your root project.inside it create an
images
folder then put yourjapanflag.png
image.Inside your
pubspec.yaml
make sure to have :then do
flutter pub get
in your terminal.then display your image like:
Stop and Build the app, the image should show up.