how can we use superscript and subscript text in flutter Text or RichText

后端 未结 3 1790
灰色年华
灰色年华 2020-12-01 14:27

i want to show a superscript text but not found any example or can anyone help me with this.

I have tried Text and RichText also, but not found any method or fields.

3条回答
  •  执念已碎
    2020-12-01 14:58

    You can make use of offset property in WidgetSpan. I have used the below code to show flight cross overs. The Offset dx and dy values helps you to set superscript or subscript as per your need.

    RichText(
      text: TextSpan(children: [
        TextSpan(
            text: '9:30 - 2:30',
            style: TextStyle(color: Colors.black)),
        WidgetSpan(
          child: Transform.translate(
            offset: const Offset(2, -4),
            child: Text(
              '+2',
              //superscript is usually smaller in size
              textScaleFactor: 0.7,
              style: TextStyle(color: Colors.red),
            ),
          ),
        )
      ]),
    )
    

提交回复
热议问题