How can I access Country Name in ISO formate from ReactivePhoneFormField<PhoneNumber> widget? - flutter

How can I access Country Name or Nationality from the following after a country iso is selected by the user:
ReactivePhoneFormField<PhoneNumber>(
defaultCountry: IsoCode.GB,
decoration: InputDecoration(
labelText: 'Contact number', border: OutlineInputBorder()),
formControlName: 'phoneNumber',
// selectionHeightStyle: BoxHeightStyle.max,
// showFlagInInput: true,
//TODO? Phone verification. After signup?
/* validationMessages: (control) => {
ValidationMessage.required:
'Please provide your contact phone number',
'phoneNumber': 'Please enter a valid contact number'
},*/
countrySelectorNavigator:
CountrySelectorNavigator.modalBottomSheet(
favorites: [IsoCode.GB, IsoCode.ZA, IsoCode.US]),
),
As well , do tell that which of the following (onSaved,onSubmitted,onTap,onEditingComplete) functions available in this widget provide the samefunctionality as of onChanged function of textfield!

Related

Flutter searchfield -how to connect it to API-

I would like to know how to connect an API with the --searchfield-- since at the moment in the documentation I don't fully understand how it works, with an API
final List<String> _suggestions = ['Equipo', 'Marca', 'Modelo'];
and this serial is the one that normally has the documentation, but I can't connect it to an api like
https://jsonplaceholder.typicode.com/albums
SearchField(
controller: con.etiqueta,
suggestionState: Suggestion.expand,
suggestionAction: SuggestionAction.next,
suggestions:
_suggestions.map((e) => SearchFieldListItem(e)).toList(),
textInputAction: TextInputAction.next,
//controller: _searchController,
hint: 'Etiqueta',
// initialValue: SearchFieldListItem(_suggestions[2], SizedBox()),
maxSuggestionsInViewPort: 3,
itemHeight: 45,
onSuggestionTap: (x) {},
),

Use form_validator to check that the email is the same

I'm using the form_validator Flutter plugin to create a form block.
My form contains contains a lot of fields including Email and Email confirmation:
TextFormField(
validator: ValidationBuilder()
.email()
.maxLength(50)
.required()
.build(),
decoration: const InputDecoration(labelText: 'email'),
),
const SizedBox(height: 30),
TextFormField(
validator: ValidationBuilder()
.email()
.maxLength(50)
.required()
.build(),
decoration:
const InputDecoration(labelText: 'email confirmation'),
),
They are equals, the only thing that changes is the label. How can I add a check to the second field (EMAIL CONFIRMATION) that controls that it's the same value of the first one?
Example:
EMAIL: john.snow#gmail.com
EMAIL CONFIRMATION: john.snow#gmail.com
--> ok
EMAIL: john.snow#gmail.com
EMAIL CONFIRMATION: harry.potter#gmail.com
--> error
You could simply use 2 text controllers like say,
emailTextController
confirmEmailTextController
Make sure you add the following validator method in the Confirm Email TextFormField
validator: (value) {
if (value != emailTextController.text) {
return 'Email is not matching';
}
},
And you get the respective errorText, whose fontStyle can be adjusted.

Unable to access an error message corresponding to your field name Email Address.(is_uniqe)

$this->form_validation->set_rules('uemail', 'Email Address', 'required|trim|valid_email|is_uniqe[users.email]');

DateFormat class doesn't work for flutter_form_builder

I am using the flutter_form_builder package and for the FormBuilderDateTimePicker I am not able to introduce the "format" property. My code is:
FormBuilderDateTimePicker(
name: 'fechaYhora',
initialValue: DateTime.now(),
initialDate: DateTime.now(),
inputType: InputType.date,
format: DateFormat('EEEE, dd MMMM, yyyy'),
decoration: InputDecoration(
icon: Icon(Icons.calendar_today_sharp),
hintText: 'Elige una fecha y una hora',
),
)
However, I get the following error message:
The method 'DateFormat' isn't defined for the type '_DarCitaState'. (Documentation)
And it is correctly imported.
I was missing the following import file:
import 'package:intl/intl.dart';
Now it is fixed.

Flutter BLoC authentication

I am using flutter BLoC for my mobile app but in my login_form.dart i have an error
return TextField(
key: const Key('loginForm_emailInput_textField'),
onChanged: (email) => context.bloc<LoginCubit>().emailChanged(email),
focusNode: focusNode,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: 'Email',
helperText: '',
errorText: state.email.invalid ? 'Invalid Email' : null,
),
);
in this TextField area the following :
context.bloc<LoginCubit>().emailChanged(email),
the .bloc shows the following error
lib/screens/login/view/login_form.dart:109:44: Error: The method 'bloc' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('../../../Desktop/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'bloc'.
onChanged: (password) => context.bloc<LoginCubit>().passwordChanged(password),
can someone please advise a solution.
context.bloc has been deprecated.
You can read the example and make necessary changes.
Another way is to use BlocProvider
You can use it like this:
BlocProvider.of<BlocName>(context).eventCall()
context.bloc<LoginCubit>().emailChanged(email),
should be written as
context.read<LoginCubit>().emailChanged(email),