繁体   English   中英

如何在 Flutter 中实现应用栏操作文本而不是操作图标?

[英]How to implement app bar action text instead of action icon in Flutter?

我正在尝试在颤振应用程序中实现 appbar。 我可以添加关闭应用程序的操作图标。 我愿意在关闭操作图标旁边显示用户名。 我尝试在 appar 部分的 action 小部件数组中添加 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),
      ),
        ],
      ),
}

将您的 Text 小部件包裹在 Center 小部件中

new Center(
    new Text(
        userName,
        textScaleFactor: 1.5,
        style: new TextStyle(
          fontSize: 12.0,
          color: Colors.white,
        ),
   ),
)

您还可以将Text小部件包裹在Align小部件内并进行alignment: Alignment.center如下所示

Align(
  alignment: Alignment.center,
  child: Text(
    "Save",
    textScaleFactor: 1.5,
    style: TextStyle(
      fontSize: 12.0,
      color: Colors.white,
    ),
  ),
)

你也可以通过使用TextButton来实现这TextButton

TextButton(
  onPressed: () {},
  child: Text('Save', style: TextStyle(color: Colors.white),),
)

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM