Search code examples
iosfluttertextword-wrap

Is there a corresponding mode in Flutter as NSLineBreakMode.byWordWrapping/NSLineBreakByWordWrapping in iOS?


When we use Flutter Text, if we give it a long text:

"The quickbrownfoxjumpsoverthelazydog."

It appears as:

The
quickbrownfoxjumpsoverthelaz //assume the container width is just 28 characters
ydog

But what i want is:

The quickbrownfoxjumpsoverth
elazydog

That is, I want it to wrap by "character" other than "words".

In iOS, we could use NSLineBreakMode.byWordWrapping/NSLineBreakByWordWrapping.

But how could we do it in Flutter?


Solution

  • There is no function of this type in flutter however you can use this quick solution for the string if you already know how many characters you have to print in one row.

     String text = "The quickbrownfoxjumpsoverthelazydog";
     String finalText = "";
     int lengthOfText = text.length;
        finalText = lengthOfText > 28 ? text.substring(0, 28) 
         + "\n" + 
         text.substring(28, lengthOfText) : text ;
    
    print(finalText);