如何将文本添加到我的浮动操作按钮?

Lav*_*rma 0 dart flutter

我正在尝试将文本添加到我的,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(),
          ),
        );
      },
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)

Jid*_*uru 6

您可以使用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),
),
Run Code Online (Sandbox Code Playgroud)