From 231ab685681fdd84200a2c51b229614eba52aa37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=91=86=E5=91=86666?= Date: Sat, 9 Nov 2024 22:03:20 +0800 Subject: [PATCH] process #235 --- example/lib/demo/issue235_toast.dart | 45 ++++++++++++++++++++++++++ lib/src/custom/toast/custom_toast.dart | 4 ++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 example/lib/demo/issue235_toast.dart diff --git a/example/lib/demo/issue235_toast.dart b/example/lib/demo/issue235_toast.dart new file mode 100644 index 0000000..4489755 --- /dev/null +++ b/example/lib/demo/issue235_toast.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; + +void main() { + runApp(MaterialApp( + navigatorObservers: [FlutterSmartDialog.observer], + builder: FlutterSmartDialog.init(), + home: const MyApp(), + )); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text( + "Test", + ), + ), + body: Center( + child: ElevatedButton( + onPressed: () async { + show("toast1"); + show("toast2"); + }, + child: const Text( + "Click", + ), + ), + ), + ); + } + + Future show(String msg) { + return SmartDialog.showToast( + msg, + alignment: Alignment.center, + displayType: SmartToastType.last, + displayTime: const Duration(seconds: 3), + ); + } +} \ No newline at end of file diff --git a/lib/src/custom/toast/custom_toast.dart b/lib/src/custom/toast/custom_toast.dart index 1bc1f3c..f3b2442 100644 --- a/lib/src/custom/toast/custom_toast.dart +++ b/lib/src/custom/toast/custom_toast.dart @@ -141,7 +141,9 @@ class CustomToast extends BaseDialog { var toastQueue = ToastTool.instance.toastQueue; if (toastQueue.isNotEmpty) { for (var item in toastQueue) { - item.mainDialog.overlayEntry.remove(); + await ViewUtils.awaitPostFrame(onPostFrame: () { + item.mainDialog.overlayEntry.remove(); + }); } toastQueue.clear(); ToastTool.instance.cancelLastDelay();