-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from IO-Design-Team/feature/support-freezed
Support freezed
- Loading branch information
Showing
10 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:hive_ce/hive.dart'; | ||
|
||
part 'freezed.freezed.dart'; | ||
part 'freezed.g.dart'; | ||
|
||
@freezed | ||
@HiveType(typeId: 100) | ||
class FreezedPerson with _$FreezedPerson { | ||
const factory FreezedPerson({ | ||
@HiveField(0) required String firstName, | ||
@HiveField(1) required String lastName, | ||
@HiveField(2) required int age, | ||
}) = _FreezedPerson; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
// coverage:ignore-file | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
// 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 'freezed.dart'; | ||
|
||
// ************************************************************************** | ||
// FreezedGenerator | ||
// ************************************************************************** | ||
|
||
T _$identity<T>(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#adding-getters-and-methods-to-our-models'); | ||
|
||
/// @nodoc | ||
mixin _$FreezedPerson { | ||
@HiveField(0) | ||
String get firstName => throw _privateConstructorUsedError; | ||
@HiveField(1) | ||
String get lastName => throw _privateConstructorUsedError; | ||
@HiveField(2) | ||
int get age => throw _privateConstructorUsedError; | ||
|
||
/// Create a copy of FreezedPerson | ||
/// with the given fields replaced by the non-null parameter values. | ||
@JsonKey(includeFromJson: false, includeToJson: false) | ||
$FreezedPersonCopyWith<FreezedPerson> get copyWith => | ||
throw _privateConstructorUsedError; | ||
} | ||
|
||
/// @nodoc | ||
abstract class $FreezedPersonCopyWith<$Res> { | ||
factory $FreezedPersonCopyWith( | ||
FreezedPerson value, $Res Function(FreezedPerson) then) = | ||
_$FreezedPersonCopyWithImpl<$Res, FreezedPerson>; | ||
@useResult | ||
$Res call( | ||
{@HiveField(0) String firstName, | ||
@HiveField(1) String lastName, | ||
@HiveField(2) int age}); | ||
} | ||
|
||
/// @nodoc | ||
class _$FreezedPersonCopyWithImpl<$Res, $Val extends FreezedPerson> | ||
implements $FreezedPersonCopyWith<$Res> { | ||
_$FreezedPersonCopyWithImpl(this._value, this._then); | ||
|
||
// ignore: unused_field | ||
final $Val _value; | ||
// ignore: unused_field | ||
final $Res Function($Val) _then; | ||
|
||
/// Create a copy of FreezedPerson | ||
/// with the given fields replaced by the non-null parameter values. | ||
@pragma('vm:prefer-inline') | ||
@override | ||
$Res call({ | ||
Object? firstName = null, | ||
Object? lastName = null, | ||
Object? age = null, | ||
}) { | ||
return _then(_value.copyWith( | ||
firstName: null == firstName | ||
? _value.firstName | ||
: firstName // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
lastName: null == lastName | ||
? _value.lastName | ||
: lastName // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
age: null == age | ||
? _value.age | ||
: age // ignore: cast_nullable_to_non_nullable | ||
as int, | ||
) as $Val); | ||
} | ||
} | ||
|
||
/// @nodoc | ||
abstract class _$$FreezedPersonImplCopyWith<$Res> | ||
implements $FreezedPersonCopyWith<$Res> { | ||
factory _$$FreezedPersonImplCopyWith( | ||
_$FreezedPersonImpl value, $Res Function(_$FreezedPersonImpl) then) = | ||
__$$FreezedPersonImplCopyWithImpl<$Res>; | ||
@override | ||
@useResult | ||
$Res call( | ||
{@HiveField(0) String firstName, | ||
@HiveField(1) String lastName, | ||
@HiveField(2) int age}); | ||
} | ||
|
||
/// @nodoc | ||
class __$$FreezedPersonImplCopyWithImpl<$Res> | ||
extends _$FreezedPersonCopyWithImpl<$Res, _$FreezedPersonImpl> | ||
implements _$$FreezedPersonImplCopyWith<$Res> { | ||
__$$FreezedPersonImplCopyWithImpl( | ||
_$FreezedPersonImpl _value, $Res Function(_$FreezedPersonImpl) _then) | ||
: super(_value, _then); | ||
|
||
/// Create a copy of FreezedPerson | ||
/// with the given fields replaced by the non-null parameter values. | ||
@pragma('vm:prefer-inline') | ||
@override | ||
$Res call({ | ||
Object? firstName = null, | ||
Object? lastName = null, | ||
Object? age = null, | ||
}) { | ||
return _then(_$FreezedPersonImpl( | ||
firstName: null == firstName | ||
? _value.firstName | ||
: firstName // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
lastName: null == lastName | ||
? _value.lastName | ||
: lastName // ignore: cast_nullable_to_non_nullable | ||
as String, | ||
age: null == age | ||
? _value.age | ||
: age // ignore: cast_nullable_to_non_nullable | ||
as int, | ||
)); | ||
} | ||
} | ||
|
||
/// @nodoc | ||
class _$FreezedPersonImpl implements _FreezedPerson { | ||
const _$FreezedPersonImpl( | ||
{@HiveField(0) required this.firstName, | ||
@HiveField(1) required this.lastName, | ||
@HiveField(2) required this.age}); | ||
|
||
@override | ||
@HiveField(0) | ||
final String firstName; | ||
@override | ||
@HiveField(1) | ||
final String lastName; | ||
@override | ||
@HiveField(2) | ||
final int age; | ||
|
||
@override | ||
String toString() { | ||
return 'FreezedPerson(firstName: $firstName, lastName: $lastName, age: $age)'; | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return identical(this, other) || | ||
(other.runtimeType == runtimeType && | ||
other is _$FreezedPersonImpl && | ||
(identical(other.firstName, firstName) || | ||
other.firstName == firstName) && | ||
(identical(other.lastName, lastName) || | ||
other.lastName == lastName) && | ||
(identical(other.age, age) || other.age == age)); | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash(runtimeType, firstName, lastName, age); | ||
|
||
/// Create a copy of FreezedPerson | ||
/// with the given fields replaced by the non-null parameter values. | ||
@JsonKey(includeFromJson: false, includeToJson: false) | ||
@override | ||
@pragma('vm:prefer-inline') | ||
_$$FreezedPersonImplCopyWith<_$FreezedPersonImpl> get copyWith => | ||
__$$FreezedPersonImplCopyWithImpl<_$FreezedPersonImpl>(this, _$identity); | ||
} | ||
|
||
abstract class _FreezedPerson implements FreezedPerson { | ||
const factory _FreezedPerson( | ||
{@HiveField(0) required final String firstName, | ||
@HiveField(1) required final String lastName, | ||
@HiveField(2) required final int age}) = _$FreezedPersonImpl; | ||
|
||
@override | ||
@HiveField(0) | ||
String get firstName; | ||
@override | ||
@HiveField(1) | ||
String get lastName; | ||
@override | ||
@HiveField(2) | ||
int get age; | ||
|
||
/// Create a copy of FreezedPerson | ||
/// with the given fields replaced by the non-null parameter values. | ||
@override | ||
@JsonKey(includeFromJson: false, includeToJson: false) | ||
_$$FreezedPersonImplCopyWith<_$FreezedPersonImpl> get copyWith => | ||
throw _privateConstructorUsedError; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import 'package:hive_ce/hive.dart'; | ||
import 'package:example/freezed.dart'; | ||
import 'package:example/main.dart'; | ||
|
||
extension HiveRegistrar on HiveInterface { | ||
void registerAdapters() { | ||
registerAdapter(FreezedPersonAdapter()); | ||
registerAdapter(PersonAdapter()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters