asjqkkkk / markdown_widget

📖Rendering markdown by flutter!Welcome for pr and issue.
MIT License
321 stars 93 forks source link

MarkdownBlock incorrect behaviour inside CupertinoAlertDialog #147

Closed Time2HackJS closed 9 months ago

Time2HackJS commented 9 months ago

Hi, i'm using MarkdownBlock inside CupertinoAlertDialog and getting unusual behaviour of text inside unordered list elements.

test

There's no problem in regular alert dialog, but i need to align text properly exactly in cupertino alert dialog.

Here's the code i'm using.

const String checkText = '''
## Hello:
- 1
- 2
- 3
- This is a very long test text which i want to show you
I'm sad :(
''';

class TextMarkdownDialog extends StatelessWidget {
  final void Function(String url)? onOpenUrl;

  const TextMarkdownDialog({
    super.key,
    required this.onOpenUrl,
  });

  @override
  Widget build(BuildContext context) {
    return CupertinoAlertDialog(
      content: SingleChildScrollView(
        child: MarkdownBlock(
          data: checkText,
          config: MarkdownConfig(
            configs: [
              if (onOpenUrl != null)
                LinkConfig(
                  onTap: (url) => onOpenUrl?.call(url),
                ),
            ],
          ),
        ),
      ),
    );
  }
}
asjqkkkk commented 9 months ago

Hi @Time2HackJS , do not use CupertinoAlertDialog, because it will center the text

image

CupertinoAlertDialog(
          content: SingleChildScrollView(
            child: Text(checkText),
          ),
        )

image

asjqkkkk commented 9 months ago

@Time2HackJS I found a way to solve this issue, just need to set the TextAlign to the rich text, wait me to fix it

Time2HackJS commented 9 months ago

@Time2HackJS I found a way to solve this issue, just need to set the TextAlign to the rich text, wait me to fix it

Any updates on this?

asjqkkkk commented 9 months ago

Hi @Time2HackJS , you can use markdown_widget 2.3.2+3 like this:

...
MarkdownBlock(
          data: checkText,
          config: MarkdownConfig(configs: [...]),
          generator: MarkdownGenerator(richTextBuilder: (span) {
            return Text.rich(span, textAlign: TextAlign.start);
          }),
        )
...
image
Time2HackJS commented 9 months ago

@asjqkkkk thanks a lot!