【发布时间】:2021-09-18 15:55:26
【问题描述】:
- 我已将我的项目 sdk 升级到
>2.12,因此我正在进行更改,但我遇到了这个特定错误,无法找到任何解决方案。 - 我已经对方法进行了更改,如下所示,调用它时我不知道如何修复它。这个问题是在我升级并尝试解决所有
non-nullable或``null-safety``` 问题后引起的 - 代码
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: Scaffold(
key: _scaffoldkey,
body: SafeArea(
child: SingleChildScrollView(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Stack(
children: <Widget>[
Positioned(
child: AppBar(
centerTitle: true,
title: Text(
"Sample",
style: TextStyle(
fontFamily: 'LobsterTwo',
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.black87,
),
),
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.black,
size: 30,
),
onPressed: () {
_onBackPressed();
},
..
..
),
),
),
],
),
],
),
),
),
),
),
);
- 错误
【问题讨论】:
标签: flutter dart dart-null-safety