name__
name__

Reputation: 59

No file or variants found for asset: Images/xyz.jpg

I am getting an error that flutter is unable to load my image which is stored in the Images directory.

I checked the indentation for the pubspec.yaml file,

and also checked the similar question for the solution to the error but nothing seems to work.

below are images for the pubspec.yaml file and code.

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.greenAccent,
        body: SafeArea(
          child: Column(
            children: [
              CircleAvatar(
                radius: 50.0,
                backgroundImage: AssetImage('Images/xyz.jpg'),
              )
            ],
          ),
        ),
      ),
    );
  }
}

enter image description here

enter image description here

if you could please let me know what am I doing wrong here, that would be very helpful.

Upvotes: 0

Views: 1300

Answers (3)

Martin Bocarejo
Martin Bocarejo

Reputation: 1

if your yaml file is in the root of the project, you must include the lib directory in the path of the yaml file

assets:

  • lib/Images/xyz.jepg

in you class

placeholder: AssetImage('lib/Images/xyz.jepg'),

Upvotes: 0

name__
name__

Reputation: 59

As mentioned in the comment by Ameer Amjed the problem was not with the indentations or the code , it was the extension used for the image. the correct extension is important here, it was .jpeg.

Upvotes: 0

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14775

Change your pubspecc.yaml file like below hope it help:

flutter:
  assets:
    - Images/
  uses-material-design: true

Upvotes: 1

Related Questions