Home > database >  Only one image can't displays image asset - Flutter
Only one image can't displays image asset - Flutter

Time:11-19

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.

CodePudding user response:

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.

CodePudding user response:

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/ 
  • Related