Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: SingleChildScrollView(
child: Center(
child: SizedBox(
width: screenWidth * 0.8,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
color: Colors.yellow,
padding: const EdgeInsetsDirectional.only(start: 16.0),
child: SizedBox(
width: double.infinity,
child: Wrap(
runAlignment: WrapAlignment.center,
crossAxisAlignment: WrapCrossAlignment.center,
alignment: WrapAlignment.center,
children: [
RichText(
text: TextSpan(
text: 'afda fd afd asf das fds',
children: [
TextSpan(
text: 'fda fda fd asfd sa',
style: TextStyle(
color: Theme.of(context).primaryColor,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () {
// Handle the click action for terms and conditions link
print("tap");
},
),
const TextSpan(
text: ' fdsa ',
),
TextSpan(
text: 'fdsafdafda sf dsa',
style: TextStyle(
color: Theme.of(context).primaryColor,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () async {
await launchUrl(
Uri.parse('https://flutter.dev'));
},
),
],
),
),
],
),
),
),
],
),
),
),
),
),
)
I want the second line of text to be centered. If I put a few containers as children of Wrap, it does center them, but it doesn’t work for the RichText or Text.rich(…).
The app is rtl so the text is on the right.
>Solution :
To center the text, you need to use textAlign: TextAlign.center
RichText(
textAlign: TextAlign.center,
text: TextSpan(

