- I have upgraded my project sdk to
>2.12 so I am making the changes and I am stuck at this particular error and not able to find any solution for it.
- I have made changes in the method as you can see below while calling it I am not sure how to fix it. The issue is being caused after I upgraded and trying to solve all the
non-nullable or ``null-safety``` issue
- Code
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();
},
..
..
),
),
),
],
),
],
),
),
),
),
),
);
