我如何将Richtext对齐到居中位置,默认情况下是左对齐

问题描述 投票:0回答:1

如何将文本(在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)),

            ],
        ),
    );

}
flutter-layout flutter-test
1个回答
0
投票

您可以将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)),

            ],
        ),
    )
    ); 
}
© www.soinside.com 2019 - 2024. All rights reserved.