AssetImage is not displaying image in flutter app

前端 未结 9 557
野趣味
野趣味 2021-01-13 00:33

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         


        
相关标签:
9条回答
  • 2021-01-13 00:39

    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

    0 讨论(0)
  • 2021-01-13 00:39

    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,
            ],
          )
        );
      }
    } 
    
    0 讨论(0)
  • 2021-01-13 00:39

    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
    
    0 讨论(0)
  • 2021-01-13 00:42

    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'),
     ),
    
    0 讨论(0)
  • 2021-01-13 00:46

    I just replaced

    Image.asset("assets\images\_Lightweight.jpeg"),
    

    To

    Image.asset("assets/images/_Lightweight.jpeg"),
    
    0 讨论(0)
  • 2021-01-13 00:51
    1. Flutter doesn't support jpg files.
    2. Try the complete path of the file with '/'(forward slash).
    0 讨论(0)
提交回复
热议问题