flutter - 如何将文本添加到我的 floatingActionButton?
问题描述
我正在尝试向我添加文本,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),
),
推荐阅读
- html - 无法更改 img 上的高度
- c# - 从 C# 运行的 powershell 命令捕获输出
- google-apps-script - 在编辑特定范围时运行函数 - 跟进问题 2
- node.js - 如何在节点js中使用异步和等待获取数据
- android - Gradle Build Fails - 类文件 com/google/wireless/android/sdk/stats/GradleBuildMemorySample$Builder 中的非法异常表范围
- reactjs - 一个字段的列内带有下拉菜单的材料 UI 表
- azure - Terraform:如何将一个模块的输出值传递给天蓝色的另一个模块
- powershell - 有没有办法使用 powershell 从 lotus notes 数据库中获取超过 30 分钟的文档?
- java - Java Jackson,带 Map 的编组类
无法访问类代码库 - java - Spring JPA如何在孩子坚持ManyToMany关系时坚持父母