Skip to content

Commit

Permalink
Added onDismiss callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Do-Repo committed Dec 20, 2023
1 parent ac8810a commit a43c4ca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
9 changes: 3 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ class _HomePageState extends State<HomePage> {
const SizedBox(height: 16),
Slider.adaptive(
value: _minHeight,
onChanged: (value) =>
setState(() => _minHeight = value.floorToDouble()),
onChanged: (value) => setState(() => _minHeight = value.floorToDouble()),
min: 0.0,
max: MediaQuery.of(context).size.height,
),
Expand All @@ -80,6 +79,7 @@ class _HomePageState extends State<HomePage> {
),
context: context,
onTap: () => print('Notification tapped!'),
onDismiss: () => print('Notification dismissed!'),
duration: Duration(milliseconds: _duration),
);
},
Expand Down Expand Up @@ -148,10 +148,7 @@ class NotificationBody extends StatelessWidget {
child: Center(
child: Text(
'Count: $count',
style: Theme.of(context)
.textTheme
.headline4!
.copyWith(color: Colors.white),
style: Theme.of(context).textTheme.headline4!.copyWith(color: Colors.white),
),
),
),
Expand Down
8 changes: 2 additions & 6 deletions lib/src/in_app_notification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class _NotificationController extends InheritedWidget {
VoidCallback? onTap,
VoidCallback? onDismiss,
}) async {
await dismiss(shouldAnimation: !state.showController.isDismissed);
(state.overlay != null) ? await dismiss(shouldAnimation: !state.showController.isDismissed) : null;

state.verticalAnimationController.dragDistance = 0.0;
state.horizontalAnimationController.dragDistance = 0.0;
Expand Down Expand Up @@ -188,14 +188,10 @@ class _NotificationController extends InheritedWidget {

Future<void> dismiss({bool shouldAnimation = true, double from = 1.0}) async {
state.timer?.cancel();
print("dismiss triggered");
if (state.onDismiss != null) {
print("on dismiss not null");
state.onDismiss!();
}

await state.showController.reverse(from: shouldAnimation ? from : 0.0);

state.onDismiss != null ? state.onDismiss!() : null;
state.overlay?.remove();
state.overlay = null;
state.notificationSizeCompleter = Completer();
Expand Down

0 comments on commit a43c4ca

Please sign in to comment.