From a40f7704a0e674cbe66f114f782af3debade4220 Mon Sep 17 00:00:00 2001 From: Badr Kouki <36043466+koukibadr@users.noreply.github.com> Date: Sun, 2 Apr 2023 13:14:26 +0100 Subject: [PATCH] Hot fix #100 : auto pop bug --- CHANGELOG.md | 4 ++++ README.md | 22 +++++++++++++++++++++- lib/motion_toast.dart | 9 +++++++++ pubspec.yaml | 2 +- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19f4b5a..d1b7eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.6.6] - 02/04/2023 + +- Add dismiss toast callback (hot fix for this [issue](https://github.com/koukibadr/Motion-Toast/issues/100) ) + ## [2.6.5] - 11/02/2023 - Fix material3 support issue for bottom toasts diff --git a/README.md b/README.md index fafb26d..2b673d7 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ In order to add motion toast to your project add this line to your `pubspec.yaml ```yaml dependencies: - motion_toast: ^2.6.5 + motion_toast: ^2.6.6 ``` @@ -501,6 +501,26 @@ MotionToast( ``` +- **Dismiss the toast from your UI screen** + + + +```dart + +MotionToast toast = MotionToast( + icon: Icons.zoom_out, + primaryColor: Colors.orange[500]!, + secondaryColor: Colors.grey, + backgroundType: BackgroundType.solid, + title: Text('Two Color Motion Toast'), + description: Text('Another motion toast example'), + displayBorder: true, + displaySideBar: false, +).show(context); +toast.dismiss(); + +``` + ## Contribution diff --git a/lib/motion_toast.dart b/lib/motion_toast.dart index 5aba5a2..763bb68 100644 --- a/lib/motion_toast.dart +++ b/lib/motion_toast.dart @@ -431,9 +431,12 @@ class MotionToast extends StatefulWidget { /// default `= true` final bool displaySideBar; + late BuildContext _context; + /// Display the created motion toast based on the [position] attribute /// [context]: the actual context of the application void show(BuildContext context) { + _context = context; Navigator.of(context).push( PageRouteBuilder( fullscreenDialog: false, @@ -444,6 +447,12 @@ class MotionToast extends StatefulWidget { ), ); } + + void dismiss() { + Navigator.of(_context).pop(); + onClose?.call(); + } + } class _MotionToastState extends State diff --git a/pubspec.yaml b/pubspec.yaml index c612b79..74f82a0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: motion_toast description: 'A beautiful designed toast with animations, contains multiple built in designs and let you design your toast' -version: 2.6.5 +version: 2.6.6 homepage: 'https://github.com/koukibadr/Motion-Toast' environment: sdk: '>=2.12.0 <3.0.0'