Hi in the below code Image is not displaying from assets folder. I added pubspec also still image is not displaying .
Can any one help me I am new to flutter
import 'dart:async';
import 'package:flutter/material.dart';
import 'login_screen.dart';
class SplashScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
Timer(Duration(seconds: 5), () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(
builder: (context) => LoginScreen(
name: "Sai Gopi",
)),
(route) => false);
});
return Scaffold(
backgroundColor: const Color(0xFF0769AA),
body: Center(
child: Image.asset('assets/images/genvcarelogo.png'),
),
);
}
}
pubspec.yml:
assets:
- images/genvcarelogo.png
CodePudding user response:
You don't need to specify all the images in pubspec.yaml, just add the root folder containing your all the images like this:
assets:
- assets/images/
And use like you already using it:
Image.asset('assets/images/genvcarelogo.png')
CodePudding user response:
The location of the image in pubspec.yaml
and in code is differing and the indentation in your pubspec is wrong. If the path in the code is right then update your pubspec to this,
assets:
- assets/images/genvcarelogo.png
(Make sure there are only two spaces in the second line.)
CodePudding user response:
if you've made sure everything is correct in your pubspec.yaml
(i.e image location is correct and indentations are right) then all you need to do is stop the application completely and rerun it.