誰かが私に国コードに基づいて携帯電話番号をフォーマットする方法を教えてください。あなたが理解してください。
これは私がこれまで試してみたことです:
var controller = new MaskedTextController(mask: '(000) 000 0000');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar( title: Text("Masked Text"), ),
body: Container(
child: Row(
children: <Widget>[
Expanded(
child: TextField(
controller: controller,
keyboardType: TextInputType.number, maxLength: 18,
),
),
],
)),
);
}
_
良いと簡単な解決策は https://pub.dev/packages/intl_phone_number_input
final TextEditingController controller = TextEditingController();
String initialCountry = 'NG';
PhoneNumber number = PhoneNumber(isoCode: 'NG');
InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber number) {
print(number.phoneNumber);
},
onInputValidated: (bool value) {
print(value);
},
selectorConfig: SelectorConfig(
selectorType: PhoneInputSelectorType.BOTTOM_SHEET,
backgroundColor: Colors.black,
),
ignoreBlank: false,
autoValidateMode: AutovalidateMode.disabled,
selectorTextStyle: TextStyle(color: Colors.black),
initialValue: number,
textFieldController: controller,
inputBorder: OutlineInputBorder(),
),
_