简体   繁体   中英

How to format text to be displayed in Flutter

I want to display following text on screen with superscripts being displayed properly. How to do that in flutter?

在此处输入图片说明

You can use RichText and Unicode

  final defaultStyle = TextStyle(color: Colors.black);
  final blueStyle = TextStyle(color: Colors.blue);


        return Center(
              child: RichText(
                text: TextSpan(
                    text: "c. 10\u{207B}\u{2076} seconds: ",
                    style: defaultStyle,
                    children: [
                      TextSpan(text: "Hadron epoch ", style: blueStyle, children: [
                        TextSpan(
                          style: defaultStyle,
                          text:
                              "begins: As the universe cools to about 10\u{00B9}\u{2070} kelvin,",
                        ),
                      ])
                    ]),
              ),
            );

More info: https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM