Play Flutter Quiz. Click here .

How to add a Background Images to the Screen?

This Article is posted by seven.srikanth@gmail.com at 25-12-2018 21:09:20



You can do this by using DecoratedBox Widget. The example code below.

Note: You can observe that Child of DecoratedBox doesn't have any code. If you are trying this example, you need to add image to your project and also add some widgets to Child within DecoaratedBox.

import 'package:flutter/material.dart';

void main() => runApp(BackgroundScreen());

class BackgroundScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Backgroun Image',
home: Scaffold(
body: DecoratedBox(
position: DecorationPosition.background,
decoration: BoxDecoration(
color: Colors.red,
image: DecorationImage(
image: AssetImage('Images/Landscape.jpg'),
fit: BoxFit.cover),
),
child:
//Rest of the widgets go here..
)
),
);
}
}


Thanks,
Srikanth

Tags: How to add a Background Images to the Screen?




0 Comments
Login to comment.

Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.







© 2018 - Fluttercentral | Email to me - Seven.srikanth@gmail.com

Terms | Privacy