flutter - 如何在 Text.rich() 中对齐文本中心
问题描述
我正在使用一个文本跨度小部件,我喜欢在其中将所有文本居中,而不是在开始时默认对齐。
Text.rich(
TextSpan(
text: "Go to your e-mail inbox and ",
style: TextStyle(
color: appBackground_color,
fontSize: 14,
fontWeight: FontWeight.w500),
children: <InlineSpan>[
TextSpan(
text: "activate your account",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w700,
color: appBackground_color,
),
),
TextSpan(
text: " to proceed.",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: appBackground_color),
),
],
),
),
我怎样才能在这个小部件中居中文本?
解决方案
使用RichText()
而不是Text.rich()
. Text.rich()
没有textAlign
参数。像这样使用:
RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: "Go to your e-mail inbox and ",
children: <InlineSpan>[
TextSpan(),
TextSpan(),
],
),
),
但请记住,RichText()
必须有一个宽度textAlign
才能工作。像这样:
Container(
width: double.infinity,
child: RichText(
//**
),
),
推荐阅读
- node.js - 如何在nodejs后端验证谷歌登录(通过Firebase)idToken?
- python - 部分离散的颜色图 matplotlib
- arrays - 如何使用bash替换文件中的数组?
- android - 提交现有 android app/apk 的新版本会受到 Android App Bundle 要求的影响吗?
- r - 从 rpart 模型中检索决策规则
- c# - Hot Chocolate (GraphQL) 根据请求获取架构(通过中间件或过滤器)
- python - 在我的货币转换器中获取“KeyError”
- reactjs - 尽管传递了值,但反应常量没有更新
- node.js - Node.js 在回调中使用外部变量
- php - 无法使用 laravel eloquent 关系获取所需的数据