imtoori/CountryCodePicker

onChanged not triggered

maitycyrus opened this issue · 1 comments

If one selects a country using the search the onChanged callback does not fire.

E/flutter (17132): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: setState() called after dispose(): CountryCodePickerState#6d294(lifecycle state: defunct, not mounted)
E/flutter (17132): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter (17132): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter (17132): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
E/flutter (17132): #0 State.setState. (package:flutter/src/widgets/framework.dart:1052:9)
E/flutter (17132): #1 State.setState (package:flutter/src/widgets/framework.dart:1087:6)
E/flutter (17132): #2 CountryCodePickerState.showCountryCodePickerDialog. (package:country_code_picker/country_code_picker.dart:355:11)
E/flutter (17132): #3 _rootRunUnary (dart:async/zone.dart:1436:47)
E/flutter (17132): #4 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter (17132):

The problem appears if setState is called during the CountryPicker being opened. Setting a ValueKey helps.