user3831831
user3831831

Reputation:

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

I am trying to implement appbar in the flutter application. I am able to add an action icon that closes the app. I am willing to show the username beside the close action icon. I tried to add new Text() in the action widget array in the appar section. but not able to align it. Is there any way to add action text directly?

enter image description here

Code:

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

Upvotes: 8

Views: 13416

Answers (1)

Dhiraj Sharma
Dhiraj Sharma

Reputation: 4879

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,
        ),
   ),
)

Upvotes: 20

Related Questions