natintosh / intl_phone_number_input

MIT License
164 stars 496 forks source link

validation not working #304

Open remymumoh opened 2 years ago

remymumoh commented 2 years ago

How can you check if the number is not empty, been scratching my head for days. The error is not displayed

  IntlPhoneField(
                                    autovalidateMode: AutovalidateMode.onUserInteraction,
                                    decoration: InputDecoration(
                                      enabledBorder: OutlineInputBorder(
                                        borderRadius: BorderRadius.circular(60),
                                        borderSide: BorderSide(
                                            width: 1.0,
                                            style: BorderStyle.solid,
                                            color: WAPrimaryColor),
                                      ),
                                    ),
                                    inputFormatters: [
                                      FilteringTextInputFormatter.allow(
                                          RegExp("[0-9]"))],
                                    validator: (value) {
                                      if (value == null) {
                                        return 'Please enter your Phone Number';
                                      }
                                      return null;
                                    },
                                    initialCountryCode: 'NG',
                                    keyboardType: TextInputType.number,
                                    onChanged: (value) {
                                      phonenumber = value.number;
                                    },
                                  ),

this doesn't work, i is ignored

MarcelWilming commented 1 year ago

Validator passes a String? not a dynamic value. So you should check value.isNotEmpty or value.isEmpty

validator: (phoneNumber) { if (phoneNumber!.isEmpty) { return 'Phone Number Required'; } return null; },