Skip to content

Commit

Permalink
array itemBuilder control
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilich6107 committed Dec 16, 2024
1 parent 68a72b5 commit 1cb1c8f
Show file tree
Hide file tree
Showing 41 changed files with 215 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/donate_action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pr-check-annotation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/pr-check-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr-check-generator-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../
8 changes: 4 additions & 4 deletions .github/workflows/pr-check-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 17 additions & 17 deletions packages/generator_tests/test/doc/array_nullable_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<dynamic> {
const ArrayNullableFormInheritedStreamer({
class AnnotatelessFormInheritedStreamer extends InheritedStreamer<dynamic> {
const AnnotatelessFormInheritedStreamer({
Key? key,
required this.form,
required Stream<dynamic> stream,
Expand All @@ -99,11 +99,11 @@ class ArrayNullableFormInheritedStreamer extends InheritedStreamer<dynamic> {
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,
Expand All @@ -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,
}) {
Expand Down Expand Up @@ -305,16 +305,16 @@ class ArrayNullableForm implements FormModel<ArrayNullable, ArrayNullable> {
List<String?>? get _someListValue => someListControl?.value;
List<String> get _emailListValue =>
emailListControl.rawValue.whereType<String>().toList();
emailListControl.value?.whereType<String>().toList() ?? [];
List<bool?> get _fruitListValue =>
fruitListControl.rawValue.whereType<bool?>().toList();
fruitListControl.value?.whereType<bool?>().toList() ?? [];
List<String?>? get _vegetablesListValue =>
vegetablesListControl?.rawValue.whereType<String?>().toList();
vegetablesListControl?.value?.whereType<String?>().toList() ?? [];
List<UserMode?>? get _modeListValue =>
modeListControl?.rawValue.whereType<UserMode?>().toList();
modeListControl?.value?.whereType<UserMode?>().toList() ?? [];
bool get containsSomeList {
try {
Expand Down
28 changes: 21 additions & 7 deletions packages/generator_tests/test/doc/delivery_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ class DeliveryListFormBuilder extends StatefulWidget {
class _DeliveryListFormBuilderState extends State<DeliveryListFormBuilder> {
late DeliveryListForm _formModel;
StreamSubscription<LogRecord>? _logSubscription;
@override
void initState() {
_formModel =
Expand All @@ -236,7 +238,7 @@ class _DeliveryListFormBuilderState extends State<DeliveryListFormBuilder> {
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
Expand Down Expand Up @@ -279,6 +281,7 @@ class _DeliveryListFormBuilderState extends State<DeliveryListFormBuilder> {
@override
void dispose() {
_formModel.form.dispose();
_logSubscription?.cancel();
super.dispose();
}
Expand All @@ -301,7 +304,7 @@ class _DeliveryListFormBuilderState extends State<DeliveryListFormBuilder> {
}
}
final _logDeliveryListForm = Logger('DeliveryListForm');
final _logDeliveryListForm = Logger.detached('DeliveryListForm');
class DeliveryListForm implements FormModel<DeliveryList, DeliveryList> {
DeliveryListForm(
Expand Down Expand Up @@ -836,7 +839,7 @@ class DeliveryListForm implements FormModel<DeliveryList, DeliveryList> {
disabled: false);
}
final _logDeliveryPointForm = Logger('DeliveryPointForm');
final _logDeliveryPointForm = Logger.detached('DeliveryPointForm');
class DeliveryPointForm implements FormModel<DeliveryPoint, DeliveryPoint> {
DeliveryPointForm(
Expand Down Expand Up @@ -1134,7 +1137,7 @@ class DeliveryPointForm implements FormModel<DeliveryPoint, DeliveryPoint> {
disabled: false);
}
final _logAddressForm = Logger('AddressForm');
final _logAddressForm = Logger.detached('AddressForm');
class AddressForm implements FormModel<Address, Address> {
AddressForm(
Expand Down Expand Up @@ -1460,7 +1463,7 @@ class AddressForm implements FormModel<Address, Address> {
disabled: false);
}
final _logClientForm = Logger('ClientForm');
final _logClientForm = Logger.detached('ClientForm');
class ClientForm implements FormModel<Client, Client> {
ClientForm(
Expand Down Expand Up @@ -1885,6 +1888,7 @@ class ReactiveDeliveryListFormArrayBuilder<
final Widget Function(
BuildContext context,
int i,
FormControl<ReactiveDeliveryListFormArrayBuilderT> control,
ReactiveDeliveryListFormArrayBuilderT? item,
DeliveryListForm formModel) itemBuilder;
Expand All @@ -1908,6 +1912,8 @@ class ReactiveDeliveryListFormArrayBuilder<
itemBuilder(
context,
i,
formArray.controls[i]
as FormControl<ReactiveDeliveryListFormArrayBuilderT>,
item,
formModel,
),
Expand Down Expand Up @@ -2124,6 +2130,8 @@ class _StandaloneDeliveryPointFormBuilderState
extends State<StandaloneDeliveryPointFormBuilder> {
late StandaloneDeliveryPointForm _formModel;
StreamSubscription<LogRecord>? _logSubscription;
@override
void initState() {
_formModel = StandaloneDeliveryPointForm(
Expand All @@ -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
Expand Down Expand Up @@ -2178,6 +2187,7 @@ class _StandaloneDeliveryPointFormBuilderState
@override
void dispose() {
_formModel.form.dispose();
_logSubscription?.cancel();
super.dispose();
}
Expand All @@ -2200,7 +2210,8 @@ class _StandaloneDeliveryPointFormBuilderState
}
}
final _logStandaloneDeliveryPointForm = Logger('StandaloneDeliveryPointForm');
final _logStandaloneDeliveryPointForm =
Logger.detached('StandaloneDeliveryPointForm');
class StandaloneDeliveryPointForm
implements FormModel<DeliveryPoint, DeliveryPoint> {
Expand Down Expand Up @@ -2523,6 +2534,7 @@ class ReactiveStandaloneDeliveryPointFormArrayBuilder<
final Widget Function(
BuildContext context,
int i,
FormControl<ReactiveStandaloneDeliveryPointFormArrayBuilderT> control,
ReactiveStandaloneDeliveryPointFormArrayBuilderT? item,
StandaloneDeliveryPointForm formModel) itemBuilder;
Expand All @@ -2546,6 +2558,8 @@ class ReactiveStandaloneDeliveryPointFormArrayBuilder<
itemBuilder(
context,
i,
formArray.controls[i] as FormControl<
ReactiveStandaloneDeliveryPointFormArrayBuilderT>,
item,
formModel,
),
Expand Down
4 changes: 4 additions & 0 deletions packages/reactive_forms_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [6.0.0-beta.16]

* expose control in itemBuilder

## [6.0.0-beta.15]

* rebase on main 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,12 @@ class ReactiveUrlFormArrayBuilder<ReactiveUrlFormArrayBuilderT>
final Widget Function(
BuildContext context, List<Widget> itemList, UrlForm formModel)? builder;

final Widget Function(BuildContext context, int i,
ReactiveUrlFormArrayBuilderT? item, UrlForm formModel) itemBuilder;
final Widget Function(
BuildContext context,
int i,
FormControl<ReactiveUrlFormArrayBuilderT> control,
ReactiveUrlFormArrayBuilderT? item,
UrlForm formModel) itemBuilder;

@override
Widget build(BuildContext context) {
Expand All @@ -836,6 +840,8 @@ class ReactiveUrlFormArrayBuilder<ReactiveUrlFormArrayBuilderT>
itemBuilder(
context,
i,
formArray.controls[i]
as FormControl<ReactiveUrlFormArrayBuilderT>,
item,
formModel,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,12 @@ class ReactiveUrlOFormArrayBuilder<ReactiveUrlOFormArrayBuilderT>
final Widget Function(
BuildContext context, List<Widget> itemList, UrlOForm formModel)? builder;

final Widget Function(BuildContext context, int i,
ReactiveUrlOFormArrayBuilderT? item, UrlOForm formModel) itemBuilder;
final Widget Function(
BuildContext context,
int i,
FormControl<ReactiveUrlOFormArrayBuilderT> control,
ReactiveUrlOFormArrayBuilderT? item,
UrlOForm formModel) itemBuilder;

@override
Widget build(BuildContext context) {
Expand All @@ -904,6 +908,8 @@ class ReactiveUrlOFormArrayBuilder<ReactiveUrlOFormArrayBuilderT>
itemBuilder(
context,
i,
formArray.controls[i]
as FormControl<ReactiveUrlOFormArrayBuilderT>,
item,
formModel,
),
Expand Down
Loading

0 comments on commit 1cb1c8f

Please sign in to comment.