From 1cb1c8f04a5762a9c7f45db5f74f6c8525dfbf11 Mon Sep 17 00:00:00 2001 From: Vasiliy Ditsyak Date: Sat, 14 Dec 2024 18:04:22 +0100 Subject: [PATCH] array itemBuilder control --- .github/workflows/donate_action.yaml | 2 +- .github/workflows/pr-check-annotation.yml | 8 ++--- .github/workflows/pr-check-example.yml | 8 ++--- .github/workflows/pr-check-generator-test.yml | 6 ++-- .github/workflows/pr-check-generator.yml | 8 ++--- .../test/doc/array_nullable_test.dart | 34 +++++++++---------- .../test/doc/delivery_list_test.dart | 28 +++++++++++---- .../reactive_forms_generator/CHANGELOG.md | 4 +++ .../example/ios/Runner/AppDelegate.swift | 2 +- .../lib/docs/animated_url_list/url.gform.dart | 10 ++++-- .../animated_url_list/url_output.gform.dart | 10 ++++-- .../docs/annotateless/annotateless.gform.dart | 3 ++ .../annotateless_output.gform.dart | 3 ++ .../array_nullable/array_nullable.gform.dart | 3 ++ .../array_nullable/array_nullable_form.dart | 8 ++--- .../delivery_list/delivery_list.gform.dart | 6 ++++ .../lib/docs/freezed/freezed_class.gform.dart | 3 ++ .../freezed/freezed_class_output.gform.dart | 3 ++ .../example/lib/docs/freezed2/test.gform.dart | 10 ++++-- .../lib/docs/generic/generic.gform.dart | 10 ++++-- .../generic_status_list.gform.dart | 3 ++ .../example/lib/docs/group/group.gform.dart | 10 ++++-- .../example/lib/docs/login/login.gform.dart | 10 ++++-- .../lib/docs/login/login_output.gform.dart | 10 ++++-- .../login_extended/login_extended.gform.dart | 3 ++ .../login_extended_output.gform.dart | 3 ++ .../login_extended_nullable.gform.dart | 3 ++ .../login_extended_nullable_output.gform.dart | 3 ++ .../docs/mailing_list/mailing_list.gform.dart | 3 ++ .../docs/mailing_list/mailing_list_form.dart | 7 ++-- .../model_extends/model_extends.gform.dart | 3 ++ .../model_implements.gform.dart | 3 ++ .../example/lib/docs/nested/nested.gform.dart | 23 ++++++++++--- .../docs/nested_generics/product.gform.dart | 13 +++++-- .../lib/docs/profile/profile.gform.dart | 3 ++ .../renamed_basic/renamed_basic.gform.dart | 3 ++ .../renamed_basic_output.gform.dart | 3 ++ .../docs/user_profile/user_profile.gform.dart | 3 ++ .../user_profile_output.gform.dart | 3 ++ .../reactive_form_array_builder.dart | 3 +- .../reactive_forms_generator/pubspec.yaml | 2 +- 41 files changed, 215 insertions(+), 71 deletions(-) diff --git a/.github/workflows/donate_action.yaml b/.github/workflows/donate_action.yaml index 90a8aa26..a0005160 100644 --- a/.github/workflows/donate_action.yaml +++ b/.github/workflows/donate_action.yaml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Comment on issue uses: actions/github-script@v5 diff --git a/.github/workflows/pr-check-annotation.yml b/.github/workflows/pr-check-annotation.yml index 260f1ace..31c3368b 100644 --- a/.github/workflows/pr-check-annotation.yml +++ b/.github/workflows/pr-check-annotation.yml @@ -16,16 +16,16 @@ jobs: steps: - name: Setup Flutter - uses: subosito/flutter-action@v2.10.0 + uses: subosito/flutter-action@v2 with: - flutter-version: 3.19.5 + flutter-version: 3.24.5 channel: stable cache: true - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: reactive_forms_annotations => analyze - run: cd packages/reactive_forms_annotations && flutter pub get && flutter analyze + run: cd packages/reactive_forms_annotations && flutter pub get && flutter analyze --no-fatal-infos - name: reactive_forms_annotations => code formatting run: cd packages/reactive_forms_annotations && flutter pub get && dart format --set-exit-if-changed lib \ No newline at end of file diff --git a/.github/workflows/pr-check-example.yml b/.github/workflows/pr-check-example.yml index 9f1975a8..a8e498a3 100644 --- a/.github/workflows/pr-check-example.yml +++ b/.github/workflows/pr-check-example.yml @@ -16,19 +16,19 @@ jobs: steps: - name: Setup Flutter - uses: subosito/flutter-action@v2.10.0 + uses: subosito/flutter-action@v2 with: - flutter-version: 3.19.5 + flutter-version: 3.24.5 channel: stable cache: true - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: reactive_forms_generator => example => build_runner run: cd packages/reactive_forms_generator/example && flutter pub get && flutter pub run build_runner build --delete-conflicting-outputs - name: reactive_forms_generator => example => analyze - run: cd packages/reactive_forms_generator/example && flutter pub get && flutter analyze + run: cd packages/reactive_forms_generator/example && flutter pub get && flutter analyze --no-fatal-infos # - name: reactive_forms_generator => example => code formatting # run: cd packages/reactive_forms_generator/example && flutter pub get && dart format --set-exit-if-changed lib diff --git a/.github/workflows/pr-check-generator-test.yml b/.github/workflows/pr-check-generator-test.yml index 1d47d753..169fbdbf 100644 --- a/.github/workflows/pr-check-generator-test.yml +++ b/.github/workflows/pr-check-generator-test.yml @@ -16,13 +16,13 @@ jobs: steps: - name: Setup Flutter - uses: subosito/flutter-action@v2.10.0 + uses: subosito/flutter-action@v2 with: - flutter-version: 3.19.5 + flutter-version: 3.24.5 channel: stable cache: true - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: reactive_forms_generator => Code generation tests run: cd packages/generator_tests && flutter pub get && dart test && cd ../ \ No newline at end of file diff --git a/.github/workflows/pr-check-generator.yml b/.github/workflows/pr-check-generator.yml index dddeea24..ac2c1cae 100644 --- a/.github/workflows/pr-check-generator.yml +++ b/.github/workflows/pr-check-generator.yml @@ -16,16 +16,16 @@ jobs: steps: - name: Setup Flutter - uses: subosito/flutter-action@v2.10.0 + uses: subosito/flutter-action@v2 with: - flutter-version: 3.19.5 + flutter-version: 3.24.5 channel: stable cache: true - name: Check out repository code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: reactive_forms_generator => analyze - run: cd packages/reactive_forms_generator && flutter pub get && flutter analyze + run: cd packages/reactive_forms_generator && flutter pub get && flutter analyze --no-fatal-infos - name: reactive_forms_generator => code formatting run: cd packages/reactive_forms_generator && flutter pub get && dart format --set-exit-if-changed lib \ No newline at end of file diff --git a/packages/generator_tests/test/doc/array_nullable_test.dart b/packages/generator_tests/test/doc/array_nullable_test.dart index ed580e19..34e04ff8 100644 --- a/packages/generator_tests/test/doc/array_nullable_test.dart +++ b/packages/generator_tests/test/doc/array_nullable_test.dart @@ -58,14 +58,14 @@ const generatedFile = r'''// coverage:ignore-file // ignore_for_file: type=lint // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark -part of 'array_nullable.dart'; +part of 'annotateless.dart'; // ************************************************************************** // ReactiveFormsGenerator // ************************************************************************** -class ReactiveArrayNullableFormConsumer extends StatelessWidget { - const ReactiveArrayNullableFormConsumer({ +class ReactiveAnnotatelessFormConsumer extends StatelessWidget { + const ReactiveAnnotatelessFormConsumer({ Key? key, required this.builder, this.child, @@ -74,21 +74,21 @@ class ReactiveArrayNullableFormConsumer extends StatelessWidget { final Widget? child; final Widget Function( - BuildContext context, ArrayNullableForm formModel, Widget? child) builder; + BuildContext context, AnnotatelessForm formModel, Widget? child) builder; @override Widget build(BuildContext context) { - final formModel = ReactiveArrayNullableForm.of(context); + final formModel = ReactiveAnnotatelessForm.of(context); - if (formModel is! ArrayNullableForm) { + if (formModel is! AnnotatelessForm) { throw FormControlParentNotFoundException(this); } return builder(context, formModel, child); } } -class ArrayNullableFormInheritedStreamer extends InheritedStreamer { - const ArrayNullableFormInheritedStreamer({ +class AnnotatelessFormInheritedStreamer extends InheritedStreamer { + const AnnotatelessFormInheritedStreamer({ Key? key, required this.form, required Stream stream, @@ -99,11 +99,11 @@ class ArrayNullableFormInheritedStreamer extends InheritedStreamer { key: key, ); - final ArrayNullableForm form; + final AnnotatelessForm form; } -class ReactiveArrayNullableForm extends StatelessWidget { - const ReactiveArrayNullableForm({ +class ReactiveAnnotatelessForm extends StatelessWidget { + const ReactiveAnnotatelessForm({ Key? key, required this.form, required this.child, @@ -113,13 +113,13 @@ class ReactiveArrayNullableForm extends StatelessWidget { final Widget child; - final ArrayNullableForm form; + final AnnotatelessForm form; final bool Function(FormGroup formGroup)? canPop; final void Function(FormGroup formGroup, bool didPop)? onPopInvoked; - static ArrayNullableForm? of( + static AnnotatelessForm? of( BuildContext context, { bool listen = true, }) { @@ -305,16 +305,16 @@ class ArrayNullableForm implements FormModel { List? get _someListValue => someListControl?.value; List get _emailListValue => - emailListControl.rawValue.whereType().toList(); + emailListControl.value?.whereType().toList() ?? []; List get _fruitListValue => - fruitListControl.rawValue.whereType().toList(); + fruitListControl.value?.whereType().toList() ?? []; List? get _vegetablesListValue => - vegetablesListControl?.rawValue.whereType().toList(); + vegetablesListControl?.value?.whereType().toList() ?? []; List? get _modeListValue => - modeListControl?.rawValue.whereType().toList(); + modeListControl?.value?.whereType().toList() ?? []; bool get containsSomeList { try { diff --git a/packages/generator_tests/test/doc/delivery_list_test.dart b/packages/generator_tests/test/doc/delivery_list_test.dart index 117404a3..ce9ba885 100644 --- a/packages/generator_tests/test/doc/delivery_list_test.dart +++ b/packages/generator_tests/test/doc/delivery_list_test.dart @@ -225,6 +225,8 @@ class DeliveryListFormBuilder extends StatefulWidget { class _DeliveryListFormBuilderState extends State { late DeliveryListForm _formModel; + StreamSubscription? _logSubscription; + @override void initState() { _formModel = @@ -236,7 +238,7 @@ class _DeliveryListFormBuilderState extends State { widget.initState?.call(context, _formModel); - _logDeliveryListForm.onRecord.listen((LogRecord e) { + _logSubscription = _logDeliveryListForm.onRecord.listen((LogRecord e) { // use `dumpErrorToConsole` for severe messages to ensure that severe // exceptions are formatted consistently with other Flutter examples and // avoids printing duplicate exceptions @@ -279,6 +281,7 @@ class _DeliveryListFormBuilderState extends State { @override void dispose() { _formModel.form.dispose(); + _logSubscription?.cancel(); super.dispose(); } @@ -301,7 +304,7 @@ class _DeliveryListFormBuilderState extends State { } } -final _logDeliveryListForm = Logger('DeliveryListForm'); +final _logDeliveryListForm = Logger.detached('DeliveryListForm'); class DeliveryListForm implements FormModel { DeliveryListForm( @@ -836,7 +839,7 @@ class DeliveryListForm implements FormModel { disabled: false); } -final _logDeliveryPointForm = Logger('DeliveryPointForm'); +final _logDeliveryPointForm = Logger.detached('DeliveryPointForm'); class DeliveryPointForm implements FormModel { DeliveryPointForm( @@ -1134,7 +1137,7 @@ class DeliveryPointForm implements FormModel { disabled: false); } -final _logAddressForm = Logger('AddressForm'); +final _logAddressForm = Logger.detached('AddressForm'); class AddressForm implements FormModel { AddressForm( @@ -1460,7 +1463,7 @@ class AddressForm implements FormModel { disabled: false); } -final _logClientForm = Logger('ClientForm'); +final _logClientForm = Logger.detached('ClientForm'); class ClientForm implements FormModel { ClientForm( @@ -1885,6 +1888,7 @@ class ReactiveDeliveryListFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveDeliveryListFormArrayBuilderT? item, DeliveryListForm formModel) itemBuilder; @@ -1908,6 +1912,8 @@ class ReactiveDeliveryListFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), @@ -2124,6 +2130,8 @@ class _StandaloneDeliveryPointFormBuilderState extends State { late StandaloneDeliveryPointForm _formModel; + StreamSubscription? _logSubscription; + @override void initState() { _formModel = StandaloneDeliveryPointForm( @@ -2135,7 +2143,8 @@ class _StandaloneDeliveryPointFormBuilderState widget.initState?.call(context, _formModel); - _logStandaloneDeliveryPointForm.onRecord.listen((LogRecord e) { + _logSubscription = + _logStandaloneDeliveryPointForm.onRecord.listen((LogRecord e) { // use `dumpErrorToConsole` for severe messages to ensure that severe // exceptions are formatted consistently with other Flutter examples and // avoids printing duplicate exceptions @@ -2178,6 +2187,7 @@ class _StandaloneDeliveryPointFormBuilderState @override void dispose() { _formModel.form.dispose(); + _logSubscription?.cancel(); super.dispose(); } @@ -2200,7 +2210,8 @@ class _StandaloneDeliveryPointFormBuilderState } } -final _logStandaloneDeliveryPointForm = Logger('StandaloneDeliveryPointForm'); +final _logStandaloneDeliveryPointForm = + Logger.detached('StandaloneDeliveryPointForm'); class StandaloneDeliveryPointForm implements FormModel { @@ -2523,6 +2534,7 @@ class ReactiveStandaloneDeliveryPointFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveStandaloneDeliveryPointFormArrayBuilderT? item, StandaloneDeliveryPointForm formModel) itemBuilder; @@ -2546,6 +2558,8 @@ class ReactiveStandaloneDeliveryPointFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] as FormControl< + ReactiveStandaloneDeliveryPointFormArrayBuilderT>, item, formModel, ), diff --git a/packages/reactive_forms_generator/CHANGELOG.md b/packages/reactive_forms_generator/CHANGELOG.md index 383b08a8..a9285aa7 100644 --- a/packages/reactive_forms_generator/CHANGELOG.md +++ b/packages/reactive_forms_generator/CHANGELOG.md @@ -1,3 +1,7 @@ +## [6.0.0-beta.16] + +* expose control in itemBuilder + ## [6.0.0-beta.15] * rebase on main 2 diff --git a/packages/reactive_forms_generator/example/ios/Runner/AppDelegate.swift b/packages/reactive_forms_generator/example/ios/Runner/AppDelegate.swift index 70693e4a..b6363034 100644 --- a/packages/reactive_forms_generator/example/ios/Runner/AppDelegate.swift +++ b/packages/reactive_forms_generator/example/ios/Runner/AppDelegate.swift @@ -1,7 +1,7 @@ import UIKit import Flutter -@UIApplicationMain +@main @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, diff --git a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart index 5865581c..0db63ec4 100644 --- a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url.gform.dart @@ -813,8 +813,12 @@ class ReactiveUrlFormArrayBuilder final Widget Function( BuildContext context, List itemList, UrlForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveUrlFormArrayBuilderT? item, UrlForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveUrlFormArrayBuilderT? item, + UrlForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -836,6 +840,8 @@ class ReactiveUrlFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart index c5227bb1..cd93c9ab 100644 --- a/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/animated_url_list/url_output.gform.dart @@ -881,8 +881,12 @@ class ReactiveUrlOFormArrayBuilder final Widget Function( BuildContext context, List itemList, UrlOForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveUrlOFormArrayBuilderT? item, UrlOForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveUrlOFormArrayBuilderT? item, + UrlOForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -904,6 +908,8 @@ class ReactiveUrlOFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart index 4d157d34..bc6b57aa 100644 --- a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless.gform.dart @@ -511,6 +511,7 @@ class ReactiveAnnotatelessFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveAnnotatelessFormArrayBuilderT? item, AnnotatelessForm formModel) itemBuilder; @@ -534,6 +535,8 @@ class ReactiveAnnotatelessFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart index 12143a0b..6875ee1f 100644 --- a/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/annotateless/annotateless_output.gform.dart @@ -521,6 +521,7 @@ class ReactiveAnnotatelessOFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveAnnotatelessOFormArrayBuilderT? item, AnnotatelessOForm formModel) itemBuilder; @@ -544,6 +545,8 @@ class ReactiveAnnotatelessOFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart b/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart index 19387d0d..92aa6914 100644 --- a/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable.gform.dart @@ -1030,6 +1030,7 @@ class ReactiveArrayNullableFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveArrayNullableFormArrayBuilderT? item, ArrayNullableForm formModel) itemBuilder; @@ -1053,6 +1054,8 @@ class ReactiveArrayNullableFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable_form.dart b/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable_form.dart index 323d6942..e18f5274 100644 --- a/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable_form.dart +++ b/packages/reactive_forms_generator/example/lib/docs/array_nullable/array_nullable_form.dart @@ -50,9 +50,9 @@ class _ArrayNullableFormWidgetState extends State { Expanded( child: ReactiveArrayNullableFormArrayBuilder( formControl: formModel.emailListControl, - itemBuilder: (context, i, item, formModel) { + itemBuilder: (context, i, control, item, formModel) { return ReactiveTextField( - formControlName: i.toString(), + formControl: control, decoration: const InputDecoration(labelText: 'Email'), ); }, @@ -76,9 +76,9 @@ class _ArrayNullableFormWidgetState extends State { Expanded( child: ReactiveArrayNullableFormArrayBuilder( formControl: formModel.fruitListControl, - itemBuilder: (_, i, __, ___) { + itemBuilder: (_, i, control, __, ___) { return ReactiveCheckboxListTile( - formControlName: i.toString(), + formControl: control, title: Text(fruits[i]), ); }, diff --git a/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart b/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart index ee2bb408..7fe332e7 100644 --- a/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/delivery_list/delivery_list.gform.dart @@ -1800,6 +1800,7 @@ class ReactiveDeliveryListFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveDeliveryListFormArrayBuilderT? item, DeliveryListForm formModel) itemBuilder; @@ -1823,6 +1824,8 @@ class ReactiveDeliveryListFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), @@ -2443,6 +2446,7 @@ class ReactiveStandaloneDeliveryPointFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveStandaloneDeliveryPointFormArrayBuilderT? item, StandaloneDeliveryPointForm formModel) itemBuilder; @@ -2466,6 +2470,8 @@ class ReactiveStandaloneDeliveryPointFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] as FormControl< + ReactiveStandaloneDeliveryPointFormArrayBuilderT>, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart index cd3bc336..976ba42c 100644 --- a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class.gform.dart @@ -874,6 +874,7 @@ class ReactiveFreezedClassFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveFreezedClassFormArrayBuilderT? item, FreezedClassForm formModel) itemBuilder; @@ -897,6 +898,8 @@ class ReactiveFreezedClassFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart index b1a0efbc..841c147d 100644 --- a/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/freezed/freezed_class_output.gform.dart @@ -1094,6 +1094,7 @@ class ReactiveFreezedClassOFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveFreezedClassOFormArrayBuilderT? item, FreezedClassOForm formModel) itemBuilder; @@ -1117,6 +1118,8 @@ class ReactiveFreezedClassOFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart b/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart index 1e7efcb3..3598a56e 100644 --- a/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/freezed2/test.gform.dart @@ -529,8 +529,12 @@ class ReactiveTestFormArrayBuilder final Widget Function( BuildContext context, List itemList, TestForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveTestFormArrayBuilderT? item, TestForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveTestFormArrayBuilderT? item, + TestForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -552,6 +556,8 @@ class ReactiveTestFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart b/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart index 9f7a9eba..56b269fd 100644 --- a/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/generic/generic.gform.dart @@ -455,8 +455,12 @@ class ReactiveTagsFormArrayBuilder BuildContext context, List itemList, TagsForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveTagsFormArrayBuilderT? item, TagsForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveTagsFormArrayBuilderT? item, + TagsForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -478,6 +482,8 @@ class ReactiveTagsFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart b/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart index 8f9b63d6..ce2c206d 100644 --- a/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/generic_status_list/generic_status_list.gform.dart @@ -490,6 +490,7 @@ class ReactiveStatusListFormArrayBuilder control, ReactiveStatusListFormArrayBuilderT? item, StatusListForm formModel) itemBuilder; @@ -513,6 +514,8 @@ class ReactiveStatusListFormArrayBuilder, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart b/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart index c9017c97..cb3bda29 100644 --- a/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/group/group.gform.dart @@ -1843,8 +1843,12 @@ class ReactiveGroupFormArrayBuilder BuildContext context, List itemList, GroupForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveGroupFormArrayBuilderT? item, GroupForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveGroupFormArrayBuilderT? item, + GroupForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -1866,6 +1870,8 @@ class ReactiveGroupFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart index e63d3777..e5f8f88f 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login/login.gform.dart @@ -505,8 +505,12 @@ class ReactiveLoginFormArrayBuilder BuildContext context, List itemList, LoginForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveLoginFormArrayBuilderT? item, LoginForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveLoginFormArrayBuilderT? item, + LoginForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -528,6 +532,8 @@ class ReactiveLoginFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart index ab8f757f..aeb39f26 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login/login_output.gform.dart @@ -570,8 +570,12 @@ class ReactiveLoginOFormArrayBuilder BuildContext context, List itemList, LoginOForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveLoginOFormArrayBuilderT? item, LoginOForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveLoginOFormArrayBuilderT? item, + LoginOForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -593,6 +597,8 @@ class ReactiveLoginOFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart index 43e3aa9d..a9031a26 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended.gform.dart @@ -1074,6 +1074,7 @@ class ReactiveLoginExtendedFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveLoginExtendedFormArrayBuilderT? item, LoginExtendedForm formModel) itemBuilder; @@ -1097,6 +1098,8 @@ class ReactiveLoginExtendedFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart index 78747959..1d76da96 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended/login_extended_output.gform.dart @@ -1130,6 +1130,7 @@ class ReactiveLoginExtendedOFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveLoginExtendedOFormArrayBuilderT? item, LoginExtendedOForm formModel) itemBuilder; @@ -1153,6 +1154,8 @@ class ReactiveLoginExtendedOFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart index eec8b6cc..bc6ecd3a 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable.gform.dart @@ -1088,6 +1088,7 @@ class ReactiveLoginExtendedNullableFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveLoginExtendedNullableFormArrayBuilderT? item, LoginExtendedNullableForm formModel) itemBuilder; @@ -1111,6 +1112,8 @@ class ReactiveLoginExtendedNullableFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] as FormControl< + ReactiveLoginExtendedNullableFormArrayBuilderT>, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart index 0e605324..1bd0b163 100644 --- a/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/login_extended_nullable/login_extended_nullable_output.gform.dart @@ -1089,6 +1089,7 @@ class ReactiveLoginExtendedNullableOFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveLoginExtendedNullableOFormArrayBuilderT? item, LoginExtendedNullableOForm formModel) itemBuilder; @@ -1112,6 +1113,8 @@ class ReactiveLoginExtendedNullableOFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] as FormControl< + ReactiveLoginExtendedNullableOFormArrayBuilderT>, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart b/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart index b52966da..620934e7 100644 --- a/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list.gform.dart @@ -485,6 +485,7 @@ class ReactiveMailingListFormArrayBuilder final Widget Function( BuildContext context, int i, + FormControl control, ReactiveMailingListFormArrayBuilderT? item, MailingListForm formModel) itemBuilder; @@ -508,6 +509,8 @@ class ReactiveMailingListFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list_form.dart b/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list_form.dart index d782a44b..0ef063df 100644 --- a/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list_form.dart +++ b/packages/reactive_forms_generator/example/lib/docs/mailing_list/mailing_list_form.dart @@ -34,14 +34,13 @@ class _MailingListFormWidgetState extends State { Expanded( child: ReactiveMailingListFormArrayBuilder( formControl: formModel.emailListControl, - itemBuilder: (context, i, item, formModel) { + itemBuilder: (context, i, control, item, formModel) { return Row( children: [ Expanded( child: ReactiveTextField( - key: ValueKey( - formModel.emailListControl.controls[i]), - formControlName: i.toString(), + key: ObjectKey(control), + formControl: control, validationMessages: { 'email': (_) => 'Invalid email', }, diff --git a/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart b/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart index fb41c5cc..ca2ed5e3 100644 --- a/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/model_extends/model_extends.gform.dart @@ -511,6 +511,7 @@ class ReactiveModelExtendsFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveModelExtendsFormArrayBuilderT? item, ModelExtendsForm formModel) itemBuilder; @@ -534,6 +535,8 @@ class ReactiveModelExtendsFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart b/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart index 660ade7a..3d4da1ec 100644 --- a/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/model_implements/model_implements.gform.dart @@ -515,6 +515,7 @@ class ReactiveModelImplementsFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveModelImplementsFormArrayBuilderT? item, ModelImplementsForm formModel) itemBuilder; @@ -538,6 +539,8 @@ class ReactiveModelImplementsFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart b/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart index 6e96e5de..afd0b4cf 100644 --- a/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/nested/nested.gform.dart @@ -432,6 +432,7 @@ class ReactiveSubGroupFormArrayBuilder final Widget Function( BuildContext context, int i, + FormControl control, ReactiveSubGroupFormArrayBuilderT? item, SubGroupForm formModel) itemBuilder; @@ -455,6 +456,8 @@ class ReactiveSubGroupFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), @@ -1152,8 +1155,12 @@ class ReactiveGroupFormArrayBuilder BuildContext context, List itemList, GroupForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveGroupFormArrayBuilderT? item, GroupForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveGroupFormArrayBuilderT? item, + GroupForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -1175,6 +1182,8 @@ class ReactiveGroupFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), @@ -1794,8 +1803,12 @@ class ReactiveNestedFormArrayBuilder BuildContext context, List itemList, NestedForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveNestedFormArrayBuilderT? item, NestedForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveNestedFormArrayBuilderT? item, + NestedForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -1817,6 +1830,8 @@ class ReactiveNestedFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.gform.dart b/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.gform.dart index 3002095c..3134fef0 100644 --- a/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.gform.dart @@ -905,6 +905,7 @@ class ReactiveProductDetailsFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveProductDetailsFormArrayBuilderT? item, ProductDetailsForm formModel) itemBuilder; @@ -928,6 +929,8 @@ class ReactiveProductDetailsFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), @@ -1244,8 +1247,12 @@ class ReactiveIdFormArrayBuilder itemList, IdForm formModel)? builder; - final Widget Function(BuildContext context, int i, - ReactiveIdFormArrayBuilderT? item, IdForm formModel) itemBuilder; + final Widget Function( + BuildContext context, + int i, + FormControl control, + ReactiveIdFormArrayBuilderT? item, + IdForm formModel) itemBuilder; @override Widget build(BuildContext context) { @@ -1267,6 +1274,8 @@ class ReactiveIdFormArrayBuilder, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart b/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart index 9e928577..7ec48240 100644 --- a/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/profile/profile.gform.dart @@ -2279,6 +2279,7 @@ class ReactiveProfileFormArrayBuilder final Widget Function( BuildContext context, int i, + FormControl control, ReactiveProfileFormArrayBuilderT? item, ProfileForm formModel) itemBuilder; @@ -2302,6 +2303,8 @@ class ReactiveProfileFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart index a73697a6..20dd0d1e 100644 --- a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic.gform.dart @@ -511,6 +511,7 @@ class ReactiveSomeWiredNameFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveSomeWiredNameFormArrayBuilderT? item, SomeWiredNameForm formModel) itemBuilder; @@ -534,6 +535,8 @@ class ReactiveSomeWiredNameFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart index cdd52f09..c7da4bff 100644 --- a/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/renamed_basic/renamed_basic_output.gform.dart @@ -573,6 +573,7 @@ class ReactiveSomeWiredNameFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveSomeWiredNameFormArrayBuilderT? item, SomeWiredNameForm formModel) itemBuilder; @@ -596,6 +597,8 @@ class ReactiveSomeWiredNameFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart index 0ed2638a..65eb31dd 100644 --- a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile.gform.dart @@ -1192,6 +1192,7 @@ class ReactiveUserProfileFormArrayBuilder final Widget Function( BuildContext context, int i, + FormControl control, ReactiveUserProfileFormArrayBuilderT? item, UserProfileForm formModel) itemBuilder; @@ -1215,6 +1216,8 @@ class ReactiveUserProfileFormArrayBuilder itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart index ad5b3d6c..04cd285d 100644 --- a/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart +++ b/packages/reactive_forms_generator/example/lib/docs/user_profile/user_profile_output.gform.dart @@ -1272,6 +1272,7 @@ class ReactiveUserProfileOFormArrayBuilder< final Widget Function( BuildContext context, int i, + FormControl control, ReactiveUserProfileOFormArrayBuilderT? item, UserProfileOForm formModel) itemBuilder; @@ -1295,6 +1296,8 @@ class ReactiveUserProfileOFormArrayBuilder< itemBuilder( context, i, + formArray.controls[i] + as FormControl, item, formModel, ), diff --git a/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_array_builder.dart b/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_array_builder.dart index bc5127c5..f66e0777 100644 --- a/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_array_builder.dart +++ b/packages/reactive_forms_generator/lib/src/reactive_forms/reactive_form_array_builder.dart @@ -91,6 +91,7 @@ class ReactiveFormArrayBuilder { itemBuilder( context, i, + formArray.controls[i] as FormControl<$T>, item, formModel, ), @@ -140,7 +141,7 @@ class ReactiveFormArrayBuilder { ..name = 'itemBuilder' ..modifier = FieldModifier.final$ ..type = Reference( - 'Widget Function(BuildContext context, int i, $T? item, ${formGenerator.classNameFull} formModel)'), + 'Widget Function(BuildContext context, int i, FormControl<$T> control, $T? item, ${formGenerator.classNameFull} formModel)'), ), ]; diff --git a/packages/reactive_forms_generator/pubspec.yaml b/packages/reactive_forms_generator/pubspec.yaml index 13b0abf6..dcba2b28 100644 --- a/packages/reactive_forms_generator/pubspec.yaml +++ b/packages/reactive_forms_generator/pubspec.yaml @@ -2,7 +2,7 @@ name: reactive_forms_generator description: Generator for reactive_forms. Generates form classes based on model. repository: https://github.com/artflutter/reactive_forms_generator -version: 6.0.0-beta.15 +version: 6.0.0-beta.16 environment: sdk: ">=3.0.0 <4.0.0"