Displaying the image in Flutter works once

flutter network image
flutter image.network not working
flutter network image placeholder
flutter display image
flutter image package
flutter image widget
flutter download image from url
flutter rootbundle

I have a problem with flutter Image.assets , when I set image in the file and set it in the assest like that :

flutter: uses-material-design: true assets: - images/facebook.png

and when I put it in my code :

Center(
    child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Image.asset(
          "images/facebook.png"

        ),
        Text(
          '$_counter',
          style: Theme.of(context).textTheme.display1,
        ),
      ],
    ),
  ),

and run it , it works well but the second time I run code , it not displaying and this the error I get :

I/flutter ( 4784): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════ I/flutter ( 4784): The following assertion was thrown while resolving an image: I/flutter ( 4784): Unable to load asset: AssetManifest.json . . . I/flutter ( 4784): #381 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:969:5) I/flutter ( 4784):

382 RenderObjectToWidgetAdapter.attachToRenderTree. (package:flutter/src/widgets/binding.dart:915:17) I/flutter (

4784): #383 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2328:19) I/flutter ( 4784): #384 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:914:13) I/flutter ( 4784):

385 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:795:7) I/flutter ( 4784):
386 runApp (package:flutter/src/widgets/binding.dart:845:7) I/flutter ( 4784): #387 main (package:flutter_app/main.dart:4:16)

I/flutter ( 4784): #388 _runMainZoned.. (dart:ui/hooks.dart:229:25) I/flutter ( 4784): #393 _runMainZoned. (dart:ui/hooks.dart:221:5) I/flutter ( 4784): #394 _startIsolate. (dart:isolate-patch/isolate_patch.dart:305:19) I/flutter ( 4784): #395 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12) I/flutter ( 4784): (elided 7 frames from package dart:async) I/flutter ( 4784): Image provider: AssetImage(bundle: null, name: "images/facebook.png") I/flutter ( 4784): Image configuration: ImageConfiguration(bundle: PlatformAssetBundle#b5447(), devicePixelRatio: 1.5, I/flutter ( 4784): locale: en_US, textDirection: TextDirection.ltr, platform: android) I/flutter ( 4784): ════════════════════════════════════════════════════════════════════════════════════════════════════

check this

assets:
   - images/facebook.png

make sure you have same spaces exactly like this

flutter:

[2 whitespaces or 1 tab]assets:
[4 whitespaces or 2 tabs]- images/facebook.png

every space matters

Displaying the image in Flutter works once – Onooks, and run it , it works well but the second time I run code , it not displaying and this the error I get : I/flutter ( 4784): ══╡ EXCEPTION CAUGHT� The images that will be displayed must be stored in particular folders. While in Android the images must be stored in res/drawable folder by default, in Flutter you can define where the images are stored. What you need to do is adding a list of image paths or a list of directories that contain images in pubspec.yaml file. Each paths must be relative to the application's root directory.

my code:

import 'package:flutter/material.dart';
import 'dart:io';
import 'package:image_picker/image_picker.dart';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'myApp'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  File imageFile;
  int _counter = 0;
  Color red = Colors.red;
   _incrementCounter() async{
     var picture = await ImagePicker.pickImage(source: ImageSource.camera);

    this.setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      imageFile = picture;
      _counter++;
      print("work");
    });
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Image.asset(
              "images/facebook.png"

            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

my pubspec.yaml:

name: flutter_app
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  image_picker:


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter


# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
  uses-material-design: true
  assets:
   - images/

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

Display images from the internet, To work with images from a URL, use the Image.network() constructor. content_copy One useful thing about the Image widget: It supports animated gifs. Once the image has been added to the assets folder, the pubsec.yaml file needs to be edited to incorporate the image. Here is code for a simple app that uses Image.network to display an image

Be sure you are using 2 or 4 spaces (avoid tabs) as indentation in your pubspec.yaml.

Your pubspec.yaml must be like this

flutter:
  uses-material-design: true
  assets:
    - images/facebook.png

not like this

flutter:
  uses-material-design: true
  assets:
      - images/facebook.png # error

or like this

flutter:
  uses-material-design: true
  assets:
  - images/facebook.png # also error

run flutter clean flutter pub get in your terminal

Fade in images with a placeholder, When displaying images using the default Image widget, you might notice they simply FadeInImage works with images of any type: in-memory, local assets,� The Image Widget also provides several constructors to display different types of images for convenience. In this example, use the Image.network constructor to display an image from the internet.

1).create folder named images 2).add image that you want to add 3).add in pubspec like this assets: - images/xyz.png 4)click on Package get 5) run the app(first kill app and run).

Adding assets and images, How to use images (and other assets) in your Flutter app. different versions of an asset that might be displayed in different contexts. AssetImage understands how to map a logical requested asset onto one that In order for this mapping to work, assets should be arranged according to a particular directory structure:. Flutter apps can include both code and assets (sometimes called resources). An asset is a file that is bundled and deployed with your app, and is accessible at runtime. Common types of assets include static data (for example, JSON files), configuration files, icons, and images (JPEG, WebP, GIF, animated WebP/GIF, PNG, BMP, and W

This issue occurred to me recently. As @Mohamed Adel answered, you have to keep the proper whitespaces. You can also include an entire folder eg: images

flutter:

[2 whitespaces]assets:
[4 whitespaces]- images/

If the images folder has subfolders eg: images/products/

flutter:

[2 whitespaces]assets:
[4 whitespaces]- images/products

In pubspec.yaml it's always safe to use whitespaces than tabs

Take a picture using the camera, Display the picture with an Image widget; Complete example. Many apps require working with the device's cameras to take photos and videos. Once you have a camera, use the following steps to create and initialize a CameraController . Its a known issue for Flutter Camera Plugin will rotate the images 90 / 270 degree when uploading it to server or displaying it with a Image widget, like this: The cause of the issue is due to EXIF meta embeded into the image itself with the orientation parameter, for servers, just make sure that it handle EXIF once the

Image (Flutter Widget of the Week), Need your app to display images? Flutter has you covered! Use the Image widget to render Duration: 2:16 Posted: Jan 13, 2020 Displaying images is fundamental for most mobile apps. Flutter provides the Image widget to display different types of images. To work with images from a URL, use the Image.network () constructor.

Flutter Tutorial for Beginners #8 - Images & Assets, Hey ninjas, in this Flutter tutorial I'll show you how to work with images. Was facing Duration: 6:53 Posted: Aug 28, 2019 Flutter provides ListView.builder which can be used to generate dynamic content from external sources.. In this tutorial, we will create a button widget, and when the button is pressed, it will add an item to the List and display that List on the mobile screen.

How to include images in your Flutter app - Suragch, I originally wrote this answer when I was learning how to add images to my Flutter project. Check out the documentation, but in case you need a� The flutter image download and display development tutorial describes, how to download a remote image and then display it in the flutter application. This flutter tutorial is part of a series of episodes describing how to switch between widgets. There is an equivalent Kotlin on Android series here.

Comments
  • the Image is display well and I have't error the fist time I run the code , but then when I click on reload button the image is disappear
  • could you show me full code of pubspec.yaml and full code of the image
  • I realize this, but the problem is : the Image is display well and I have't error the fist time I run the code , but then when I click on reload button the image is disappear...
  • try to delete and recreate your images/ folder