Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I justify text with Flutter markdown?

I started using flutter markdown, however I'd like to justify the content, and I couldn't until now.

I tried using a Center and Alignment but didn't work.

import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';

class OutsideBankHourDescription extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    String text =
        "Antecipações em __horários__ bancários acontecem em 1h na média. __Fora do horário bancário__ o saldo estará em sua conta __no dia seguinte.__";

    return Expanded(
      child: Container(
        alignment: Alignment.center,
        child: Markdown(
          styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)),
          data: text,
        ),
      ),
    );
  }
}
like image 417
Felipe Augusto Avatar asked Feb 07 '19 18:02

Felipe Augusto


People also ask

How do you justify Center text in flutter?

To center align the text in a Text widget, provide textAlign property with value TextAlign. center .

How do you align paragraph text in flutter?

How do you align paragraph text in Flutter? textAlign: Flutter facilitates the alignment of text horizontally inside its parent widget's boundary using textAlign property. textDirection: textDirection is used to specify the direction of the text inside a Text Widget say ltr (left-to-right) or rtl (right to left).


1 Answers

It's not available for now to change text alignment in flutter_markdown 0.2.0. You must contact the authors of this plugin to request this feature.

But if you need fast fix, you can add textAlign: TextAlign.center attribute in source code of this file: https://github.com/flutter/flutter_markdown/blob/master/lib/src/builder.dart

Line of code: 345

mergedTexts.add(new RichText(text: mergedSpan, textAlign: TextAlign.center));

Result:

flutter_markdown alignment center

For more elegant way you must clone git repository of this plugin, attach to your project directly and work to add text alignment feature on your own.

like image 94
Maxim Milyutin Avatar answered Oct 25 '22 00:10

Maxim Milyutin