web-dev-qa-db-ja.com

Flutterでアクションアイコンの代わりにアプリバーのアクションテキストを実装するにはどうすればよいですか?

フラッターアプリケーションにappbarを実装しようとしています。アプリを閉じるアクションアイコンを追加できます。クローズアクションアイコンの横にユーザー名を表示したいと思います。 apparセクションのアクションウィジェット配列に新しいText()を追加しようとしました。しかし、それを整列させることはできません。アクションテキストを直接追加する方法はありますか?

enter image description here

コード:

@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),
      ),
        ],
      ),
}
5
user3831831

テキストウィジェットをセンターウィジェット内に次のようにラップします

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