Deep dive into the Container widget in flutter
Hi, Flutter developers in this blog we shall discuss the container widget. It is one of the most used widgets in flutter. It provides us with a lot of properties to build a customized widget.
1. Color property: The container widget provides us with a colors property to pass the color.
Container(
color: Colors.blue,
),
2. Dimensions: The container provides height and width properties to set the dimensions of the container. They can be accessed using height, and width properties. Both the property takes double values.
Container(
color: Colors.blue,
width: 200,
height: 400,
),
Passing responsive height and width using media query:
MediaQuery is a class that enables us to query the current size of the screen.
Let’s define the methods to get the size, height, and width using MediaQuery.
MediaQueryData mediaQueryData(BuildContext context) {
return MediaQuery.of(context);
}
Size size(BuildContext buildContext) {
return mediaQueryData(buildContext).size;
} double width(BuildContext buildContext) {
return size(buildContext).width;
}
double height(BuildContext buildContext) {…