Skip to content

Commit

Permalink
replacing the deprecated will-pop-scope with pop-scope widget (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
superiorsd10 authored Dec 9, 2023
1 parent fcb8077 commit b942e36
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 86 deletions.
155 changes: 79 additions & 76 deletions lib/app/modules/addOrUpdateAlarm/views/add_or_update_alarm_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,85 @@ class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
Widget build(BuildContext context) {
var width = Get.width;
var height = Get.height;
return WillPopScope(
return PopScope(
canPop: false,
onPopInvoked: (bool didPop) {
if (didPop) {
return;
}

Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(
vertical: 20,
),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
: ksecondaryBackgroundColor,
title: 'Discard Changes?',
titleStyle: Theme.of(context).textTheme.displaySmall,
content: Column(
children: [
Text(
'You have unsaved changes. Are you sure you want to leave this'
' page?',
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(
top: 20,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () {
Get.back();
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(kprimaryColor),
),
child: Text(
'Cancel',
style:
Theme.of(context).textTheme.displaySmall!.copyWith(
color: kprimaryBackgroundColor,
),
),
),
OutlinedButton(
onPressed: () {
Get.offNamedUntil(
'/home',
(route) => route.settings.name == '/splash-screen',
);
},
style: OutlinedButton.styleFrom(
side: BorderSide(
color: themeController.isLightMode.value
? Colors.red.withOpacity(0.9)
: Colors.red,
width: 1,
),
),
child: Text(
'Leave',
style:
Theme.of(context).textTheme.displaySmall!.copyWith(
color: themeController.isLightMode.value
? Colors.red.withOpacity(0.9)
: Colors.red,
),
),
),
],
),
),
],
),
);
},
child: WithForegroundTask(
child: Scaffold(
floatingActionButtonLocation:
Expand Down Expand Up @@ -633,81 +711,6 @@ class AddOrUpdateAlarmView extends GetView<AddOrUpdateAlarmController> {
),
),
),
onWillPop: () async {
Get.defaultDialog(
titlePadding: const EdgeInsets.symmetric(
vertical: 20,
),
backgroundColor: themeController.isLightMode.value
? kLightSecondaryBackgroundColor
: ksecondaryBackgroundColor,
title: 'Discard Changes?',
titleStyle: Theme.of(context).textTheme.displaySmall,
content: Column(
children: [
Text(
'You have unsaved changes. Are you sure you want to leave this'
' page?',
style: Theme.of(context).textTheme.bodyMedium,
textAlign: TextAlign.center,
),
Padding(
padding: const EdgeInsets.only(
top: 20,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () {
Get.back();
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(kprimaryColor),
),
child: Text(
'Cancel',
style:
Theme.of(context).textTheme.displaySmall!.copyWith(
color: kprimaryBackgroundColor,
),
),
),
OutlinedButton(
onPressed: () {
Get.offNamedUntil(
'/home',
(route) => route.settings.name == '/splash-screen',
);
},
style: OutlinedButton.styleFrom(
side: BorderSide(
color: themeController.isLightMode.value
? Colors.red.withOpacity(0.9)
: Colors.red,
width: 1,
),
),
child: Text(
'Leave',
style:
Theme.of(context).textTheme.displaySmall!.copyWith(
color: themeController.isLightMode.value
? Colors.red.withOpacity(0.9)
: Colors.red,
),
),
),
],
),
),
],
),
);

return false;
},
);
}
}
24 changes: 14 additions & 10 deletions lib/app/modules/alarmRing/views/alarm_ring_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@ class AlarmControlView extends GetView<AlarmControlController> {
Widget build(BuildContext context) {
var width = Get.width;
var height = Get.height;
return WillPopScope(
return PopScope(
canPop: false,
onPopInvoked: (bool didPop) {
if (didPop) {
return;
}

Get.snackbar(
'Note',
"You can't go back while the alarm is ringing",
backgroundColor: Colors.red,
colorText: Colors.white,
);
},
child: SafeArea(
child: Scaffold(
floatingActionButtonLocation:
Expand Down Expand Up @@ -175,15 +188,6 @@ class AlarmControlView extends GetView<AlarmControlController> {
),
),
),
onWillPop: () async {
Get.snackbar(
'Note',
"You can't go back while the alarm is ringing",
backgroundColor: Colors.red,
colorText: Colors.white,
);
return false;
},
);
}
}

0 comments on commit b942e36

Please sign in to comment.