diff --git a/example/lib/demo/issue235_toast.dart b/example/lib/demo/issue235_toast.dart new file mode 100644 index 0000000..a5601ef --- /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), + ); + } +} 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();