我正在尝试向floatingActionButton
添加文本,但无法这样做。我如何添加文本但找不到任何方法。
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () async {
// when clicked on floating action button prompt to create user
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => CreateUser(),
),
);
},
),
);
}
您可以使用FloatingActionButton.extended
一次在FAB中显示文本和图标。
FloatingActionButton.extended(
onPressed: () {
// when clicked on floating action button prompt to create user
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => CreateUser(),
),
);
},
label: Text('Label'),
icon: Icon(Icons.add),
),
使用label
构造函数的FloatingActionButton.extended
属性。例如label: Text('Approve'),
Reference with sample codes from flutter.dev。页面上的第二个示例。