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?
2 Answers 2
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
2 Comments
food (2).jpg to food.jpg and move it inside assets/ directoryBelow 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
1 Comment
food (2).jpg to food.jpg and move it inside assets/ directory. Instead of posting answer, you can edit your own post.