ponnamkarthik / FlutterToast

Toast Plugin for Flutter
MIT License
1.43k stars 349 forks source link

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

Open subzero911 opened 3 weeks ago

subzero911 commented 3 weeks 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();
        }
      });
  }