skip to Main Content

I want to display an image in my app.
Like this :

class _OnBoardingDataPage1State extends State<OnBoardingDataPage1> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SafeArea(
      child: SingleChildScrollView(
          child: SizedBox(
        width: double.infinity,
        child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              SizedBox(height: 5.h),
              Text(
                "MugiwarApp",
                textAlign: TextAlign.center,
                style: Theme.of(context).textTheme.titleLarge,
              ),
              SizedBox(
                height: 5.h,
              ),
              Image.asset(
                "assets/images/th-2465707242.png",
                height: 250.0,
                width: 250.0,
              )
            ]),
      )),
    ));
  }
}

Every images are displaying great, except ONE: my logo.

My pubspec.yaml :

flutter:
  assets:
    - assets/

I can’t figure why only my logo can’t be displayed.

2

Answers


  1. If you want to display images from assets/images you need to add the full path to pubspec.yaml. The subdirectories are NOT added automatically.

    flutter:
      assets:
        - assets/
        - assets/images/ 
    
    Login or Signup to reply.
  2. Very basic issue, three steps to resolve.

    1 – define asset correctly

    flutter:
      assets:
        - assets/
        - assets/images/ 
    

    2 – stop the application and run flutter clean.

    3 – run flutter pub get.

    now run the app, it will work fine.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search