我如何将文本添加到我的floatActionButton?

问题描述 投票:0回答:2

我正在尝试向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(),
          ),
        );
      },
    ),
  );
}
flutter dart
2个回答
2
投票

您可以使用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),
),

0
投票

使用label构造函数的FloatingActionButton.extended属性。例如label: Text('Approve'),

Reference with sample codes from flutter.dev。页面上的第二个示例。

Api Reference of FloatingActionButton.extended constructor

© www.soinside.com 2019 - 2024. All rights reserved.