如何将文本(在RichText
中)对齐在抖动中心?
这是我的代码:
import 'package:flutter/material.dart';
Widget appBar(BuildContext context) {
return RichText(
text: TextSpan(
style: TextStyle(fontSize:22),
children: <TextSpan >[
TextSpan(text: 'My', style: TextStyle(fontWeight: FontWeight.w500, color: Colors.black54)),
TextSpan(text: 'App', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue)),
],
),
);
}
您可以将RichText包装为中心小部件的子元素,如下所示:
Widget appBar(BuildContext context) {
return Center(
child : RichText(
text: TextSpan(
style: TextStyle(fontSize:22),
children: <TextSpan >[
TextSpan(text: 'My', style: TextStyle(fontWeight: FontWeight.w500, color: Colors.black54)),
TextSpan(text: 'App', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.blue)),
],
),
)
);
}