From 71c47d3e38a772faefd15117e610554c019fff0b Mon Sep 17 00:00:00 2001 From: MAYANK MALHOTRA <95639908+mayank29malhotra@users.noreply.github.com> Date: Thu, 20 Jun 2024 23:39:12 +0530 Subject: [PATCH 1/2] Update fluttertoast.dart --- lib/fluttertoast.dart | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/fluttertoast.dart b/lib/fluttertoast.dart index 26a1487c..a04d23cf 100644 --- a/lib/fluttertoast.dart +++ b/lib/fluttertoast.dart @@ -35,10 +35,14 @@ class Fluttertoast { static const MethodChannel _channel = const MethodChannel('PonnamKarthik/fluttertoast'); + /// Boolean to track if a toast is currently being shown + static bool isCurrentlyShowingToast = false; + /// Let say you have an active show /// Use this method to hide the toast immediately static Future cancel() async { bool? res = await _channel.invokeMethod("cancel"); + isCurrentlyShowingToast = false; // Update variable return res; } @@ -97,7 +101,15 @@ class Fluttertoast { 'webPosition': webPosition }; + isCurrentlyShowingToast = true; // Update variable + bool? res = await _channel.invokeMethod('showToast', params); + + // Assuming the platform will invoke 'cancel' method after showing toast + Future.delayed(Duration(seconds: timeInSecForIosWeb), () { + isCurrentlyShowingToast = false; + }); + return res; } } @@ -140,6 +152,7 @@ class FToast { _showOverlay() { if (_overlayQueue.isEmpty) { _entry = null; + Fluttertoast.isCurrentlyShowingToast = false; // Update variable return; } if (context == null) { @@ -184,6 +197,8 @@ class FToast { removeCustomToast(); }); }); + + Fluttertoast.isCurrentlyShowingToast = true; // Update variable } /// If any active toast present @@ -211,6 +226,7 @@ class FToast { _overlayQueue.clear(); _entry?.remove(); _entry = null; + Fluttertoast.isCurrentlyShowingToast = false; // Update variable } /// showToast accepts all the required paramenters and prepares the child From 997ec5b32a0de444b2a348328ffeff5a55fb98f3 Mon Sep 17 00:00:00 2001 From: MAYANK MALHOTRA <95639908+mayank29malhotra@users.noreply.github.com> Date: Thu, 20 Jun 2024 23:54:50 +0530 Subject: [PATCH 2/2] Create ErrorSolvedTesting.dart --- ErrorSolvedTesting.dart | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 ErrorSolvedTesting.dart diff --git a/ErrorSolvedTesting.dart b/ErrorSolvedTesting.dart new file mode 100644 index 00000000..f8fdcda6 --- /dev/null +++ b/ErrorSolvedTesting.dart @@ -0,0 +1,69 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +void main() { + runApp(MyApp()); +} + +class MyApp extends StatelessWidget { + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Flutter Toast Test', + theme: ThemeData( + primarySwatch: Colors.blue, + ), + home: MyHomePage(), + ); + } +} + +class MyHomePage extends StatefulWidget { + @override + _MyHomePageState createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + late Timer _timer; + + @override + void initState() { + super.initState(); + _timer = Timer.periodic(Duration(seconds: 1), (timer) { + print("isCurrentlyShowingToast: ${Fluttertoast.isCurrentlyShowingToast}"); + }); + } + + @override + void dispose() { + _timer.cancel(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Flutter Toast Test'), + ), + body: Center( + child: ElevatedButton( + onPressed: () { + Fluttertoast.showToast( + msg: "This is Center Short Toast", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.CENTER, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0, + ); + }, + child: Text('Show Toast'), + ), + ), + ); + } +}