Skip to content

Instantly share code, notes, and snippets.

@bizz84
Created August 10, 2021 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bizz84/07cb696d46e80627939d009e10ca37c9 to your computer and use it in GitHub Desktop.
Save bizz84/07cb696d46e80627939d009e10ca37c9 to your computer and use it in GitHub Desktop.
// review.dart
import 'package:freezed_annotation/freezed_annotation.dart';
part 'review.freezed.dart';
part 'review.g.dart';
@freezed
class Review with _$Review {
factory Review({
required double score,
String? review,
}) = _Review;
factory Review.fromJson(Map<String, dynamic> json) => _$ReviewFromJson(json);
}
// restaurant.dart
import 'package:freezed_annotation/freezed_annotation.dart';
import 'review.dart';
part 'restaurant.freezed.dart';
part 'restaurant.g.dart';
@freezed
class Restaurant with _$Restaurant {
factory Restaurant({
required String name,
required String cuisine,
@JsonKey(name: 'year_opened') int? yearOpened,
@Default([]) List<Review> reviews,
}) = _Restaurant;
factory Restaurant.fromJson(Map<String, dynamic> json) =>
_$RestaurantFromJson(json);
}
// review.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'review.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$_Review _$_$_ReviewFromJson(Map<String, dynamic> json) {
return _$_Review(
score: (json['score'] as num).toDouble(),
review: json['review'] as String?,
);
}
Map<String, dynamic> _$_$_ReviewToJson(_$_Review instance) => <String, dynamic>{
'score': instance.score,
'review': instance.review,
};
// review.freezed.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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
part of 'review.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 informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
Review _$ReviewFromJson(Map<String, dynamic> json) {
return _Review.fromJson(json);
}
/// @nodoc
class _$ReviewTearOff {
const _$ReviewTearOff();
_Review call({required double score, String? review}) {
return _Review(
score: score,
review: review,
);
}
Review fromJson(Map<String, Object> json) {
return Review.fromJson(json);
}
}
/// @nodoc
const $Review = _$ReviewTearOff();
/// @nodoc
mixin _$Review {
double get score => throw _privateConstructorUsedError;
String? get review => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ReviewCopyWith<Review> get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ReviewCopyWith<$Res> {
factory $ReviewCopyWith(Review value, $Res Function(Review) then) =
_$ReviewCopyWithImpl<$Res>;
$Res call({double score, String? review});
}
/// @nodoc
class _$ReviewCopyWithImpl<$Res> implements $ReviewCopyWith<$Res> {
_$ReviewCopyWithImpl(this._value, this._then);
final Review _value;
// ignore: unused_field
final $Res Function(Review) _then;
@override
$Res call({
Object? score = freezed,
Object? review = freezed,
}) {
return _then(_value.copyWith(
score: score == freezed
? _value.score
: score // ignore: cast_nullable_to_non_nullable
as double,
review: review == freezed
? _value.review
: review // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
abstract class _$ReviewCopyWith<$Res> implements $ReviewCopyWith<$Res> {
factory _$ReviewCopyWith(_Review value, $Res Function(_Review) then) =
__$ReviewCopyWithImpl<$Res>;
@override
$Res call({double score, String? review});
}
/// @nodoc
class __$ReviewCopyWithImpl<$Res> extends _$ReviewCopyWithImpl<$Res>
implements _$ReviewCopyWith<$Res> {
__$ReviewCopyWithImpl(_Review _value, $Res Function(_Review) _then)
: super(_value, (v) => _then(v as _Review));
@override
_Review get _value => super._value as _Review;
@override
$Res call({
Object? score = freezed,
Object? review = freezed,
}) {
return _then(_Review(
score: score == freezed
? _value.score
: score // ignore: cast_nullable_to_non_nullable
as double,
review: review == freezed
? _value.review
: review // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
@JsonSerializable()
class _$_Review implements _Review {
_$_Review({required this.score, this.review});
factory _$_Review.fromJson(Map<String, dynamic> json) =>
_$_$_ReviewFromJson(json);
@override
final double score;
@override
final String? review;
@override
String toString() {
return 'Review(score: $score, review: $review)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _Review &&
(identical(other.score, score) ||
const DeepCollectionEquality().equals(other.score, score)) &&
(identical(other.review, review) ||
const DeepCollectionEquality().equals(other.review, review)));
}
@override
int get hashCode =>
runtimeType.hashCode ^
const DeepCollectionEquality().hash(score) ^
const DeepCollectionEquality().hash(review);
@JsonKey(ignore: true)
@override
_$ReviewCopyWith<_Review> get copyWith =>
__$ReviewCopyWithImpl<_Review>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$_$_ReviewToJson(this);
}
}
abstract class _Review implements Review {
factory _Review({required double score, String? review}) = _$_Review;
factory _Review.fromJson(Map<String, dynamic> json) = _$_Review.fromJson;
@override
double get score => throw _privateConstructorUsedError;
@override
String? get review => throw _privateConstructorUsedError;
@override
@JsonKey(ignore: true)
_$ReviewCopyWith<_Review> get copyWith => throw _privateConstructorUsedError;
}
// restaurant.g.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'restaurant.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$_Restaurant _$_$_RestaurantFromJson(Map<String, dynamic> json) {
return _$_Restaurant(
name: json['name'] as String,
cuisine: json['cuisine'] as String,
yearOpened: json['yearOpened'] as int?,
reviews: (json['reviews'] as List<dynamic>?)
?.map((e) => Review.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
);
}
Map<String, dynamic> _$_$_RestaurantToJson(_$_Restaurant instance) =>
<String, dynamic>{
'name': instance.name,
'cuisine': instance.cuisine,
'yearOpened': instance.yearOpened,
'reviews': instance.reviews,
};
// restaurant.freezed.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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
part of 'restaurant.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 informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
Restaurant _$RestaurantFromJson(Map<String, dynamic> json) {
return _Restaurant.fromJson(json);
}
/// @nodoc
class _$RestaurantTearOff {
const _$RestaurantTearOff();
_Restaurant call(
{required String name,
required String cuisine,
int? yearOpened,
List<Review> reviews = const []}) {
return _Restaurant(
name: name,
cuisine: cuisine,
yearOpened: yearOpened,
reviews: reviews,
);
}
Restaurant fromJson(Map<String, Object> json) {
return Restaurant.fromJson(json);
}
}
/// @nodoc
const $Restaurant = _$RestaurantTearOff();
/// @nodoc
mixin _$Restaurant {
String get name => throw _privateConstructorUsedError;
String get cuisine => throw _privateConstructorUsedError;
int? get yearOpened => throw _privateConstructorUsedError;
List<Review> get reviews => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$RestaurantCopyWith<Restaurant> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $RestaurantCopyWith<$Res> {
factory $RestaurantCopyWith(
Restaurant value, $Res Function(Restaurant) then) =
_$RestaurantCopyWithImpl<$Res>;
$Res call(
{String name, String cuisine, int? yearOpened, List<Review> reviews});
}
/// @nodoc
class _$RestaurantCopyWithImpl<$Res> implements $RestaurantCopyWith<$Res> {
_$RestaurantCopyWithImpl(this._value, this._then);
final Restaurant _value;
// ignore: unused_field
final $Res Function(Restaurant) _then;
@override
$Res call({
Object? name = freezed,
Object? cuisine = freezed,
Object? yearOpened = freezed,
Object? reviews = freezed,
}) {
return _then(_value.copyWith(
name: name == freezed
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
cuisine: cuisine == freezed
? _value.cuisine
: cuisine // ignore: cast_nullable_to_non_nullable
as String,
yearOpened: yearOpened == freezed
? _value.yearOpened
: yearOpened // ignore: cast_nullable_to_non_nullable
as int?,
reviews: reviews == freezed
? _value.reviews
: reviews // ignore: cast_nullable_to_non_nullable
as List<Review>,
));
}
}
/// @nodoc
abstract class _$RestaurantCopyWith<$Res> implements $RestaurantCopyWith<$Res> {
factory _$RestaurantCopyWith(
_Restaurant value, $Res Function(_Restaurant) then) =
__$RestaurantCopyWithImpl<$Res>;
@override
$Res call(
{String name, String cuisine, int? yearOpened, List<Review> reviews});
}
/// @nodoc
class __$RestaurantCopyWithImpl<$Res> extends _$RestaurantCopyWithImpl<$Res>
implements _$RestaurantCopyWith<$Res> {
__$RestaurantCopyWithImpl(
_Restaurant _value, $Res Function(_Restaurant) _then)
: super(_value, (v) => _then(v as _Restaurant));
@override
_Restaurant get _value => super._value as _Restaurant;
@override
$Res call({
Object? name = freezed,
Object? cuisine = freezed,
Object? yearOpened = freezed,
Object? reviews = freezed,
}) {
return _then(_Restaurant(
name: name == freezed
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
cuisine: cuisine == freezed
? _value.cuisine
: cuisine // ignore: cast_nullable_to_non_nullable
as String,
yearOpened: yearOpened == freezed
? _value.yearOpened
: yearOpened // ignore: cast_nullable_to_non_nullable
as int?,
reviews: reviews == freezed
? _value.reviews
: reviews // ignore: cast_nullable_to_non_nullable
as List<Review>,
));
}
}
/// @nodoc
@JsonSerializable()
class _$_Restaurant implements _Restaurant {
_$_Restaurant(
{required this.name,
required this.cuisine,
this.yearOpened,
this.reviews = const []});
factory _$_Restaurant.fromJson(Map<String, dynamic> json) =>
_$_$_RestaurantFromJson(json);
@override
final String name;
@override
final String cuisine;
@override
final int? yearOpened;
@JsonKey(defaultValue: const [])
@override
final List<Review> reviews;
@override
String toString() {
return 'Restaurant(name: $name, cuisine: $cuisine, yearOpened: $yearOpened, reviews: $reviews)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other is _Restaurant &&
(identical(other.name, name) ||
const DeepCollectionEquality().equals(other.name, name)) &&
(identical(other.cuisine, cuisine) ||
const DeepCollectionEquality()
.equals(other.cuisine, cuisine)) &&
(identical(other.yearOpened, yearOpened) ||
const DeepCollectionEquality()
.equals(other.yearOpened, yearOpened)) &&
(identical(other.reviews, reviews) ||
const DeepCollectionEquality().equals(other.reviews, reviews)));
}
@override
int get hashCode =>
runtimeType.hashCode ^
const DeepCollectionEquality().hash(name) ^
const DeepCollectionEquality().hash(cuisine) ^
const DeepCollectionEquality().hash(yearOpened) ^
const DeepCollectionEquality().hash(reviews);
@JsonKey(ignore: true)
@override
_$RestaurantCopyWith<_Restaurant> get copyWith =>
__$RestaurantCopyWithImpl<_Restaurant>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$_$_RestaurantToJson(this);
}
}
abstract class _Restaurant implements Restaurant {
factory _Restaurant(
{required String name,
required String cuisine,
int? yearOpened,
List<Review> reviews}) = _$_Restaurant;
factory _Restaurant.fromJson(Map<String, dynamic> json) =
_$_Restaurant.fromJson;
@override
String get name => throw _privateConstructorUsedError;
@override
String get cuisine => throw _privateConstructorUsedError;
@override
int? get yearOpened => throw _privateConstructorUsedError;
@override
List<Review> get reviews => throw _privateConstructorUsedError;
@override
@JsonKey(ignore: true)
_$RestaurantCopyWith<_Restaurant> get copyWith =>
throw _privateConstructorUsedError;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment