Skip to content

Commit

Permalink
feat: Add onRemoveFromRoute in DefaultFlashController.
Browse files Browse the repository at this point in the history
  • Loading branch information
sososdk committed Oct 27, 2023
1 parent 387dac6 commit 96e438b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [3.0.5+2] - 2023-10-27
- Add `onRemoveFromRoute` in `DefaultFlashController`, it only works when `persistent` is false.

## [3.0.5+1] - 2023-5-30
- `FlashBar` add `builder` param to warp child.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
```yaml
dependencies:
...
flash: ^3.0.5+1
flash: ^3.0.5+2
```
In your library add the following import:
Expand Down
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ class _FlashPageState extends State<FlashPage> {
ElevatedButton(
onPressed: () => context.showFlash<bool>(
persistent: false,
onRemoveFromRoute: () {
context.showToast(Text('Flash removed'));
},
builder: (context, controller) => FlashBar(
controller: controller,
behavior: FlashBehavior.floating,
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.0.5+1"
version: "3.0.5+2"
flutter:
dependency: "direct main"
description: flutter
Expand Down
2 changes: 2 additions & 0 deletions lib/flash_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ extension FlashShortcuts on BuildContext {
FutureOr<bool> Function()? onBarrierTap,
Curve barrierCurve = Curves.ease,
bool persistent = true,
VoidCallback? onRemoveFromRoute,
Duration? duration,
required FlashBuilder<T> builder,
Completer<T>? dismissCompleter,
Expand All @@ -283,6 +284,7 @@ extension FlashShortcuts on BuildContext {
onBarrierTap: onBarrierTap,
barrierCurve: barrierCurve,
persistent: persistent,
onRemoveFromRoute: onRemoveFromRoute,
duration: duration,
builder: builder,
);
Expand Down
10 changes: 8 additions & 2 deletions lib/src/flash_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Future<T?> showFlash<T>({
Curve barrierCurve = Curves.ease,
Duration? duration,
bool persistent = true,
VoidCallback? onRemoveFromRoute,
}) {
return DefaultFlashController<T>(
context,
Expand All @@ -39,6 +40,7 @@ Future<T?> showFlash<T>({
barrierCurve: barrierCurve,
duration: duration,
persistent: persistent,
onRemoveFromRoute: onRemoveFromRoute,
).show();
}

Expand All @@ -54,6 +56,7 @@ class DefaultFlashController<T> implements FlashController<T> {
this.onBarrierTap,
this.barrierCurve = Curves.ease,
this.persistent = true,
this.onRemoveFromRoute,
this.duration,
}) : assert(onBarrierTap == null || (barrierDismissible || barrierColor != null || barrierBlur != null)),
route = ModalRoute.of(context) {
Expand Down Expand Up @@ -119,9 +122,11 @@ class DefaultFlashController<T> implements FlashController<T> {
/// ```
final bool persistent;

/// Called when this flash is removed from the history of its associated [LocalHistoryRoute].
/// Only works when [persistent] is false.
final VoidCallback? onRemoveFromRoute;

/// The animation controller that the route uses to drive the transitions.
///
/// The animation itself is exposed by the [animation] property.
@override
AnimationController get controller => _controller;
late AnimationController _controller;
Expand Down Expand Up @@ -257,6 +262,7 @@ class DefaultFlashController<T> implements FlashController<T> {
if (!persistent) {
_historyEntry = LocalHistoryEntry(onRemove: () {
assert(!_transitionCompleter.isCompleted, 'Cannot reuse a $runtimeType after disposing it.');
onRemoveFromRoute?.call();
_removedHistoryEntry = true;
if (!_dismissed) {
_cancelTimer();
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: flash
description: A highly customizable, powerful and easy-to-use alerting library for Flutter.
version: 3.0.5+1
version: 3.0.5+2
homepage: https://github.com/sososdk/flash

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=2.17.0 <4.0.0"

dependencies:
flutter:
Expand Down

0 comments on commit 96e438b

Please sign in to comment.