Reputation: 59
I am just trying to upload image to the scaffold and I got this error:
The flutter tool cannot access the file or directory.
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
Though I have checked my environmental variables and The path to the bin folder of flutter is made correctly. While uploading image my pubspec.yaml
looks as:
assets:
- images/image1.jpg
- images/image2.jpg
Code:
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image'),
),
body: Center(
image: AssetImage('images/image1.jpg'),
height: 70,
),
);
}
}
Upvotes: 0
Views: 615
Reputation: 17772
A center image can take image.asset. You can try this format. Also make sure you have an asset folder in the root directory. Inside the asset folder add images. Update the same in pubspec.yaml. Restart the application and it should work as expected.
body: Center(
child: Image.asset('assets/images/image1.jpg', height : 70),
),
Upvotes: 1