This code defines a Flutter app with a single screen built using the StackExample class. The MyApp class extends StatelessWidget and overrides its build method to return a MaterialApp widget. The MaterialApp widget is the root widget of a Flutter app that uses material design. It has several properties:
title: This is a string that is displayed in the app bar.
theme: This is a ThemeData object that defines the theme of the app.
home: This is the default route of the app and is typically a widget that represents the home screen.
In this case, the home property is set to a StackExample widget, which is a custom widget displaying a Stack widget with some widgets as its children.
When the app runs, the MyApp widget’s build method will be called, returning a MaterialApp widget that displays the StackExample widget as the home screen.
Here, we take our three Container widgets and wrap them inside the Stack widget. The first Container widget will act as a base to position the other two Container widgets.
We can experiment with it by adding more containers with different positions in the stack and see the change. We can also use the Positioned widget and the Align widget.
The Positioned widget uses the offset in pixels to arrange its child, whereas the Align uses a percent of the parent’s size to arrange its child widget.