ponnamkarthik / FlutterToast

Toast Plugin for Flutter
MIT License
1.46k stars 364 forks source link

cancel() works only on the 1st time #512

Open subzero911 opened 4 months ago

subzero911 commented 4 months ago

I want to cancel the toast everytime I press the key.

But it works only on the 1st time, next toasts are not cancelled:

https://github.com/ponnamkarthik/FlutterToast/assets/12999702/3fbcd444-7969-45ba-b8c8-68b4614da188

code:

@override
  void initState() {
    super.initState();
    nameTextController = TextEditingController()
      ..addListener(() async {
        if (nameTextController.text.length > 40) {
          await Fluttertoast.cancel();
          Fluttertoast.showToast(msg: 'Max 40 characters').ignore();
        }
      });
  }
jongkb commented 1 week ago

I'm noticing this too on Android 14. However, on Android 10, cancel() works as expected on repeated calls.

davidd7 commented 1 week ago

I'm also having this problem on Android 14. One workaround I've found is calling cancel multiple times. For example, the problem doesn't appear for me for short toasts when always calling cancel 10 times:

  for (int i = 0; i < 10; i++) {
    await Fluttertoast.cancel();
  }

This is of course a rather ugly workaround and it would be better if the underlying problem would be fixed.