Home > Net >  image is not loading in flutter
image is not loading in flutter

Time:04-26

this is my pubspec file this is happening every time I want to use the assets image. i use every combination for in asset

 name: profile1
 description: A new Flutter project.
 publish_to: 'none'
 version: 1.0.0 1
environment:
 sdk: ">=2.16.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
 cupertino_icons: ^1.0.2
dev_dependencies:
 flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flutter:
uses-material-design: true
    assets:
 - assets/*

[enter image description here][1]
 [1]: https://i.stack.imgur.com/EJ75N.png

the error is in my pubspec file I cant use my asset images

 Error on line 61, column 4: Expected a key while parsing a block mapping.

      ╷
   61 │    assets:
      │    ^
      ╵

 Please correct the pubspec.yaml file at 
 C:\Users\Akshay\AndroidStudioProjects\profile1\pubspec.yaml
        Process finished with exit code 1

dart code go to the image part

        import 'package:flutter/material.dart';

        void main() => runApp(MaterialApp(
              home: profile(),
            ));

        class profile extends StatelessWidget {
          const profile({Key? key}) : super(key: key);

          @override
          Widget build(BuildContext context) {
            return Scaffold(
              appBar: AppBar(
                backgroundColor: Colors.black,
    title: Text('profile'),
  ),
  body: Padding(
    padding: EdgeInsets.fromLTRB(19, 15, 0, 0),
    child: Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children:  [
         Center(

using image in image asset Image but the error is in the pubspec file. i use various methods in dart that is not working

           child: CircleAvatar(
             backgroundImage: new AssetImage("assets/img1.jpeg"),
             // backgroundColor: Colors.cyanAccent,
            radius: 70,
        ),
         ),
        
                ),
              ),
              backgroundColor: Color.fromARGB(255, 26, 26, 26),
            );
         }
        }

CodePudding user response:

The pubspec.yaml is indentation sensitive.

assets must be without any indentation at the start of the line. The individual asset entries are one tab level deeper in.

CodePudding user response:

Pubspec.yaml is not set properly.

You should make the asset part as follows :

This is just an example. If you want, you can also export the whole folder as just lib/img/ . The important thing here is the alignment of the codes.

enter image description here

  • Related