When implementing the InternationalPhoneNumberInput widget, follow these patterns for common tasks:
Form Integration
Integrate with a Flutter Form widget and use autoValidateMode (e.g., AutovalidateMode.onUserInteraction) to provide real-time feedback. Always handle the onInputChanged callback to receive the updated PhoneNumber object.
Form(
key: _formKey,
child: InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber number) {
// Handle phone number changes
},
validator: (String? value) {
// Custom validation logic
return null;
},
autoValidateMode: AutovalidateMode.onUserInteraction,
),
),
Programmatic Control with Controllers
Use a TextEditingController via the textFieldController property to control the text input programmatically.
final TextEditingController _controller = TextEditingController();
InternationalPhoneNumberInput(
textFieldController: _controller,
onInputChanged: (PhoneNumber number) {
// number contains the complete phone number data
},
)
Customizing the Selector and Input Decoration
Use selectorConfig to change the selector type (e.g., PhoneInputSelectorType.BOTTOM_SHEET) and appearance, and inputDecoration for standard Material Design styling.
InternationalPhoneNumberInput(
selectorConfig: SelectorConfig(
selectorType: PhoneInputSelectorType.BOTTOM_SHEET,
backgroundColor: Colors.blue,
showFlags: true,
),
inputDecoration: InputDecoration(
labelText: 'Phone Number',
border: OutlineInputBorder(),
),
)