Repository: flutter
Issue: [proposal] Support multiple TextDirection in Text widget  (ie textDirection per paragraph/line-break)
Labels: c: new feature,framework,f: material design,a: accessibility,a: internationalization,a: typography,c: proposal,team-design,triaged-design

## Current Limitation

All the Text Widgets currently supports one `TextDirection` that applies to the entire text in a multi-paragraph scenario. 

While one can use separate widget for each paragraph, managing them becomes complex and the approach breaks some core features such as selection or editing. 
 
## Use case

In a typical application, when typing or presenting a bidirectional text _(e.g. Arabic + English)_, each paragraph _(i.e. after a line break)_ has its own `TextDirection` based on the first character of the paragraph. Here are two examples:

- Twitter Web Example
<img width="538" alt="Screen Shot 2021-04-05 at 1 53 20 AM" src="https://user-images.githubusercontent.com/46427323/113523718-27d63880-95b2-11eb-887c-1e2a452ffd26.png">

- WhatsApp iOS Example 
![image](https://user-images.githubusercontent.com/46427323/113523724-345a9100-95b2-11eb-8592-0af5c1f34ec4.png)


- This is how it appears in Flutter with `TextDirection.ltr`:

Notice in the last line, the word `English` is misplaced (it should be on the left side since it's the last word in that line). 

<img width="311" alt="Screen Shot 2021-04-05 at 2 38 11 AM" src="https://user-images.githubusercontent.com/46427323/113524540-ffe9d380-95b7-11eb-8430-02dab8d14e03.png">


- This is how it appears in Flutter with `TextDirection.rtl`:

Notice in the third line, the word "عربي" should be on the right side. 

<img width="261" alt="Screen Shot 2021-04-05 at 2 52 50 AM" src="https://user-images.githubusercontent.com/46427323/113524844-1b55de00-95ba-11eb-880d-d16923cfe7fc.png">


If each paragraph has its own `TextDirection`, the word misplacement won't be an issue.

<details><summary>code sample:</summary>

```dart
Text( '''This is an English Text 
هذا نص عربي 
This is English with عربي 
وهذا عربي مع English''',
              textDirection: TextDirection.ltr,
              maxLines: null,
),
```
</details>

## Proposal

I'd like to present two options:  

1- Introduce `TextDirection.auto`:

Since the framework is already aware of LTR and RTL and has a way to determine the text direction based on the given characters, I'd propose to add an `auto` option to `textDirection` that automatically set the `textDirection` for each paragraph based on whether the initial character is LTR or RTL of the given paragraph. For instance:

```dart
TextField(
  textDirection: TextDirection.auto,  // <~~~ proposal 
  textAlign: TextAlign.start,
  maxLines: null,
)
``` 

2- Provide `textDirectionBuilder`:

Another option is to provide a callback that's called for each paragraph/new-line to determine the directionality:

```dart
Text(
  'some English text \n نص عربي',
  maxLines: null, 
  textDirectionBuilder: (String paragraph)  {  // <~ called for each paragraph and called once for a single paragraph. 
     return isLTR(paragraph) ?  TextDirection.ltr : TextDirection.rtl;
   },
 ),
```

note: If the second option is preferred, `textAlignBuilder` per paragraph could be considered as well to provide more control over the text appearance. This is mainly useful for rich text scenarios since both `textDirection` and `textAlign` cannot be configured when building `TextSpan`s.