diff --git a/example/lib/models/freezed_union.freezed.dart b/example/lib/models/freezed_union.freezed.dart index 1fba332..e213982 100644 --- a/example/lib/models/freezed_union.freezed.dart +++ b/example/lib/models/freezed_union.freezed.dart @@ -1,3 +1,4 @@ +// dart format width=80 // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint @@ -9,301 +10,111 @@ part of 'freezed_union.dart'; // FreezedGenerator // ************************************************************************** +// dart format off T _$identity(T value) => value; -final _privateConstructorUsedError = UnsupportedError( - 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); - /// @nodoc mixin _$FreezedUnion { - @optionalTypeArgs - TResult when({ - required TResult Function() home, - required TResult Function(User user) user, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? home, - TResult? Function(User user)? user, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? home, - TResult Function(User user)? user, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult map({ - required TResult Function(Home value) home, - required TResult Function(UserUnion value) user, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Home value)? home, - TResult? Function(UserUnion value)? user, - }) => - throw _privateConstructorUsedError; - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Home value)? home, - TResult Function(UserUnion value)? user, - required TResult orElse(), - }) => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $FreezedUnionCopyWith<$Res> { - factory $FreezedUnionCopyWith( - FreezedUnion value, $Res Function(FreezedUnion) then) = - _$FreezedUnionCopyWithImpl<$Res, FreezedUnion>; -} - -/// @nodoc -class _$FreezedUnionCopyWithImpl<$Res, $Val extends FreezedUnion> - implements $FreezedUnionCopyWith<$Res> { - _$FreezedUnionCopyWithImpl(this._value, this._then); + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && other is FreezedUnion); + } - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; -} + @override + int get hashCode => runtimeType.hashCode; -/// @nodoc -abstract class _$$HomeImplCopyWith<$Res> { - factory _$$HomeImplCopyWith( - _$HomeImpl value, $Res Function(_$HomeImpl) then) = - __$$HomeImplCopyWithImpl<$Res>; + @override + String toString() { + return 'FreezedUnion()'; + } } /// @nodoc -class __$$HomeImplCopyWithImpl<$Res> - extends _$FreezedUnionCopyWithImpl<$Res, _$HomeImpl> - implements _$$HomeImplCopyWith<$Res> { - __$$HomeImplCopyWithImpl(_$HomeImpl _value, $Res Function(_$HomeImpl) _then) - : super(_value, _then); +class $FreezedUnionCopyWith<$Res> { + $FreezedUnionCopyWith(FreezedUnion _, $Res Function(FreezedUnion) __); } /// @nodoc -class _$HomeImpl implements Home { - const _$HomeImpl(); - - @override - String toString() { - return 'FreezedUnion.home()'; - } +class Home implements FreezedUnion { + const Home(); @override bool operator ==(Object other) { return identical(this, other) || - (other.runtimeType == runtimeType && other is _$HomeImpl); + (other.runtimeType == runtimeType && other is Home); } @override int get hashCode => runtimeType.hashCode; @override - @optionalTypeArgs - TResult when({ - required TResult Function() home, - required TResult Function(User user) user, - }) { - return home(); + String toString() { + return 'FreezedUnion.home()'; } +} - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? home, - TResult? Function(User user)? user, - }) { - return home?.call(); - } +/// @nodoc - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? home, - TResult Function(User user)? user, - required TResult orElse(), - }) { - if (home != null) { - return home(); - } - return orElse(); - } +class UserUnion implements FreezedUnion { + const UserUnion(this.user); + + final User user; + + /// Create a copy of FreezedUnion + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @pragma('vm:prefer-inline') + $UserUnionCopyWith get copyWith => + _$UserUnionCopyWithImpl(this, _$identity); @override - @optionalTypeArgs - TResult map({ - required TResult Function(Home value) home, - required TResult Function(UserUnion value) user, - }) { - return home(this); + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is UserUnion && + (identical(other.user, user) || other.user == user)); } @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Home value)? home, - TResult? Function(UserUnion value)? user, - }) { - return home?.call(this); - } + int get hashCode => Object.hash(runtimeType, user); @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Home value)? home, - TResult Function(UserUnion value)? user, - required TResult orElse(), - }) { - if (home != null) { - return home(this); - } - return orElse(); + String toString() { + return 'FreezedUnion.user(user: $user)'; } } -abstract class Home implements FreezedUnion { - const factory Home() = _$HomeImpl; -} - /// @nodoc -abstract class _$$UserUnionImplCopyWith<$Res> { - factory _$$UserUnionImplCopyWith( - _$UserUnionImpl value, $Res Function(_$UserUnionImpl) then) = - __$$UserUnionImplCopyWithImpl<$Res>; +abstract mixin class $UserUnionCopyWith<$Res> + implements $FreezedUnionCopyWith<$Res> { + factory $UserUnionCopyWith(UserUnion value, $Res Function(UserUnion) _then) = + _$UserUnionCopyWithImpl; @useResult $Res call({User user}); } /// @nodoc -class __$$UserUnionImplCopyWithImpl<$Res> - extends _$FreezedUnionCopyWithImpl<$Res, _$UserUnionImpl> - implements _$$UserUnionImplCopyWith<$Res> { - __$$UserUnionImplCopyWithImpl( - _$UserUnionImpl _value, $Res Function(_$UserUnionImpl) _then) - : super(_value, _then); +class _$UserUnionCopyWithImpl<$Res> implements $UserUnionCopyWith<$Res> { + _$UserUnionCopyWithImpl(this._self, this._then); + final UserUnion _self; + final $Res Function(UserUnion) _then; + + /// Create a copy of FreezedUnion + /// with the given fields replaced by the non-null parameter values. @pragma('vm:prefer-inline') - @override $Res call({ Object? user = null, }) { - return _then(_$UserUnionImpl( + return _then(UserUnion( null == user - ? _value.user + ? _self.user : user // ignore: cast_nullable_to_non_nullable as User, )); } } -/// @nodoc - -class _$UserUnionImpl implements UserUnion { - const _$UserUnionImpl(this.user); - - @override - final User user; - - @override - String toString() { - return 'FreezedUnion.user(user: $user)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$UserUnionImpl && - (identical(other.user, user) || other.user == user)); - } - - @override - int get hashCode => Object.hash(runtimeType, user); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$UserUnionImplCopyWith<_$UserUnionImpl> get copyWith => - __$$UserUnionImplCopyWithImpl<_$UserUnionImpl>(this, _$identity); - - @override - @optionalTypeArgs - TResult when({ - required TResult Function() home, - required TResult Function(User user) user, - }) { - return user(this.user); - } - - @override - @optionalTypeArgs - TResult? whenOrNull({ - TResult? Function()? home, - TResult? Function(User user)? user, - }) { - return user?.call(this.user); - } - - @override - @optionalTypeArgs - TResult maybeWhen({ - TResult Function()? home, - TResult Function(User user)? user, - required TResult orElse(), - }) { - if (user != null) { - return user(this.user); - } - return orElse(); - } - - @override - @optionalTypeArgs - TResult map({ - required TResult Function(Home value) home, - required TResult Function(UserUnion value) user, - }) { - return user(this); - } - - @override - @optionalTypeArgs - TResult? mapOrNull({ - TResult? Function(Home value)? home, - TResult? Function(UserUnion value)? user, - }) { - return user?.call(this); - } - - @override - @optionalTypeArgs - TResult maybeMap({ - TResult Function(Home value)? home, - TResult Function(UserUnion value)? user, - required TResult orElse(), - }) { - if (user != null) { - return user(this); - } - return orElse(); - } -} - -abstract class UserUnion implements FreezedUnion { - const factory UserUnion(final User user) = _$UserUnionImpl; - - User get user; - @JsonKey(ignore: true) - _$$UserUnionImplCopyWith<_$UserUnionImpl> get copyWith => - throw _privateConstructorUsedError; -} +// dart format on diff --git a/example/lib/user_mappr.auto_mappr.dart b/example/lib/user_mappr.auto_mappr.dart index 0dc7fd3..4bdc540 100644 --- a/example/lib/user_mappr.auto_mappr.dart +++ b/example/lib/user_mappr.auto_mappr.dart @@ -1,3 +1,4 @@ +// dart format width=80 // GENERATED CODE - DO NOT MODIFY BY HAND // ************************************************************************** @@ -64,16 +65,23 @@ class $UserMappr implements _i1.AutoMapprInterface { /// {@macro AutoMapprInterface:tryConvert} /// {@macro package:example/user_mappr.dart} @override - TARGET? tryConvert(SOURCE? model) { + TARGET? tryConvert( + SOURCE? model, { + void Function(Object error, StackTrace stackTrace, SOURCE? source)? + onMappingError, + }) { if (canConvert(recursive: false)) { - return _convert( + return _safeConvert( model, - canReturnNull: true, + onMappingError: onMappingError, ); } for (final mappr in _delegates) { if (mappr.canConvert()) { - return mappr.tryConvert(model); + return mappr.tryConvert( + model, + onMappingError: onMappingError, + ); } } @@ -103,13 +111,20 @@ class $UserMappr implements _i1.AutoMapprInterface { /// {@macro package:example/user_mappr.dart} @override Iterable tryConvertIterable( - Iterable model) { + Iterable model, { + void Function(Object error, StackTrace stackTrace, SOURCE? source)? + onMappingError, + }) { if (canConvert(recursive: false)) { - return model.map((item) => _convert(item, canReturnNull: true)); + return model.map( + (item) => _safeConvert(item, onMappingError: onMappingError)); } for (final mappr in _delegates) { if (mappr.canConvert()) { - return mappr.tryConvertIterable(model); + return mappr.tryConvertIterable( + model, + onMappingError: onMappingError, + ); } } @@ -138,13 +153,23 @@ class $UserMappr implements _i1.AutoMapprInterface { /// /// {@macro package:example/user_mappr.dart} @override - List tryConvertList(Iterable model) { + List tryConvertList( + Iterable model, { + void Function(Object error, StackTrace stackTrace, SOURCE? source)? + onMappingError, + }) { if (canConvert(recursive: false)) { - return tryConvertIterable(model).toList(); + return tryConvertIterable( + model, + onMappingError: onMappingError, + ).toList(); } for (final mappr in _delegates) { if (mappr.canConvert()) { - return mappr.tryConvertList(model); + return mappr.tryConvertList( + model, + onMappingError: onMappingError, + ); } } @@ -173,13 +198,23 @@ class $UserMappr implements _i1.AutoMapprInterface { /// /// {@macro package:example/user_mappr.dart} @override - Set tryConvertSet(Iterable model) { + Set tryConvertSet( + Iterable model, { + void Function(Object error, StackTrace stackTrace, SOURCE? source)? + onMappingError, + }) { if (canConvert(recursive: false)) { - return tryConvertIterable(model).toSet(); + return tryConvertIterable( + model, + onMappingError: onMappingError, + ).toSet(); } for (final mappr in _delegates) { if (mappr.canConvert()) { - return mappr.tryConvertSet(model); + return mappr.tryConvertSet( + model, + onMappingError: onMappingError, + ); } } @@ -204,6 +239,35 @@ class $UserMappr implements _i1.AutoMapprInterface { throw Exception('No ${model.runtimeType} -> $targetTypeOf mapping.'); } + TARGET? _safeConvert( + SOURCE? model, { + void Function(Object error, StackTrace stackTrace, SOURCE? source)? + onMappingError, + }) { + if (!useSafeMapping()) { + return _convert( + model, + canReturnNull: true, + ); + } + try { + return _convert( + model, + canReturnNull: true, + ); + } catch (e, s) { + onMappingError?.call(e, s, model); + return null; + } + } + + /// {@macro AutoMapprInterface:useSafeMapping} + /// {@macro package:example/user_mappr.dart} + @override + bool useSafeMapping() { + return false; + } + _i3.User _map__i2$UserDto_To__i3$User(_i2.UserDto? input) { final model = input; if (model == null) { diff --git a/example/pubspec.yaml b/example/pubspec.yaml index ebc265c..ca37f19 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -6,22 +6,22 @@ publish_to: "none" version: 1.0.0+1 environment: - sdk: ">=2.19.2 <3.0.0" + sdk: ">=3.0.0 <4.0.0" dependencies: - json_serializable: ^6.6.1 - json_annotation: ^4.8.1 - freezed_annotation: ^2.4.1 - auto_mappr_annotation: 2.1.0 + json_serializable: ^6.9.5 + json_annotation: ^4.9.0 + freezed_annotation: ^3.0.0 + auto_mappr_annotation: ^2.3.0 dev_dependencies: - build_runner: ^2.3.3 + build_runner: ^2.4.15 cached_build_runner: path: ../ - auto_mappr: 2.2.0 + auto_mappr: ^2.8.1 - flutter_lints: ^2.0.0 - freezed: ^2.4.6 + flutter_lints: ^5.0.0 + freezed: ^3.0.6 flutter: uses-material-design: true diff --git a/lib/model/code_file_generated_type.dart b/lib/model/code_file_generated_type.dart index e69de29..a30cee5 100644 --- a/lib/model/code_file_generated_type.dart +++ b/lib/model/code_file_generated_type.dart @@ -0,0 +1,4 @@ +enum CodeFileGeneratedType { + import, + partFile, +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 3cec055..e402455 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,17 +8,17 @@ environment: sdk: ">=3.0.0 <4.0.0" dependencies: - ansicolor: ^2.0.2 - args: ^2.4.0 + ansicolor: ^2.0.3 + args: ^2.7.0 barbecue: ^0.5.0 - crypto: ^3.0.1 - get_it: ^7.6.7 + crypto: ^3.0.6 + get_it: ^8.0.3 hive: ^2.2.3 - logger: ^1.1.0 - meta: ^1.11.0 - path: ^1.8.2 - synchronized: ^3.0.1 + logger: ^2.5.0 + meta: ^1.16.0 + path: ^1.9.1 + synchronized: ^3.3.1 text_table: ^4.0.3 dev_dependencies: - netglade_analysis: ^7.0.0 + netglade_analysis: ^16.1.0