-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What does this PR do? This PR contains a new cancel creation post/article modal screen ### Changes brought by this PR - When back selected on create article / create post screens we show an extra confirmation popup that all changes will be reset ### Additional information <img width="495" alt="Screenshot 2024-10-03 at 14 25 46" src="https://github.com/user-attachments/assets/aa81afe6-e05f-4aa1-8b54-12dcf17abb83"> <img width="495" alt="Screenshot 2024-10-03 at 14 25 41" src="https://github.com/user-attachments/assets/b091a2ab-70c2-43d0-ad00-91cb1b0eca4f">
- Loading branch information
1 parent
70226ca
commit 10525d0
Showing
9 changed files
with
329 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
lib/app/components/back_hardware_button_interceptor/back_hardware_button_interceptor.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
import 'dart:async'; | ||
|
||
import 'package:back_button_interceptor/back_button_interceptor.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
|
||
class BackHardwareButtonInterceptor extends HookWidget { | ||
const BackHardwareButtonInterceptor({ | ||
required this.child, | ||
required this.onBackPress, | ||
super.key, | ||
}); | ||
final Widget child; | ||
final Future<void> Function(BuildContext context) onBackPress; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final handleBackButton = useCallback( | ||
({ | ||
required bool stop, | ||
required RouteInfo info, | ||
required BuildContext context, | ||
}) async { | ||
if (info.ifRouteChanged(context)) { | ||
return false; | ||
} else { | ||
await onBackPress(context); | ||
return true; | ||
} | ||
}, | ||
[], | ||
); | ||
|
||
final backButtonInterceptor = useCallback( | ||
(bool stop, RouteInfo info) { | ||
return handleBackButton( | ||
stop: stop, | ||
info: info, | ||
context: info.routeWhenAdded?.navigator?.context ?? context, | ||
); | ||
}, | ||
[handleBackButton], | ||
); | ||
|
||
useEffect( | ||
() { | ||
BackButtonInterceptor.add(backButtonInterceptor, context: context); | ||
return () => BackButtonInterceptor.remove(backButtonInterceptor); | ||
}, | ||
[backButtonInterceptor], | ||
); | ||
|
||
return child; | ||
} | ||
} |
Oops, something went wrong.