Meeting the recruitment challenges of the European Medicines Agency move to Amsterdam

The European Medicines Agency (EMA) will leave London for Amsterdam on March 30th, 2019 at the latest. We spoke to Dutch industry insiders Aarnoud Overkamp and Annemiek Verkamman for their view on…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Set a shared background in your Flutter app

In the last months I started building apps for my clients in Flutter, I have to say that for the time being I’m in love with this library that Google has built. But I was having an hard time figuring out how to set a background that would persint in various pages of my app.
Keep reading to learn how I did it in my latest apps.

Flutter is made of Widgets, these are like lego bricks, you put one above each other to build your unique app interface.
The basic widget of Flutter is MaterialApp if your using Material design, this widget tells how to render the App on the phones and which pages you can navigate to, if you use named navigator (highly recommended).

Another basic widget that you’ll find in every Flutter application is Scaffold, it lets you put your widgets on the screen, and it has natively implementations of AppBars, BottomNavigationsAppBars and Drawers. That’s really something awesome.
So lets keep it up, each Scaffold has one required field: body, it’s a generic Widget that’ll be put at the top left on your screen if you don’t tell nothing to Flutter.

Here’s an example:

This basically tells to render a Text on the top left of your screen. See it yourself:

That been said it’s time to pass to the argument of this post, how can we use the informations we have to share an image as background throughout our application?
The answer is quite simple really, all we have to do is use another basic flutter’s widget: Stack.

What Stack allows us to do is to simply put widgets on top of each other.
There are three ways to render our widgets in flutter: Row, Column and Stack, but that’s not the argument of this post and the informations about these widget can be easily seen on flutter documentation.

What can we do now is use the Scaffold widget to render a body with a Stack by default, and the stack children being an Image widget and a Container widget.
The Image widget will render an image which will cover all of our phone’s screen and the Container will take all the screen’s space to render other widgets on top of ou image, using it as a background. Here’s the code:

Here’s the result:

What do you think of this approach?
Let me know in the comments! 😉

Add a comment

Related posts:

How to BUCK Everything

150 years ago humanity witnessed the emergence of a new economic model. The combination of interchangeable parts, assembly line, the telegram, new kinds of financing created the ‘industrial Trust.’…

you are enough

This is a reminder that you are enough. That whatever you did today and however you did it is just fine, in fact, it’s great. It’s okay. It’s just is. I’m not creative one hundred percent of the…

Why the Return of Star Wars Sequel Trilogy Characters Is Inevitable

While Disney Plus Day did not bring any news for a Star Wars Sequel Trilogy show, Kathleen Kennedy recently left the door open for the Sequel Trilogy characters return: Kennedy can tease this because…