reactive_forms icon indicating copy to clipboard operation
reactive_forms copied to clipboard

Add generics support to methods

Open codakkk opened this issue 5 months ago • 0 comments

Environment

Package version: ^17.0.1

Description

Actually some if not allreactive_forms methods don't support generics meaning we have to manually cast to the right type each time. A normal way to avoid lots of as casts is using generics.

What you'd like to happen:

final form = ReactiveForm.of<FormGroup>(context); // returns a FormGroup
final c = form.control<String>('control-name'); // returns a FormControl<String>
final formArray = form.control<FormArray>('array-name'); // returns a FormArray
// and so on

Alternatives you've considered: There's actually no alternative to "manual" casting.

final form = ReactiveForm.of(context) as FormGroup;
final c = form.control('control-name') as FormControl<String>
final formArray = form.control('array-name') as FormArray<dynamic>; // returns a FormArray

I can start working on this if makes sense to you.

codakkk avatar Sep 30 '24 15:09 codakkk