0

I am building a flutter app for the first time. I figured out the initial error I was getting with yaml. Now my error is "Error detected in pubspec.yaml: No file or variants found for asset: assets/food.jpg.

Error building assets Finished with error: Gradle task assembleDebug failed with exit code 1"

I created a folder for the picture I am using named it 'assets' the pic is in the folder. yaml is not recognizing the folder. I guess the path is not correct.

flutter:

# The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true

# To add assets to your application, add an assets section, like this:

assets: - assets/food.jpg

The above code is what is on yaml.

Below is the code for android studio:

import 'package:flutter/material.dart';
main() {
 runApp(MyApp());
}
class MyApp extends StatelessWidget {
 build(context) {
 return MaterialApp(
 home: Scaffold(
 appBar: AppBar(
 title: Text('EasyList'),
 ),
 body: Card(child: Column(children: <Widget>[
 Image.asset('assets/food.jpg'),
 Text('Food Paradise')
 ],),),
 ),
 );
 }
}

Below is the error:

Error detected in pubspec.yaml: No file or variants found for asset: assets/food.jpg.

Error building assets Finished with error: Gradle task assembleDebug failed with exit code 1

I am trying to get the pic on to the app. Any suggestions?

asked Mar 31, 2019 at 17:34
0

2 Answers 2

1

Make sure pubspec.yaml is properly indented & food.jpg image file is added in assets directory.

flutter:
 uses-material-design: true
 assets:
 - assets/food.jpg

Also make sure assets directory is created at root of project.

- app/
 - android/
 - assets/
 - lib/
 - pubspec.yaml
 - other directories/files
answered Mar 31, 2019 at 17:41
Sign up to request clarification or add additional context in comments.

2 Comments

Rename food (2).jpg to food.jpg and move it inside assets/ directory
Got it Thanks! I suspected that I needed to remove (2) in the assets folder, but I wasn't sure. Thanks for that!
-1

Below is how I have my 'assets' folder on flutter. I have the assets folder open. Is that correct?

flutter_practice
.idea
android
assets
food (2).jpg
gradle
ios
lib
test
.gitignore
.metadata
.packages
build.gradle
flutter_practice.iml
gradlew
gradlew.bat
local.properties
pubspec.lock
pubspec.yaml
README.md
answered Mar 31, 2019 at 18:17

1 Comment

Rename food (2).jpg to food.jpg and move it inside assets/ directory. Instead of posting answer, you can edit your own post.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.