skip to Main Content

In flutter, Is there any way to set textAlign for each line separately?
I want something like telegram app text input:

enter image description here

In telegram, if the line starts with a rtl language, text align is right otherwise it is left.

I try these ways so far:

1- auto_direction package

2- Checking text with intl.Bidi.detectRtlDirectionality and set textAlign dynamically.

But all of these ways sets the textAlign for all lines, I want to set it separately for each line.

2

Answers


  1. Wrap each line with align widget separately and give alignment property as per your requirement

    Login or Signup to reply.
  2. Detect language and change textDirection and textAlign properly.
    You can detect languages with RegExp class.

      var persian = RegExp(r'[u0600-u06FF]');
      var english = RegExp(r'[a-zA-Z]');
      var arabic = RegExp(r'[u0750-u077F]');
      var chinese = RegExp(r'[u4E00-u9FFF]');
      var japanese = RegExp(r'[u3040-u309F]');
      var korean = RegExp(r'[uAC00-uD7AF]');
    

    Use onChanged call back property of TextField to detect language.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search