LWB
LWB

Reputation: 514

Flutter Image not being displayed

So I'm trying to make a page with an image background and this is my code:

body: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage("loginBackground"),
          ),
        )
      ),

However when I run this it opens a new editor with some of Flutters code, and a line is highlighted yellow, which I think means a breakpoint (correct me if I'm wrong). The file name is 'image_provider.dart' and this is the relevant code (I have indicated the highlighted line):

@protected
  Future<ui.Codec> _loadAsync(AssetBundleImageKey key, DecoderCallback decode) async {
    ByteData? data;
    // Hot reload/restart could change whether an asset bundle or key in a
    // bundle are available, or if it is a network backed bundle.
    try {
      data = await key.bundle.load(key.name);
    } on FlutterError {
      PaintingBinding.instance!.imageCache!.evict(key);


      rethrow;          // THIS IS THE HIGHLIGHTED LINE

    }
    // `key.bundle.load` has a non-nullable return type, but might be null when
    // running with weak checking, so we need to null check it anyway (and
    // ignore the warning that the null-handling logic is dead code).
    if (data == null) { // ignore: dead_code
      PaintingBinding.instance!.imageCache!.evict(key);
      throw StateError('Unable to read data');
    }
    return await decode(data.buffer.asUint8List());
  }
}

I don't know what this means, so any help would be really appreciated. This is the image (Scroll):

(sorry for it being so big) If you need more details just comment :)

Upvotes: 3

Views: 9997

Answers (2)

Nathan Miranda
Nathan Miranda

Reputation: 11

try AssetImage('assets/loginBackground.png'), assuming you've created a folder assets in your project with all your images. You also need to specify

assets:

- assets/

in your pubspec.yaml file

Upvotes: 1

Fahmi Sawalha
Fahmi Sawalha

Reputation: 622

in the assetImage the synatx is usually like this :

image: AssetImage("images/loginBackground.png")

also if you didn't enable your assets in pubspec.yaml by doing this in your assets section :

 assets:
    - images/

also a little bit of error code will help

Upvotes: 3

Related Questions