On flutter, when trying to upload an image on a window it says "unable to load asset: the asset does not exist".
The image is kept in a file named "assets" kept in the same folder as the rest of the program.
Here is my code
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(
home: Home()
));
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('App Title'),
titleTextStyle: TextStyle (
fontSize: 25.0,
fontWeight: FontWeight.bold,
color: const Color.fromARGB(255, 248, 245, 245),
fontFamily: 'Ubuntu',
) ,
centerTitle: true,
backgroundColor: Color.fromARGB(255, 235, 8, 4),
),
body: Center(
child: Image(
image: AssetImage('assets/hotcoffee.jpg'),
)
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: Text('click'),
backgroundColor: Color.fromARGB(255, 235, 8, 4),
),
);
}
}
here is my pubspec.yaml file:
name: flutter_application_2
escription: "A new Flutter project."
publish_to: 'none'
version: 0.1.0
environment:
sdk: '>=3.2.5 <4.0.0'
dependencies:
flutter:
sdk: flutter
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
uses-material-design: true
fonts:
- family: Ubuntu
fonts:
- asset: assets/fonts/Ubuntu-Regular.ttf
assets:
- assets\hotcoffee.jpg
Tried multiple solutions. Nothing has worked.
Sorry for the unnecessary add on. Stack Overflow won't let me post the question unless I add more details.
I think that you did not add the right path for the image. It should be
With the "/" instead of the backslashe. Also considering your app will have multiple assets it is better to reference the assets folder and not the asset itself.
If I am wrong try to run flutter pub get or flutter clean?