Erez
Erez

Reputation: 1953

Showing a number as a power or another number in flutter

I dont have code to show because i couldn't find any solution for this.

Does anyone knows how to show in flutter a power of number like this:

14ug/m3

The 3 in the example meeds to me small and above the m, like in hand writing

I know it can be done with a row of containers and text elements, but asking if there is a way to do it better? If flutter have a build-in mechanism for this?

Upvotes: 0

Views: 1429

Answers (1)

Sukhi
Sukhi

Reputation: 14195

It's called super-script and you can use unicode for it. For example, the 3 in m³ can be written as '\u2083'

Example, the following code produces this :

enter image description here

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,",
                        ),
                      ])
                    ]),
                  ),
              );

The code snippet is taken from here.

Upvotes: 3

Related Questions