flutterflutter-layoutpubspec

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.


Solution

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

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