-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: type 'FormControl<dynamic>' is not a subtype of type 'int' #104
Comments
Hi @jbt-cii, This definition: FormGroup get form => FormGroup({
'my_field_01': FormControl<int>(validators: [Validators.required, Validators.number]),
'my_field_02': FormControl<String>(validators: [Validators.required]),
'my_field_03': FormControl<int>(validators: [Validators.required, Validators.number]),
}); is just OK. It doesn't throw an exception, so I guess you are having trouble defining the WIdget. Could you please show me the complete example, the definition of the form group, and how you bind the group with widgets? |
I have also released a new version update and let me know. Thanks |
Thank you for your answer. From the complexe example in the issue #101 I changed one thing:
And I added some logs when I tapped on the button in that function:
=> I see the log "Form button tapped!" and just after I have the error (I don't see the log "Form submitted!" |
And this is the whole error:
|
And this is the part for the button tapped that was not indicated in the issue #101:
|
Hi @jbt-cii, I have recreated your code the best I could, and everything works just fine. The only pieces I haven't tested was the ones related to your Cubit controllers. So I guess that maybe this function: myObjectCubit.mySpecificMethodCubit(this._myFields01, this._myFields02, this._myFields03); is expecting "int" as arguments maybe is expecting 2 "int" and a "String". but you are passing FormControl. form.control("my_field_01"); returns a FormControl not the value of the FormControle. To get access to the value you need to use: formControl.value: // get the control
this._myFields01 = form.control("my_field_01");
// print the value of the control
print(this._myFields01.value); So you may change the function call to: myObjectCubit.mySpecificMethodCubit(this._myFields01.value, this._myFields02.value, this._myFields03.value); |
Yes!
But it does not concern your package anymore :-D So the whole solution seems to be that:
Thanks a lot for your help!!! |
Hi @jbt-cii, Is good to know you have solved the issue. My last advice is to always try to declare you FormGroup within your controller/viewmodel/bloc/cubit/etc. That way you don't need a stateful widget because the cubit or bloc/controller will always hold the state and you have access to it from your widgets(using context.bloc). That way you declare your form group (that is the model of your inputs data) in the controller. |
Thank you for the advice. |
Hi @joanpablo, I try to follow your advice but I can't figure how to do that. I can't understand the way to link a "front" widget declaring a form (what I have to declare ? a classic "Form" widget or "ReactiveFormBuilder") with a Cubit/Bloc part in which I have to declare the FormGroup. Do you have an example of that type of usage? |
Hi @jbt-cii, I will give you a very simple example with Provider plugin, you can see that is the same with Cubit. // your bloc/controller/viewmodel/etc
class SignInViewModel {
final form = FormGroup({
'email': FormControl<String>(validators: [Validators.required, Validators.email]),
'password': FormControl<String>(validators: [Validators.required, Validators.minLength(8)])
});
void signIn() {
final credentials = this.form.value;
// ... make some business logic
// ...
}
} // simple sign-in view
class SignInScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final viewModel = Provider.of<SignInViewModel>(context, listen: false);
return ReactiveForm(
formGroup: viewModel.form,
child: Column(
children: <Widget>[
ReactiveTextField(
formControlName: 'email',
),
ReactiveTextField(
formControlName: 'password',
obscureText: true,
),
ReactiveFormConsumer(
builder: (context, form, child) {
return RaisedButton(
child: Text('Submit'),
// if form valid, sign-in
onPressed: form.valid ? viewModel.signIn : null,
);
},
),
],
),
);
}
} |
It was not so easy in my case but I succedeed defining it inside my Cubit part. |
Hello,
I open a new issue because I can't find a good way to mix controls for input fields containing "integer" values and fields containing "String" values.
Example:
I tried several things from the severals examples you gave.
I tried also that:
I tried also to use this:
I tried also to change the "FormGroup" declaration like this:
Each time I get an error like this one:
If you have any clue it will be great! :-)
The text was updated successfully, but these errors were encountered: