3

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

enter image description here

Prasanth Kanna
  • 1,961
  • 4
  • 18
  • 25
  • [Relevant github issue](https://github.com/flutter/flutter/issues/10906) which says you might be able to use unicode characters to achieve this. – soupjake Dec 19 '18 at 14:36

1 Answers1

6

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

diegoveloper
  • 93,875
  • 20
  • 236
  • 194