I’m new to flutter and i’ve a issue.Thinking that I did all the steps correctly, I added a background image, but the emulator shows a black screen instead of the image.
import 'package:flutter/material.dart';
class LoginPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('/assets/images/login_bg.png'),
fit:BoxFit.cover))
,
);
}
}
My code is also very simple. Is it trying to load but taking a long time?
3
Answers
The path to the asset should be without the first slash. So like
Please improve your image path:
to
The path for image should not start with "/"
and also please try to return Scaffold and not container when building a widget
So Your code should be Like