Use form_validator to check that the email is the same - flutter

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.

Related

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

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!

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) {},
),

Flutter: Another exception was thrown: FormatException: Invalid double on '-' double

TextFormField(
decoration: InputDecoration(
labelText: 'Coordination - Latitude',
),
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'^(\-*\d+)?\.?\d{0,4}'))
],
onChanged: (v) {
lat(double.parse(v));
},
),
I have this value for the lat value. v is a string and when I add - then I get Another exception was thrown: FormatException: Invalid double error. How can I parse value with the - like -23.4348?
The reason is -(minus) alone will not be considered as num, so you are getting exceptions. But when you enter a number and then add a minus sign, you won't face the issue. So add conditions like this
onChanged: (v) {
if(v == '-' || v.isEmpty) {
return;
} else {
lat(double.parse(v));
}
}
Note: Your regex may need some tweaks.

Flutter Form Builder with Date Picker. No named parameter with the name 'anchorPoint'. anchorPoint: widget.anchorPoint,

I have a strange problem, I used Flutter Form Builder before and I can't fix any issues but when I use it in other project this is occurred with me.
I cleaned my project and run flutter pub get then flutter run but no thing is changed
this is complete error:
Error Image
FormBuilder(
key: _formKey,
child: Column(
children: [
FormBuilderTextField(
name: 'age',
decoration: const InputDecoration(
labelText:
'This value is passed along to the [Text.maxLines] attribute of the [Text] widget used to display the hint text.',
),
onChanged: (value) {},
// valueTransformer: (text) => num.tryParse(text),
keyboardType: TextInputType.number,
),
],
),
)
Error
../../FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_form_builder-7.2.1/lib/src/fields/for
m_builder_date_time_picker.dart:355:7: Error: No named parameter with the name 'anchorPoint'.
anchorPoint: widget.anchorPoint,
^^^^^^^^^^^
../../FlutterDev/flutter/packages/flutter/lib/src/material/date_picker.dart:133:19: Context: Found this
candidate, but the arguments don't match.
Future<DateTime?> showDatePicker({
^^^^^^^^^^^^^^
../../FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_form_builder-7.2.1/lib/src/fields/for
m_builder_date_time_picker.dart:373:7: Error: No named parameter with the name 'anchorPoint'.
anchorPoint: widget.anchorPoint,
^^^^^^^^^^^
../../FlutterDev/flutter/packages/flutter/lib/src/material/time_picker.dart:2413:20: Context: Found this
candidate, but the arguments don't match.
Future<TimeOfDay?> showTimePicker({
^^^^^^^^^^^^^^
add form_builder_extra_fields: ^8.2.0 dependencies.

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),