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?
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),
),
],
),
}
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,
),
),
)
You can also Wrap your Text
widget inside Align
widget and give a alignment: Alignment.center
like below
Align(
alignment: Alignment.center,
child: Text(
"Save",
textScaleFactor: 1.5,
style: TextStyle(
fontSize: 12.0,
color: Colors.white,
),
),
)
And also you can achieve this by using a TextButton
TextButton(
onPressed: () {},
child: Text('Save', style: TextStyle(color: Colors.white),),
)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.