From e1725009c0ac5c4af3de13895698f70154014c3d Mon Sep 17 00:00:00 2001 From: Vasiliy Ditsyak Date: Thu, 8 Aug 2024 16:51:44 +0200 Subject: [PATCH] rebase --- .../lib/docs/nested_generics/product.dart | 15 +-- .../docs/nested_generics/product.gform.dart | 93 +++++++++++++++++-- .../example/lib/docs/profile/profile.g.dart | 6 +- 3 files changed, 95 insertions(+), 19 deletions(-) diff --git a/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.dart b/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.dart index 4d011056..8a32c615 100644 --- a/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.dart +++ b/packages/reactive_forms_generator/example/lib/docs/nested_generics/product.dart @@ -2,11 +2,13 @@ import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:reactive_forms_annotations/reactive_forms_annotations.dart'; part 'product.freezed.dart'; + part 'product.gform.dart'; @freezed -@Rf() -class ProductDetails

with _$ProductDetails { +@Rf(output: false) +class ProductDetails

+ with _$ProductDetails { factory ProductDetails({ @RfControl() String? description, @Rf() Id? id, @@ -16,10 +18,9 @@ class ProductDetails

with _$ProductDetails - with _$Id { +class Id

with _$Id { factory Id({ @RfControl() String? companyName, @RfControl() String? name, @@ -31,7 +32,7 @@ class Id

@freezed class Product with _$Product { const factory Product({ - String? companyName, + String? companyName, String? name, }) = _Product; @@ -41,7 +42,7 @@ class Product with _$Product { @freezed class Cart with _$Cart { const factory Cart({ - Product? product, + Product? product, String? description, }) = _Cart; 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 967be42e..bdd2ae7b 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 @@ -1,7 +1,7 @@ // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint -// ignore_for_file: +// 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 'product.dart'; @@ -144,6 +144,8 @@ class _ProductDetailsFormBuilderState

extends State> { late ProductDetailsForm _formModel; + StreamSubscription? _logSubscription; + @override void initState() { _formModel = ProductDetailsForm( @@ -155,6 +157,34 @@ class _ProductDetailsFormBuilderState

widget.initState?.call(context, _formModel); + _logSubscription = _logProductDetailsForm.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 + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -170,6 +200,7 @@ class _ProductDetailsFormBuilderState

@override void dispose() { _formModel.form.dispose(); + _logSubscription?.cancel(); super.dispose(); } @@ -192,8 +223,10 @@ class _ProductDetailsFormBuilderState

} } +final _logProductDetailsForm = Logger.detached('ProductDetailsForm'); + class ProductDetailsForm

- implements FormModel> { + implements FormModel, ProductDetails> { ProductDetailsForm( this.form, this.path, @@ -403,9 +436,11 @@ class ProductDetailsForm

final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'ProductDetailsForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logProductDetailsForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return ProductDetails(description: _descriptionValue, id: _idValue); } @@ -453,6 +488,8 @@ class ProductDetailsForm

if (currentForm.valid) { onValid(model); } else { + _logProductDetailsForm.info('Errors'); + _logProductDetailsForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -502,7 +539,10 @@ class ProductDetailsForm

disabled: false); } -class IdForm

implements FormModel> { +final _logIdForm = Logger.detached('IdForm'); + +class IdForm

+ implements FormModel, Id> { IdForm( this.form, this.path, @@ -709,9 +749,11 @@ class IdForm

implements FormModel> { final isValid = !currentForm.hasErrors && currentForm.errors.isEmpty; if (!isValid) { - debugPrintStack( - label: - '[${path ?? 'IdForm'}]\n┗━ Avoid calling `model` on invalid form. Possible exceptions for non-nullable fields which should be guarded by `required` validator.'); + _logIdForm.warning( + 'Avoid calling `model` on invalid form.Possible exceptions for non-nullable fields which should be guarded by `required` validator.', + null, + StackTrace.current, + ); } return Id(companyName: _companyNameValue, name: _nameValue); } @@ -757,6 +799,8 @@ class IdForm

implements FormModel> { if (currentForm.valid) { onValid(model); } else { + _logIdForm.info('Errors'); + _logIdForm.info('┗━━ ${form.errors}'); onNotValid?.call(); } } @@ -1077,6 +1121,8 @@ class _IdFormBuilderState

extends State> { late IdForm _formModel; + StreamSubscription? _logSubscription; + @override void initState() { _formModel = IdForm(IdForm.formElements(widget.model), null); @@ -1087,6 +1133,34 @@ class _IdFormBuilderState

widget.initState?.call(context, _formModel); + _logSubscription = _logIdForm.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 + if (e.level >= Level.SEVERE) { + final Object? error = e.error; + FlutterError.dumpErrorToConsole( + FlutterErrorDetails( + exception: error is Exception ? error : Exception(error), + stack: e.stackTrace, + library: e.loggerName, + context: ErrorDescription(e.message), + ), + ); + } else { + log( + e.message, + time: e.time, + sequenceNumber: e.sequenceNumber, + level: e.level.value, + name: e.loggerName, + zone: e.zone, + error: e.error, + stackTrace: e.stackTrace, + ); + } + }); + super.initState(); } @@ -1102,6 +1176,7 @@ class _IdFormBuilderState

@override void dispose() { _formModel.form.dispose(); + _logSubscription?.cancel(); super.dispose(); } diff --git a/packages/reactive_forms_generator/example/lib/docs/profile/profile.g.dart b/packages/reactive_forms_generator/example/lib/docs/profile/profile.g.dart index 1ba0becc..5a8bbd0e 100644 --- a/packages/reactive_forms_generator/example/lib/docs/profile/profile.g.dart +++ b/packages/reactive_forms_generator/example/lib/docs/profile/profile.g.dart @@ -54,7 +54,7 @@ _$ThresholdSettingImpl _$$ThresholdSettingImplFromJson( Map json) => _$ThresholdSettingImpl( isEnabled: json['isEnabled'] as bool? ?? true, - value: (json['value'] as num?)?.toInt() ?? 2, + value: json['value'] as int? ?? 2, ); Map _$$ThresholdSettingImplToJson( @@ -67,7 +67,7 @@ Map _$$ThresholdSettingImplToJson( _$TimerSettingImpl _$$TimerSettingImplFromJson(Map json) => _$TimerSettingImpl( isEnabled: json['isEnabled'] as bool? ?? false, - value: (json['value'] as num?)?.toInt() ?? 5, + value: json['value'] as int? ?? 5, ); Map _$$TimerSettingImplToJson(_$TimerSettingImpl instance) => @@ -160,7 +160,7 @@ _$ChartingOrderValueImpl _$$ChartingOrderValueImplFromJson( chartingOrder: $enumDecodeNullable( _$ChartingOrderTypeEnumMap, json['chartingOrder']) ?? ChartingOrderType.arch, - selectedOption: (json['selectedOption'] as num?)?.toInt() ?? 0, + selectedOption: json['selectedOption'] as int? ?? 0, order: (json['order'] as List) .map((e) => (e as List) .map((e) => ScanOrder.fromJson(e as Map))