Reputation: 43
How do I align the text (in the RichText
) to center in flutter?
Here is my code:
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)),
],
),
);
}
Upvotes: 1
Views: 2306
Reputation: 3479
You can wrap your RichText as a child of center widget like following:
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)),
],
),
)
);
}
Upvotes: 2