🍢
【Flutter】Centering of Multiple TextSpan
Flutterでは、TextSpanの文字を中央揃えするためにWidgetSpanが使用できます。
WidgetSpanのalignmentでPlaceholderAlignment.middleを適用します。
RichText(
text: TextSpan(
children: [
WidgetSpan(
child: Text(
'+',
style: TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
),
),
alignment: PlaceholderAlignment.middle,
),
WidgetSpan(
child: Text(
'40',
style: TextStyle(
fontSize: 64,
fontWeight: FontWeight.bold,
),
),
alignment: PlaceholderAlignment.middle,
),
WidgetSpan(
child: Text(
'pt',
style: TextStyle(
fontSize: 48,
fontWeight: FontWeight.bold,
),
),
alignment: PlaceholderAlignment.middle,
),
],
),
);
Ref
AI メンタルパートナー アウェアファイを開発する、株式会社Awarefy の技術ブログ Zenn 支社です。 技術ブログ(公式) awarefy.dev
Discussion