0

I am using following code to display image as splash screen :

class WelcomeWidget extends StatefulWidget { static const routeName = '/welcome_page'; @override _WelcomeWidgetState createState() => _WelcomeWidgetState(); } class _WelcomeWidgetState extends State<WelcomeWidget> { @override void initState() { super.initState(); Timer( Duration(seconds: 10), () => Navigator.of(context).pushReplacement( MaterialPageRoute( builder: (_) => LowerStripWidget(), ), ), ); } @override Widget build(BuildContext context) { return Scaffold( body: Container( child:Center( child: Image.asset('assets/images/Splash-Screen-bg.png'), ), width: double.infinity, ), ); } } 

This shows the image but does not stretch image to fill the white space. How we can do that in flutter?

Here is the current screen:

enter image description here

4
  • Use the fit property of the Image.asset widget and set it to BoxFit.cover. Commented Aug 5, 2020 at 9:29
  • Thanks @TimilehinJegede. How we can also set the fit along with image path? Commented Aug 5, 2020 at 9:39
  • 1
    Image.asset('assets/images/Splash-Screen-bg.png',fit: BoxFit.cover,), Commented Aug 5, 2020 at 9:40
  • 1
    Happy Fluttering :) Commented Aug 5, 2020 at 9:46

1 Answer 1

1

You can use the fit property of the Image widget to determine how to inscribe the image into the space allocated during layout.

I added an example using your code:

Image.asset( 'assets/images/Splash-Screen-bg.png', // set the fit property to cover it: BoxFit.cover, // new line ), 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.