Set Text Widget Vertically Horizontally Center in Flutter iOS Android

In flutter we cannot directly put text widget at the center of a View layout. We have to use Center widget with Center text align property of Text and combination of both of them makes our Text at middle of View. In this tutorial for full explanation i am first creating a Container View with fixed height and set border around view. Then i am putting Center widget in Container and putting Text widget inside it. So in this tutorial we would Set Text Widget Vertically Horizontally Center in Flutter iOS Android App Example.

Contents in this project Set Text Widget Vertically Horizontally Center in Flutter iOS Android Example:

1. Import material.dart package in your app’s main.dart file.

2. Create void main runApp() method and call our MyApp class here.

3. Create our main class named as MyApp extends with State less widget.

4. Create a SafeArea widget in Scaffold widget in Widget build area.

5. Now we would create a Container view widget with fixed height and border, So you all know that how much area our Container is occupying on device screen.

6. Create a Center widget in Container widget and wrap Text widget in Center widget. We would also set text align as TextAlign.center.

7. Complete source code for main.dart file:

Screenshot in Android device:

Set Text Widget Vertically Horizontally Center in Flutter iOS Android

Screenshot in iOS device:

Leave a Reply

Your email address will not be published.