LiewJunTung / pin_code_text_field

A highly customisable Flutter widget for entering pin code. Suitable for use cases such as login and OTP.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting error dispose

Raviteja11122 opened this issue · comments

@LiewJunTung
I/flutter ( 8091): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 8091): The following assertion was thrown building NotificationListener:
I/flutter ( 8091): A TextEditingController was used after being disposed.
I/flutter ( 8091): Once you have called dispose() on a TextEditingController, it can no longer be used.

This is because the Widget is closing the controller rather than relying on the parent to do it.

For now, the safest way to fix it is to wrap the dispose call in a try / catch. That will stop the error from propagating while preventing a memory leak when this is fixed in a future release. I saw this error myself late last night and found the root cause early this morning. I have an active PR, I'll add this to it.

Until said PR is merged, just do this for now:

  void dispose() {
    // ... other cleanup here

    try {
      _pinController?.dispose();
    } catch (e) {
      // no-op;
      // There's a bug in the current PIN editor where the controller is
      // disposed by the PIN editor itself, even though it should not be.
      //
      // This silences the error while also protects us from a memory leak
      // if that bug is fixed in a bug-fix version that we auto-pick-up.
    }
    super.dispose();
  }

Fix is available in this PR:
#22

Okay, thanks! @jpeiffer I'll merge it once I tested it.