4

I want to create a superscript text like 2^4 then how can I do this in the flutter. If someone knows please let me know.

Ravi
  • 912
  • 1
  • 12
  • 17
  • 1
    That's currently not directly supported by Flutter. https://github.com/flutter/flutter/issues/224, https://github.com/flutter/flutter/issues/12675. You would need to position text spans yourself – Günter Zöchbauer Jan 04 '19 at 07:18

3 Answers3

1

To answer your question in one liner

final String twoRaisedToFour = '2\u2074';

To know more about such unicodes refer to following answer unicode list

If this helps do accept the answer. Thank you :)

Swapnil Kadam
  • 4,075
  • 5
  • 29
  • 35
  • This is in fact the official Flutter answer to this question: https://github.com/flutter/flutter/issues/10906#issuecomment-385723664 (There's also https://github.com/flutter/flutter/issues/224 where doing superscript/subscript in general is one of a long list of features they might add someday, but Unicode is the official answer until then.) – Greg Price Jan 24 '21 at 22:35
  • @GregPrice I am also waiting for this feature till then, EasyRichText library is the option though it is bit different than RichText as you cannot use it directly as a String which I reckon is a deal breaker. – Swapnil Kadam Jan 25 '21 at 06:47
0

RichText class might help you - https://docs.flutter.io/flutter/widgets/RichText-class.html It is very similar to Spannable string in Android

user1991679
  • 2,109
  • 1
  • 23
  • 19
  • That is a lot like SpannableString in Android, but it doesn't have this feature. (Because Flutter currently doesn't have this feature at all; see issue linked in a comment on the question.) – Greg Price Jan 24 '21 at 22:32
  • Sorry, didn't notice. There is a library that could help you to achieve desired effect: https://pub.dev/packages/easy_rich_text – user1991679 Jan 26 '21 at 11:29
0

If you need a widget then you can go with Text.rich widget or if you need a text alone then you can create List<TextSpan> with the text you have and make into a single text

Suganya
  • 419
  • 3
  • 11