小编Lav*_*rma的帖子

根据闭包上下文的要求,返回类型“Future<bool?> Function()”不是“Future<bool>”

  • 我已经将我的项目 sdk 升级到了,>2.12所以我正在进行更改,但我陷入了这个特定的错误,无法找到任何解决方案。
  • 我对该方法进行了更改,如下所示,在调用它时我不知道如何修复它。这个问题是在我升级并尝试解决所有non-nullable“空安全”问题后引起的
  • 代码
  Future<bool?> _onBackPressed() async {
    return showDialog(
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text('Do you want to exit without saving changes?'),
            content:
                Text('Please press the SAVE button at the bottom of the page'),
            actions: <Widget>[
              TextButton(
                child: Text('NO'),
                onPressed: () {
                  Navigator.of(context).pop(false);
                },
              ),
              TextButton(
                child: Text('YES'),
                onPressed: () {
                  Navigator.of(context).pop(true);
                  Navigator.of(context).pop(true);
                },
              ),
            ],
          );
        });
  }
..
    return WillPopScope(
      onWillPop: () => _onBackPressed, // causing error
      child: …
Run Code Online (Sandbox Code Playgroud)

dart flutter dart-null-safety

3
推荐指数
1
解决办法
1万
查看次数

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

我正在尝试将文本添加到我的,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)

dart flutter

0
推荐指数
1
解决办法
1292
查看次数

标签 统计

dart ×2

flutter ×2

dart-null-safety ×1