Flutter TextAlign Property Explained Example Tutorial-How It Works

In Flutter we have seen most of time TextAlign property of Text widget dose not works because some of developers don’t know its working environment. TextAlign property works inside Container widget which has increase width and height so the Text widget can move in all directions according to given alignment. So in this tutorial we would learn about Flutter TextAlign Property Explained Example Tutorial – How It Works in iOS and Android devices.

Contents in this project Flutter TextAlign Property Explained Example Tutorial – How It Works in iOS & Android Devices:

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

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

3. Creating our main MyApp class extends with StatelessWidget.

4. Creating Widget Build area in MyApp class. Now we would make Scaffold widget.

5. Creating Container widget and then we would make Text widget as Child of Container widget. We are using textAlign property on Text widget here to set alignment of Text widget.

  1. TextAlign.center : Align the Text widget text in Container widget if Free space is available on screen.
  2. TextAlign.end : Align the Text Widget on the trailing edge of the Container widget.
  3. TextAlign.justify : Stretch lines of text that end with a soft line break and manage all the Text.
  4. TextAlign.left : Align the Text widget on the Left side of Container widget.
  5. TextAlign.right : Align the Text widget on Right side of Container widget.
  6. TextAlign.start : Align the Text widget on the Leading Edge of Container widget.

6. Complete source code for main.dart file:

Screenshot:

Flutter TextAlign Property Explained Example Tutorial - How It Works

One Comment

  1. Great post.

Leave a Reply

Your email address will not be published.