flutter - 如何在 Flutter 中实现应用栏操作文本而不是操作图标?
问题描述
我正在尝试在颤振应用程序中实现 appbar。我可以添加一个关闭应用程序的操作图标。我愿意在关闭操作图标旁边显示用户名。我尝试在 appar 部分的操作小部件数组中添加 new Text() 。但无法对齐。有没有办法直接添加动作文本?
代码:
@override
Widget build(BuildContext context) {
//build a form widget using the form key we created above
return new Scaffold(
appBar: new AppBar(
title: new Text(StringRef.appName),
actions: <Widget>[
new Container(),
new Text(
userName,
textScaleFactor: 1.5,
style: new TextStyle(
fontSize: 12.0,
color: Colors.white,
),
),
new IconButton(
icon: new Icon(Icons.close),
tooltip: 'Closes application',
onPressed: () => exit(0),
),
],
),
}
解决方案
Wrap your Text widget inside Center widget as
new Center(
new Text(
userName,
textScaleFactor: 1.5,
style: new TextStyle(
fontSize: 12.0,
color: Colors.white,
),
),
)
推荐阅读
- javascript - 遍历数组并分配新值
- c# - 存储过程在价格范围内查找产品
- python - Flask-Limiter 不适用于基于 Flask-Restful API 的应用程序
- email - 如何在 logstash 输出电子邮件中附加附件?
- python - 我遇到了函数错误之外的返回问题
- haskell - 使用类别的 Functor 进行映射
- asp.net - Ajax AutoCompleteExtender 工具包 ASP.net vb
- python - 为什么 ImportError: cannot import name 'AutoReg' from 'statsmodels.tsa.ar_model' 发生?
- python - 解酸堆栈下溢
- python - CSV 文件读取未进入循环