@@ -13,6 +13,7 @@ class _PhoneFormatPageState extends State<PhoneFormatPage> {
1313 TextEditingController _russianPhoneController =
1414 TextEditingController (text: '9998887766' );
1515 PhoneCountryData ? _initialCountryData;
16+ PhoneCountryData ? _initialCountryDataFiltered;
1617
1718 @override
1819 void dispose () {
@@ -121,10 +122,63 @@ class _PhoneFormatPageState extends State<PhoneFormatPage> {
121122 )
122123 ],
123124 ),
125+ SizedBox (height: 30.0 ),
126+ _getText (
127+ 'The next input uses a predefined country code' ,
128+ ),
129+ Row (
130+ children: [
131+ Expanded (
132+ flex: 3 ,
133+ child: CountryDropdown (
134+ printCountryName: true ,
135+ initialPhoneCode: '7' ,
136+ filter: PhoneCodes .findCountryDatasByCountryCodes (
137+ countryIsoCodes: [
138+ 'RU' ,
139+ 'BR' ,
140+ 'DE' ,
141+ ],
142+ ),
143+ onCountrySelected: (PhoneCountryData countryData) {
144+ setState (() {
145+ _initialCountryDataFiltered = countryData;
146+ });
147+ },
148+ ),
149+ ),
150+ SizedBox (width: 10.0 ),
151+ Expanded (
152+ flex: 5 ,
153+ child: TextFormField (
154+ key: ValueKey (
155+ _initialCountryDataFiltered ?? 'country' ),
156+ decoration: InputDecoration (
157+ border: OutlineInputBorder (),
158+ hintText: _initialCountryDataFiltered
159+ ? .phoneMaskWithoutCountryCode,
160+ hintStyle:
161+ TextStyle (color: Colors .black.withOpacity (.3 )),
162+ errorStyle: TextStyle (
163+ color: Colors .red,
164+ ),
165+ ),
166+ keyboardType: TextInputType .phone,
167+ inputFormatters: [
168+ PhoneInputFormatter (
169+ allowEndlessPhone: true ,
170+ defaultCountryCode:
171+ _initialCountryDataFiltered? .countryCode,
172+ )
173+ ],
174+ ),
175+ )
176+ ],
177+ ),
124178 _getText (
125- _initialCountryData == null
179+ _initialCountryDataFiltered == null
126180 ? 'A country is not detected'
127- : 'The country is: ${_initialCountryData ?.country }' ,
181+ : 'The country is: ${_initialCountryDataFiltered ?.country }' ,
128182 ),
129183 SizedBox (
130184 height: 10.0 ,
0 commit comments