Search code examples
flutterflutter-web

How to display exponent string in Flutter?


I'm struggling to display this type of character (the mini 2) on a Flutter Web screen:
enter image description here

I've been looking around but without any good results. Is there currently any existing package or method to display this cleanly?


Solution

  • You can make use of offset property in WidgetSpan.

    RichText(
      text: TextSpan(children: [
        TextSpan(text: '90 m',),
           WidgetSpan(
              child: Transform.translate(
                offset: const Offset(2, -4),
                 child: Text(
                        '2',
                       //superscript is usually smaller in size
                       textScaleFactor: 0.7,
                  ),
              ),
            )
      ]),
    )
    

    or use the Unicode of exponent 2

    Text("90 m\u00B2"),