coingaming / moon_flutter

Moon Design System for Flutter
https://flutter.moon.io
MIT License
196 stars 24 forks source link

Disposing provided controllers. #419

Closed dickermoshe closed 4 months ago

dickermoshe commented 5 months ago

Regular flutter widgets don't typically dispose of controllers they are explicitly provided. I was wondering why I was getting errors when disposing TextEditingControllers and the MoonCarouselScrollController.

Turns out, that MoonCarousel will dispose MoonCarouselScrollController even if it was passed explicity.

A MoonCarouselScrollController was used after being disposed.

The same is true for MoonAuthCode, where Im getting this error when disposing:

Once you have called dispose() on a TextEditingController, it can no longer be used.

I would suggest adding the following:

void _initializeTextEditingController() {
  _textEditingController = widget.textController ?? TextEditingController();
  _isPrivateTextEditingController = widget.textController == null;
//...
}
//...
@override
  void dispose() {
    if (_isPrivateTextEditingController){
     _textEditingController.dispose();
   }
   //...
}
GittHub-d commented 4 months ago

Fixed in latest release #426