1

I don't know what is happening but I m not able to insert image through Asset image using pubspec.yaml file.Pub get is not loading dependencies.

Kindly please help me out. I am running a flutter project.

Here is the code of pubspec.yaml file

name: mi_card_flutter
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    images/khushi.jpg

Error is :

Error detected in pubspec.yaml: Expected "assets" to be a list, but got images/ (String). Please correct the pubspec.yaml file at C:\Users\khush\AndroidStudioProjects\mi_card_flutter\pubspec.yaml Process finished with exit code 1

enter image description here

0

3 Answers 3

1

So finally after spending 3 hours on this doubt.I got the answer.What I did is ran pub get from terminal and it worked!

Sign up to request clarification or add additional context in comments.

Comments

0

Your indentation of the images/kushi.jpg is wrong.

Try the code below: Works well:

name: mi_card_flutter
description: A new Flutter application.

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    -images/

I hope this helps.

5 Comments

Error detected in pubspec.yaml: Expected "assets" to be a list, but got -images/khushi.jpg (String). Please correct the pubspec.yaml file at C:\Users\khush\AndroidStudioProjects\mi_card_flutter\pubspec.yaml Process finished with exit code 1 it is showing this now...basically pub get is not working
Expected "assets" to be a list, but got -assests/images/ (String). what does this mean?
Expected "assets" to be a list, but got -assests/images/ (String).
Post a screenshot of the directory your image is @KhushiZawar
Also I have added the screenshot
0

Please write in assets in pubspec.yaml file as shown below

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    images/khushi.jpg

instead of this

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true
  assets:
    - images/khushi.jpg

7 Comments

C:\Users\khush\Downloads\flutter_windows_v1.12.13+hotfix.9-stable\flutter\bin\flutter.bat --no-color pub get Error detected in pubspec.yaml: Expected "assets" to be a list, but got images/khushi.jpg (String). Please correct the pubspec.yaml file at C:\Users\khush\AndroidStudioProjects\trial\pubspec.yaml Again same thing!
@KhushiZawar please also add your class file code where r u using this image?
Okay so that error got solved,now showing this,pub get is not loading C:\Users\khush\Downloads\flutter_windows_v1.12.13+hotfix.9-stable\flutter\bin\flutter.bat --no-color pub get Running "flutter pub get" in mi_card_flutter... 1.1s Process finished with exit code 0
main dart code: import 'package:flutter/cupertino.dart'import 'package:flutter/material.dart'; void main() { runApp(Myapp()); } class Myapp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( backgroundColor: Colors.black, body: SafeArea( child: Column( children: <Widget>[ CircleAvatar( radius: 50.0, backgroundImage: AssetImage('images/khushi.jpg')), ], ), ), ), ); } }
@KhushiZawar use CircleAvatar( radius: 50.0, backgroundImage: AssetImage('assets/images/khushi.jpg'))
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.