flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.08k stars 27.21k forks source link

[flutter_markdown] Support RTL #138723

Open mbfakourii opened 10 months ago

mbfakourii commented 10 months ago

Is there an existing issue for this?

Use case

RTL is not supported in flutter_markdown.

Proposal

Github site supports this Feature:

Screenshot from 2023-11-20 17-53-38

But flutter_markdown is not support:

Screenshot from 2023-11-20 18-04-42

Example code:

# Title
This is atest
## Title 2
This is a test

https://github.com

این تست است این تست است

این تست است این تست است
# Title
This is atest

I suggest adding this feature.

huycozy commented 10 months ago

Have you tried using Directionality widget as below? I checked it can make this works as expected.

Directionality(
    textDirection: TextDirection.rtl,
    child: Markdown(
      data: 'مرحبا بالعالم',
    ),
  ),

Screenshot 2023-11-21 at 16 22 54

mbfakourii commented 10 months ago

Have you tried using Directionality widget as below? I checked it can make this works as expected.

Directionality(
    textDirection: TextDirection.rtl,
    child: Markdown(
      data: 'مرحبا بالعالم',
    ),
  ),

The output of this code is as follows:

Directionality(
  textDirection: TextDirection.rtl,
  child: Markdown(
    data: '''
    # Title
    This is atest
    ## Title 2
    This is a test

    https://github.com

    این تست است این تست است

    این تست است این تست است
    # Title
    This is atest''',
  ),
),

Screenshot from 2023-11-21 13-46-57

English sentences are expected to be on the left and Persian on the right!

huycozy commented 10 months ago

Currently, Markdown.data is a String only. This means that there needs to be the ability to automatically detect RTL text in the source string (which seems similar to https://github.com/flutter/flutter/issues/23881).

I'm not sure if it's feasible currently. Labeling the issue for other's ideas.