helpoatmeal
helpoatmeal

Reputation: 45

Why is flutter unable to load asset image?

No errors in the code and as far as I can see the pubspec.yaml file is functional, as it worked before.

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SafeArea(
          child: Column(
            children: [
              Card(
                child: Image.asset('anyaparent.jpeg'),
              ),
            ],
          ),
        ),
      ),
    );

Error text "Unable to load asset"

[1]: https://i.sstatic.net/GeTW2.png The pubspec.yaml file

Upvotes: 1

Views: 284

Answers (2)

Anandh Krishnan
Anandh Krishnan

Reputation: 6022

Check your image path images/anyaparent.jpeg

@override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: SafeArea(
              child: Column(
                children: [
                  Card(
                    child: Image.asset('images/anyaparent.jpeg'),
                  ),
                ],
              ),
            ),
          ),
        );

Upvotes: 0

Wali Khan
Wali Khan

Reputation: 652

try doing like this

Image.asset('images/anyaparent.jpeg'),

Upvotes: 1

Related Questions