initial commit (migrated)

This commit is contained in:
fiatcode 2025-10-20 16:43:59 +07:00
commit b594facb51
143 changed files with 11057 additions and 0 deletions

View file

@ -0,0 +1,84 @@
import 'dart:convert';
import 'package:kuwot/core/env.dart';
import 'package:kuwot/core/network/network.dart';
import 'package:kuwot/features/quote/data/models/image_model.dart';
import 'package:kuwot/features/quote/data/models/quote_model.dart';
import 'package:kuwot/features/quote/data/models/translation_model.dart';
const imagesPerPage = 10;
abstract class KuwotApiRemoteDataSource {
Future<QuoteModel> getQuote({String? query});
Future<QuoteModel> getTranslatedQuote(int id, {String? query});
Future<List<ImageModel>> getRandomImages();
Future<List<TranslationModel>> getTranslations();
}
class KuwotApiRemoteApiImpl implements KuwotApiRemoteDataSource {
final Env env;
final Network network;
KuwotApiRemoteApiImpl({required this.env, required this.network});
@override
Future<QuoteModel> getQuote({String? query}) async {
final uri = Uri(
scheme: env.quoteApiScheme,
host: env.quoteApiHost,
port: env.quoteApiPort,
path: 'kuwot/v1/quotes/random',
query: query,
);
final response = await network.get(uri);
final jsonResponse = jsonDecode(response) as Map<String, dynamic>;
return QuoteModel.fromJson(jsonResponse);
}
@override
Future<QuoteModel> getTranslatedQuote(int id, {String? query}) async {
final uri = Uri(
scheme: env.quoteApiScheme,
host: env.quoteApiHost,
port: env.quoteApiPort,
path: 'kuwot/v1/quotes/$id',
query: query,
);
final response = await network.get(uri);
final jsonResponse = jsonDecode(response) as Map<String, dynamic>;
return QuoteModel.fromJson(jsonResponse);
}
@override
Future<List<ImageModel>> getRandomImages() async {
final uri = Uri(
scheme: env.quoteApiScheme,
host: env.quoteApiHost,
port: env.quoteApiPort,
path: 'kuwot/v1/images',
);
final response = await network.get(uri);
final jsonResponse = jsonDecode(response) as List;
return jsonResponse
.map((e) => ImageModel.fromJson(e as Map<String, dynamic>))
.toList();
}
@override
Future<List<TranslationModel>> getTranslations() async {
final uri = Uri(
scheme: env.quoteApiScheme,
host: env.quoteApiHost,
port: env.quoteApiPort,
path: 'kuwot/v1/translations',
);
final response = await network.get(uri);
final jsonResponse = jsonDecode(response) as List;
return jsonResponse
.map((e) => TranslationModel.fromJson(e as Map<String, dynamic>))
.toList();
}
}

View file

@ -0,0 +1,27 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'image_model.freezed.dart';
part 'image_model.g.dart';
@freezed
abstract class ImageModel with _$ImageModel {
const factory ImageModel({
required String id,
required String description,
required String color,
required String blurHash,
required String url,
required String originUrl,
required String authorName,
required String authorBio,
required String authorLocation,
required int authorTotalLikes,
required int authorTotalPhotos,
required bool authorIsForHire,
required String authorProfileImageUrl,
required String authorUrl,
}) = _ImageModel;
factory ImageModel.fromJson(Map<String, dynamic> json) =>
_$ImageModelFromJson(json);
}

View file

@ -0,0 +1,316 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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 'image_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$ImageModel {
String get id; String get description; String get color; String get blurHash; String get url; String get originUrl; String get authorName; String get authorBio; String get authorLocation; int get authorTotalLikes; int get authorTotalPhotos; bool get authorIsForHire; String get authorProfileImageUrl; String get authorUrl;
/// Create a copy of ImageModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$ImageModelCopyWith<ImageModel> get copyWith => _$ImageModelCopyWithImpl<ImageModel>(this as ImageModel, _$identity);
/// Serializes this ImageModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ImageModel&&(identical(other.id, id) || other.id == id)&&(identical(other.description, description) || other.description == description)&&(identical(other.color, color) || other.color == color)&&(identical(other.blurHash, blurHash) || other.blurHash == blurHash)&&(identical(other.url, url) || other.url == url)&&(identical(other.originUrl, originUrl) || other.originUrl == originUrl)&&(identical(other.authorName, authorName) || other.authorName == authorName)&&(identical(other.authorBio, authorBio) || other.authorBio == authorBio)&&(identical(other.authorLocation, authorLocation) || other.authorLocation == authorLocation)&&(identical(other.authorTotalLikes, authorTotalLikes) || other.authorTotalLikes == authorTotalLikes)&&(identical(other.authorTotalPhotos, authorTotalPhotos) || other.authorTotalPhotos == authorTotalPhotos)&&(identical(other.authorIsForHire, authorIsForHire) || other.authorIsForHire == authorIsForHire)&&(identical(other.authorProfileImageUrl, authorProfileImageUrl) || other.authorProfileImageUrl == authorProfileImageUrl)&&(identical(other.authorUrl, authorUrl) || other.authorUrl == authorUrl));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,description,color,blurHash,url,originUrl,authorName,authorBio,authorLocation,authorTotalLikes,authorTotalPhotos,authorIsForHire,authorProfileImageUrl,authorUrl);
@override
String toString() {
return 'ImageModel(id: $id, description: $description, color: $color, blurHash: $blurHash, url: $url, originUrl: $originUrl, authorName: $authorName, authorBio: $authorBio, authorLocation: $authorLocation, authorTotalLikes: $authorTotalLikes, authorTotalPhotos: $authorTotalPhotos, authorIsForHire: $authorIsForHire, authorProfileImageUrl: $authorProfileImageUrl, authorUrl: $authorUrl)';
}
}
/// @nodoc
abstract mixin class $ImageModelCopyWith<$Res> {
factory $ImageModelCopyWith(ImageModel value, $Res Function(ImageModel) _then) = _$ImageModelCopyWithImpl;
@useResult
$Res call({
String id, String description, String color, String blurHash, String url, String originUrl, String authorName, String authorBio, String authorLocation, int authorTotalLikes, int authorTotalPhotos, bool authorIsForHire, String authorProfileImageUrl, String authorUrl
});
}
/// @nodoc
class _$ImageModelCopyWithImpl<$Res>
implements $ImageModelCopyWith<$Res> {
_$ImageModelCopyWithImpl(this._self, this._then);
final ImageModel _self;
final $Res Function(ImageModel) _then;
/// Create a copy of ImageModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? description = null,Object? color = null,Object? blurHash = null,Object? url = null,Object? originUrl = null,Object? authorName = null,Object? authorBio = null,Object? authorLocation = null,Object? authorTotalLikes = null,Object? authorTotalPhotos = null,Object? authorIsForHire = null,Object? authorProfileImageUrl = null,Object? authorUrl = null,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,description: null == description ? _self.description : description // ignore: cast_nullable_to_non_nullable
as String,color: null == color ? _self.color : color // ignore: cast_nullable_to_non_nullable
as String,blurHash: null == blurHash ? _self.blurHash : blurHash // ignore: cast_nullable_to_non_nullable
as String,url: null == url ? _self.url : url // ignore: cast_nullable_to_non_nullable
as String,originUrl: null == originUrl ? _self.originUrl : originUrl // ignore: cast_nullable_to_non_nullable
as String,authorName: null == authorName ? _self.authorName : authorName // ignore: cast_nullable_to_non_nullable
as String,authorBio: null == authorBio ? _self.authorBio : authorBio // ignore: cast_nullable_to_non_nullable
as String,authorLocation: null == authorLocation ? _self.authorLocation : authorLocation // ignore: cast_nullable_to_non_nullable
as String,authorTotalLikes: null == authorTotalLikes ? _self.authorTotalLikes : authorTotalLikes // ignore: cast_nullable_to_non_nullable
as int,authorTotalPhotos: null == authorTotalPhotos ? _self.authorTotalPhotos : authorTotalPhotos // ignore: cast_nullable_to_non_nullable
as int,authorIsForHire: null == authorIsForHire ? _self.authorIsForHire : authorIsForHire // ignore: cast_nullable_to_non_nullable
as bool,authorProfileImageUrl: null == authorProfileImageUrl ? _self.authorProfileImageUrl : authorProfileImageUrl // ignore: cast_nullable_to_non_nullable
as String,authorUrl: null == authorUrl ? _self.authorUrl : authorUrl // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [ImageModel].
extension ImageModelPatterns on ImageModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _ImageModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _ImageModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _ImageModel value) $default,){
final _that = this;
switch (_that) {
case _ImageModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _ImageModel value)? $default,){
final _that = this;
switch (_that) {
case _ImageModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String description, String color, String blurHash, String url, String originUrl, String authorName, String authorBio, String authorLocation, int authorTotalLikes, int authorTotalPhotos, bool authorIsForHire, String authorProfileImageUrl, String authorUrl)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ImageModel() when $default != null:
return $default(_that.id,_that.description,_that.color,_that.blurHash,_that.url,_that.originUrl,_that.authorName,_that.authorBio,_that.authorLocation,_that.authorTotalLikes,_that.authorTotalPhotos,_that.authorIsForHire,_that.authorProfileImageUrl,_that.authorUrl);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String description, String color, String blurHash, String url, String originUrl, String authorName, String authorBio, String authorLocation, int authorTotalLikes, int authorTotalPhotos, bool authorIsForHire, String authorProfileImageUrl, String authorUrl) $default,) {final _that = this;
switch (_that) {
case _ImageModel():
return $default(_that.id,_that.description,_that.color,_that.blurHash,_that.url,_that.originUrl,_that.authorName,_that.authorBio,_that.authorLocation,_that.authorTotalLikes,_that.authorTotalPhotos,_that.authorIsForHire,_that.authorProfileImageUrl,_that.authorUrl);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String description, String color, String blurHash, String url, String originUrl, String authorName, String authorBio, String authorLocation, int authorTotalLikes, int authorTotalPhotos, bool authorIsForHire, String authorProfileImageUrl, String authorUrl)? $default,) {final _that = this;
switch (_that) {
case _ImageModel() when $default != null:
return $default(_that.id,_that.description,_that.color,_that.blurHash,_that.url,_that.originUrl,_that.authorName,_that.authorBio,_that.authorLocation,_that.authorTotalLikes,_that.authorTotalPhotos,_that.authorIsForHire,_that.authorProfileImageUrl,_that.authorUrl);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _ImageModel implements ImageModel {
const _ImageModel({required this.id, required this.description, required this.color, required this.blurHash, required this.url, required this.originUrl, required this.authorName, required this.authorBio, required this.authorLocation, required this.authorTotalLikes, required this.authorTotalPhotos, required this.authorIsForHire, required this.authorProfileImageUrl, required this.authorUrl});
factory _ImageModel.fromJson(Map<String, dynamic> json) => _$ImageModelFromJson(json);
@override final String id;
@override final String description;
@override final String color;
@override final String blurHash;
@override final String url;
@override final String originUrl;
@override final String authorName;
@override final String authorBio;
@override final String authorLocation;
@override final int authorTotalLikes;
@override final int authorTotalPhotos;
@override final bool authorIsForHire;
@override final String authorProfileImageUrl;
@override final String authorUrl;
/// Create a copy of ImageModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$ImageModelCopyWith<_ImageModel> get copyWith => __$ImageModelCopyWithImpl<_ImageModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$ImageModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ImageModel&&(identical(other.id, id) || other.id == id)&&(identical(other.description, description) || other.description == description)&&(identical(other.color, color) || other.color == color)&&(identical(other.blurHash, blurHash) || other.blurHash == blurHash)&&(identical(other.url, url) || other.url == url)&&(identical(other.originUrl, originUrl) || other.originUrl == originUrl)&&(identical(other.authorName, authorName) || other.authorName == authorName)&&(identical(other.authorBio, authorBio) || other.authorBio == authorBio)&&(identical(other.authorLocation, authorLocation) || other.authorLocation == authorLocation)&&(identical(other.authorTotalLikes, authorTotalLikes) || other.authorTotalLikes == authorTotalLikes)&&(identical(other.authorTotalPhotos, authorTotalPhotos) || other.authorTotalPhotos == authorTotalPhotos)&&(identical(other.authorIsForHire, authorIsForHire) || other.authorIsForHire == authorIsForHire)&&(identical(other.authorProfileImageUrl, authorProfileImageUrl) || other.authorProfileImageUrl == authorProfileImageUrl)&&(identical(other.authorUrl, authorUrl) || other.authorUrl == authorUrl));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,description,color,blurHash,url,originUrl,authorName,authorBio,authorLocation,authorTotalLikes,authorTotalPhotos,authorIsForHire,authorProfileImageUrl,authorUrl);
@override
String toString() {
return 'ImageModel(id: $id, description: $description, color: $color, blurHash: $blurHash, url: $url, originUrl: $originUrl, authorName: $authorName, authorBio: $authorBio, authorLocation: $authorLocation, authorTotalLikes: $authorTotalLikes, authorTotalPhotos: $authorTotalPhotos, authorIsForHire: $authorIsForHire, authorProfileImageUrl: $authorProfileImageUrl, authorUrl: $authorUrl)';
}
}
/// @nodoc
abstract mixin class _$ImageModelCopyWith<$Res> implements $ImageModelCopyWith<$Res> {
factory _$ImageModelCopyWith(_ImageModel value, $Res Function(_ImageModel) _then) = __$ImageModelCopyWithImpl;
@override @useResult
$Res call({
String id, String description, String color, String blurHash, String url, String originUrl, String authorName, String authorBio, String authorLocation, int authorTotalLikes, int authorTotalPhotos, bool authorIsForHire, String authorProfileImageUrl, String authorUrl
});
}
/// @nodoc
class __$ImageModelCopyWithImpl<$Res>
implements _$ImageModelCopyWith<$Res> {
__$ImageModelCopyWithImpl(this._self, this._then);
final _ImageModel _self;
final $Res Function(_ImageModel) _then;
/// Create a copy of ImageModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? description = null,Object? color = null,Object? blurHash = null,Object? url = null,Object? originUrl = null,Object? authorName = null,Object? authorBio = null,Object? authorLocation = null,Object? authorTotalLikes = null,Object? authorTotalPhotos = null,Object? authorIsForHire = null,Object? authorProfileImageUrl = null,Object? authorUrl = null,}) {
return _then(_ImageModel(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,description: null == description ? _self.description : description // ignore: cast_nullable_to_non_nullable
as String,color: null == color ? _self.color : color // ignore: cast_nullable_to_non_nullable
as String,blurHash: null == blurHash ? _self.blurHash : blurHash // ignore: cast_nullable_to_non_nullable
as String,url: null == url ? _self.url : url // ignore: cast_nullable_to_non_nullable
as String,originUrl: null == originUrl ? _self.originUrl : originUrl // ignore: cast_nullable_to_non_nullable
as String,authorName: null == authorName ? _self.authorName : authorName // ignore: cast_nullable_to_non_nullable
as String,authorBio: null == authorBio ? _self.authorBio : authorBio // ignore: cast_nullable_to_non_nullable
as String,authorLocation: null == authorLocation ? _self.authorLocation : authorLocation // ignore: cast_nullable_to_non_nullable
as String,authorTotalLikes: null == authorTotalLikes ? _self.authorTotalLikes : authorTotalLikes // ignore: cast_nullable_to_non_nullable
as int,authorTotalPhotos: null == authorTotalPhotos ? _self.authorTotalPhotos : authorTotalPhotos // ignore: cast_nullable_to_non_nullable
as int,authorIsForHire: null == authorIsForHire ? _self.authorIsForHire : authorIsForHire // ignore: cast_nullable_to_non_nullable
as bool,authorProfileImageUrl: null == authorProfileImageUrl ? _self.authorProfileImageUrl : authorProfileImageUrl // ignore: cast_nullable_to_non_nullable
as String,authorUrl: null == authorUrl ? _self.authorUrl : authorUrl // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View file

@ -0,0 +1,42 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'image_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_ImageModel _$ImageModelFromJson(Map<String, dynamic> json) => _ImageModel(
id: json['id'] as String,
description: json['description'] as String,
color: json['color'] as String,
blurHash: json['blurHash'] as String,
url: json['url'] as String,
originUrl: json['originUrl'] as String,
authorName: json['authorName'] as String,
authorBio: json['authorBio'] as String,
authorLocation: json['authorLocation'] as String,
authorTotalLikes: (json['authorTotalLikes'] as num).toInt(),
authorTotalPhotos: (json['authorTotalPhotos'] as num).toInt(),
authorIsForHire: json['authorIsForHire'] as bool,
authorProfileImageUrl: json['authorProfileImageUrl'] as String,
authorUrl: json['authorUrl'] as String,
);
Map<String, dynamic> _$ImageModelToJson(_ImageModel instance) =>
<String, dynamic>{
'id': instance.id,
'description': instance.description,
'color': instance.color,
'blurHash': instance.blurHash,
'url': instance.url,
'originUrl': instance.originUrl,
'authorName': instance.authorName,
'authorBio': instance.authorBio,
'authorLocation': instance.authorLocation,
'authorTotalLikes': instance.authorTotalLikes,
'authorTotalPhotos': instance.authorTotalPhotos,
'authorIsForHire': instance.authorIsForHire,
'authorProfileImageUrl': instance.authorProfileImageUrl,
'authorUrl': instance.authorUrl,
};

View file

@ -0,0 +1,58 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'photo_list_model.freezed.dart';
part 'photo_list_model.g.dart';
@freezed
abstract class PhotoListModel with _$PhotoListModel {
@JsonSerializable(fieldRename: FieldRename.snake)
const factory PhotoListModel({
required int page,
required int perPage,
required List<PhotoModel> photos,
required int totalResults,
required String nextPage,
}) = _PhotoListModel;
factory PhotoListModel.fromJson(Map<String, dynamic> json) =>
_$PhotoListModelFromJson(json);
}
@freezed
abstract class PhotoModel with _$PhotoModel {
@JsonSerializable(fieldRename: FieldRename.snake)
const factory PhotoModel({
required int id,
required int width,
required int height,
required String url,
required String photographer,
required String photographerUrl,
required int photographerId,
required String avgColor,
required SrcModel src,
required bool liked,
required String alt,
}) = _PhotoModel;
factory PhotoModel.fromJson(Map<String, dynamic> json) =>
_$PhotoModelFromJson(json);
}
@freezed
abstract class SrcModel with _$SrcModel {
@JsonSerializable(fieldRename: FieldRename.snake)
const factory SrcModel({
required String original,
required String large2x,
required String large,
required String medium,
required String small,
required String portrait,
required String landscape,
required String tiny,
}) = _SrcModel;
factory SrcModel.fromJson(Map<String, dynamic> json) =>
_$SrcModelFromJson(json);
}

View file

@ -0,0 +1,890 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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 'photo_list_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$PhotoListModel {
int get page; int get perPage; List<PhotoModel> get photos; int get totalResults; String get nextPage;
/// Create a copy of PhotoListModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$PhotoListModelCopyWith<PhotoListModel> get copyWith => _$PhotoListModelCopyWithImpl<PhotoListModel>(this as PhotoListModel, _$identity);
/// Serializes this PhotoListModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is PhotoListModel&&(identical(other.page, page) || other.page == page)&&(identical(other.perPage, perPage) || other.perPage == perPage)&&const DeepCollectionEquality().equals(other.photos, photos)&&(identical(other.totalResults, totalResults) || other.totalResults == totalResults)&&(identical(other.nextPage, nextPage) || other.nextPage == nextPage));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,page,perPage,const DeepCollectionEquality().hash(photos),totalResults,nextPage);
@override
String toString() {
return 'PhotoListModel(page: $page, perPage: $perPage, photos: $photos, totalResults: $totalResults, nextPage: $nextPage)';
}
}
/// @nodoc
abstract mixin class $PhotoListModelCopyWith<$Res> {
factory $PhotoListModelCopyWith(PhotoListModel value, $Res Function(PhotoListModel) _then) = _$PhotoListModelCopyWithImpl;
@useResult
$Res call({
int page, int perPage, List<PhotoModel> photos, int totalResults, String nextPage
});
}
/// @nodoc
class _$PhotoListModelCopyWithImpl<$Res>
implements $PhotoListModelCopyWith<$Res> {
_$PhotoListModelCopyWithImpl(this._self, this._then);
final PhotoListModel _self;
final $Res Function(PhotoListModel) _then;
/// Create a copy of PhotoListModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? page = null,Object? perPage = null,Object? photos = null,Object? totalResults = null,Object? nextPage = null,}) {
return _then(_self.copyWith(
page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable
as int,perPage: null == perPage ? _self.perPage : perPage // ignore: cast_nullable_to_non_nullable
as int,photos: null == photos ? _self.photos : photos // ignore: cast_nullable_to_non_nullable
as List<PhotoModel>,totalResults: null == totalResults ? _self.totalResults : totalResults // ignore: cast_nullable_to_non_nullable
as int,nextPage: null == nextPage ? _self.nextPage : nextPage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [PhotoListModel].
extension PhotoListModelPatterns on PhotoListModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _PhotoListModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _PhotoListModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _PhotoListModel value) $default,){
final _that = this;
switch (_that) {
case _PhotoListModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _PhotoListModel value)? $default,){
final _that = this;
switch (_that) {
case _PhotoListModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( int page, int perPage, List<PhotoModel> photos, int totalResults, String nextPage)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _PhotoListModel() when $default != null:
return $default(_that.page,_that.perPage,_that.photos,_that.totalResults,_that.nextPage);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( int page, int perPage, List<PhotoModel> photos, int totalResults, String nextPage) $default,) {final _that = this;
switch (_that) {
case _PhotoListModel():
return $default(_that.page,_that.perPage,_that.photos,_that.totalResults,_that.nextPage);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( int page, int perPage, List<PhotoModel> photos, int totalResults, String nextPage)? $default,) {final _that = this;
switch (_that) {
case _PhotoListModel() when $default != null:
return $default(_that.page,_that.perPage,_that.photos,_that.totalResults,_that.nextPage);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable(fieldRename: FieldRename.snake)
class _PhotoListModel implements PhotoListModel {
const _PhotoListModel({required this.page, required this.perPage, required final List<PhotoModel> photos, required this.totalResults, required this.nextPage}): _photos = photos;
factory _PhotoListModel.fromJson(Map<String, dynamic> json) => _$PhotoListModelFromJson(json);
@override final int page;
@override final int perPage;
final List<PhotoModel> _photos;
@override List<PhotoModel> get photos {
if (_photos is EqualUnmodifiableListView) return _photos;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_photos);
}
@override final int totalResults;
@override final String nextPage;
/// Create a copy of PhotoListModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$PhotoListModelCopyWith<_PhotoListModel> get copyWith => __$PhotoListModelCopyWithImpl<_PhotoListModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$PhotoListModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _PhotoListModel&&(identical(other.page, page) || other.page == page)&&(identical(other.perPage, perPage) || other.perPage == perPage)&&const DeepCollectionEquality().equals(other._photos, _photos)&&(identical(other.totalResults, totalResults) || other.totalResults == totalResults)&&(identical(other.nextPage, nextPage) || other.nextPage == nextPage));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,page,perPage,const DeepCollectionEquality().hash(_photos),totalResults,nextPage);
@override
String toString() {
return 'PhotoListModel(page: $page, perPage: $perPage, photos: $photos, totalResults: $totalResults, nextPage: $nextPage)';
}
}
/// @nodoc
abstract mixin class _$PhotoListModelCopyWith<$Res> implements $PhotoListModelCopyWith<$Res> {
factory _$PhotoListModelCopyWith(_PhotoListModel value, $Res Function(_PhotoListModel) _then) = __$PhotoListModelCopyWithImpl;
@override @useResult
$Res call({
int page, int perPage, List<PhotoModel> photos, int totalResults, String nextPage
});
}
/// @nodoc
class __$PhotoListModelCopyWithImpl<$Res>
implements _$PhotoListModelCopyWith<$Res> {
__$PhotoListModelCopyWithImpl(this._self, this._then);
final _PhotoListModel _self;
final $Res Function(_PhotoListModel) _then;
/// Create a copy of PhotoListModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? page = null,Object? perPage = null,Object? photos = null,Object? totalResults = null,Object? nextPage = null,}) {
return _then(_PhotoListModel(
page: null == page ? _self.page : page // ignore: cast_nullable_to_non_nullable
as int,perPage: null == perPage ? _self.perPage : perPage // ignore: cast_nullable_to_non_nullable
as int,photos: null == photos ? _self._photos : photos // ignore: cast_nullable_to_non_nullable
as List<PhotoModel>,totalResults: null == totalResults ? _self.totalResults : totalResults // ignore: cast_nullable_to_non_nullable
as int,nextPage: null == nextPage ? _self.nextPage : nextPage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
mixin _$PhotoModel {
int get id; int get width; int get height; String get url; String get photographer; String get photographerUrl; int get photographerId; String get avgColor; SrcModel get src; bool get liked; String get alt;
/// Create a copy of PhotoModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$PhotoModelCopyWith<PhotoModel> get copyWith => _$PhotoModelCopyWithImpl<PhotoModel>(this as PhotoModel, _$identity);
/// Serializes this PhotoModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is PhotoModel&&(identical(other.id, id) || other.id == id)&&(identical(other.width, width) || other.width == width)&&(identical(other.height, height) || other.height == height)&&(identical(other.url, url) || other.url == url)&&(identical(other.photographer, photographer) || other.photographer == photographer)&&(identical(other.photographerUrl, photographerUrl) || other.photographerUrl == photographerUrl)&&(identical(other.photographerId, photographerId) || other.photographerId == photographerId)&&(identical(other.avgColor, avgColor) || other.avgColor == avgColor)&&(identical(other.src, src) || other.src == src)&&(identical(other.liked, liked) || other.liked == liked)&&(identical(other.alt, alt) || other.alt == alt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,width,height,url,photographer,photographerUrl,photographerId,avgColor,src,liked,alt);
@override
String toString() {
return 'PhotoModel(id: $id, width: $width, height: $height, url: $url, photographer: $photographer, photographerUrl: $photographerUrl, photographerId: $photographerId, avgColor: $avgColor, src: $src, liked: $liked, alt: $alt)';
}
}
/// @nodoc
abstract mixin class $PhotoModelCopyWith<$Res> {
factory $PhotoModelCopyWith(PhotoModel value, $Res Function(PhotoModel) _then) = _$PhotoModelCopyWithImpl;
@useResult
$Res call({
int id, int width, int height, String url, String photographer, String photographerUrl, int photographerId, String avgColor, SrcModel src, bool liked, String alt
});
$SrcModelCopyWith<$Res> get src;
}
/// @nodoc
class _$PhotoModelCopyWithImpl<$Res>
implements $PhotoModelCopyWith<$Res> {
_$PhotoModelCopyWithImpl(this._self, this._then);
final PhotoModel _self;
final $Res Function(PhotoModel) _then;
/// Create a copy of PhotoModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? width = null,Object? height = null,Object? url = null,Object? photographer = null,Object? photographerUrl = null,Object? photographerId = null,Object? avgColor = null,Object? src = null,Object? liked = null,Object? alt = null,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as int,width: null == width ? _self.width : width // ignore: cast_nullable_to_non_nullable
as int,height: null == height ? _self.height : height // ignore: cast_nullable_to_non_nullable
as int,url: null == url ? _self.url : url // ignore: cast_nullable_to_non_nullable
as String,photographer: null == photographer ? _self.photographer : photographer // ignore: cast_nullable_to_non_nullable
as String,photographerUrl: null == photographerUrl ? _self.photographerUrl : photographerUrl // ignore: cast_nullable_to_non_nullable
as String,photographerId: null == photographerId ? _self.photographerId : photographerId // ignore: cast_nullable_to_non_nullable
as int,avgColor: null == avgColor ? _self.avgColor : avgColor // ignore: cast_nullable_to_non_nullable
as String,src: null == src ? _self.src : src // ignore: cast_nullable_to_non_nullable
as SrcModel,liked: null == liked ? _self.liked : liked // ignore: cast_nullable_to_non_nullable
as bool,alt: null == alt ? _self.alt : alt // ignore: cast_nullable_to_non_nullable
as String,
));
}
/// Create a copy of PhotoModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$SrcModelCopyWith<$Res> get src {
return $SrcModelCopyWith<$Res>(_self.src, (value) {
return _then(_self.copyWith(src: value));
});
}
}
/// Adds pattern-matching-related methods to [PhotoModel].
extension PhotoModelPatterns on PhotoModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _PhotoModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _PhotoModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _PhotoModel value) $default,){
final _that = this;
switch (_that) {
case _PhotoModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _PhotoModel value)? $default,){
final _that = this;
switch (_that) {
case _PhotoModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( int id, int width, int height, String url, String photographer, String photographerUrl, int photographerId, String avgColor, SrcModel src, bool liked, String alt)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _PhotoModel() when $default != null:
return $default(_that.id,_that.width,_that.height,_that.url,_that.photographer,_that.photographerUrl,_that.photographerId,_that.avgColor,_that.src,_that.liked,_that.alt);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( int id, int width, int height, String url, String photographer, String photographerUrl, int photographerId, String avgColor, SrcModel src, bool liked, String alt) $default,) {final _that = this;
switch (_that) {
case _PhotoModel():
return $default(_that.id,_that.width,_that.height,_that.url,_that.photographer,_that.photographerUrl,_that.photographerId,_that.avgColor,_that.src,_that.liked,_that.alt);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( int id, int width, int height, String url, String photographer, String photographerUrl, int photographerId, String avgColor, SrcModel src, bool liked, String alt)? $default,) {final _that = this;
switch (_that) {
case _PhotoModel() when $default != null:
return $default(_that.id,_that.width,_that.height,_that.url,_that.photographer,_that.photographerUrl,_that.photographerId,_that.avgColor,_that.src,_that.liked,_that.alt);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable(fieldRename: FieldRename.snake)
class _PhotoModel implements PhotoModel {
const _PhotoModel({required this.id, required this.width, required this.height, required this.url, required this.photographer, required this.photographerUrl, required this.photographerId, required this.avgColor, required this.src, required this.liked, required this.alt});
factory _PhotoModel.fromJson(Map<String, dynamic> json) => _$PhotoModelFromJson(json);
@override final int id;
@override final int width;
@override final int height;
@override final String url;
@override final String photographer;
@override final String photographerUrl;
@override final int photographerId;
@override final String avgColor;
@override final SrcModel src;
@override final bool liked;
@override final String alt;
/// Create a copy of PhotoModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$PhotoModelCopyWith<_PhotoModel> get copyWith => __$PhotoModelCopyWithImpl<_PhotoModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$PhotoModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _PhotoModel&&(identical(other.id, id) || other.id == id)&&(identical(other.width, width) || other.width == width)&&(identical(other.height, height) || other.height == height)&&(identical(other.url, url) || other.url == url)&&(identical(other.photographer, photographer) || other.photographer == photographer)&&(identical(other.photographerUrl, photographerUrl) || other.photographerUrl == photographerUrl)&&(identical(other.photographerId, photographerId) || other.photographerId == photographerId)&&(identical(other.avgColor, avgColor) || other.avgColor == avgColor)&&(identical(other.src, src) || other.src == src)&&(identical(other.liked, liked) || other.liked == liked)&&(identical(other.alt, alt) || other.alt == alt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,width,height,url,photographer,photographerUrl,photographerId,avgColor,src,liked,alt);
@override
String toString() {
return 'PhotoModel(id: $id, width: $width, height: $height, url: $url, photographer: $photographer, photographerUrl: $photographerUrl, photographerId: $photographerId, avgColor: $avgColor, src: $src, liked: $liked, alt: $alt)';
}
}
/// @nodoc
abstract mixin class _$PhotoModelCopyWith<$Res> implements $PhotoModelCopyWith<$Res> {
factory _$PhotoModelCopyWith(_PhotoModel value, $Res Function(_PhotoModel) _then) = __$PhotoModelCopyWithImpl;
@override @useResult
$Res call({
int id, int width, int height, String url, String photographer, String photographerUrl, int photographerId, String avgColor, SrcModel src, bool liked, String alt
});
@override $SrcModelCopyWith<$Res> get src;
}
/// @nodoc
class __$PhotoModelCopyWithImpl<$Res>
implements _$PhotoModelCopyWith<$Res> {
__$PhotoModelCopyWithImpl(this._self, this._then);
final _PhotoModel _self;
final $Res Function(_PhotoModel) _then;
/// Create a copy of PhotoModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? width = null,Object? height = null,Object? url = null,Object? photographer = null,Object? photographerUrl = null,Object? photographerId = null,Object? avgColor = null,Object? src = null,Object? liked = null,Object? alt = null,}) {
return _then(_PhotoModel(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as int,width: null == width ? _self.width : width // ignore: cast_nullable_to_non_nullable
as int,height: null == height ? _self.height : height // ignore: cast_nullable_to_non_nullable
as int,url: null == url ? _self.url : url // ignore: cast_nullable_to_non_nullable
as String,photographer: null == photographer ? _self.photographer : photographer // ignore: cast_nullable_to_non_nullable
as String,photographerUrl: null == photographerUrl ? _self.photographerUrl : photographerUrl // ignore: cast_nullable_to_non_nullable
as String,photographerId: null == photographerId ? _self.photographerId : photographerId // ignore: cast_nullable_to_non_nullable
as int,avgColor: null == avgColor ? _self.avgColor : avgColor // ignore: cast_nullable_to_non_nullable
as String,src: null == src ? _self.src : src // ignore: cast_nullable_to_non_nullable
as SrcModel,liked: null == liked ? _self.liked : liked // ignore: cast_nullable_to_non_nullable
as bool,alt: null == alt ? _self.alt : alt // ignore: cast_nullable_to_non_nullable
as String,
));
}
/// Create a copy of PhotoModel
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$SrcModelCopyWith<$Res> get src {
return $SrcModelCopyWith<$Res>(_self.src, (value) {
return _then(_self.copyWith(src: value));
});
}
}
/// @nodoc
mixin _$SrcModel {
String get original; String get large2x; String get large; String get medium; String get small; String get portrait; String get landscape; String get tiny;
/// Create a copy of SrcModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$SrcModelCopyWith<SrcModel> get copyWith => _$SrcModelCopyWithImpl<SrcModel>(this as SrcModel, _$identity);
/// Serializes this SrcModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is SrcModel&&(identical(other.original, original) || other.original == original)&&(identical(other.large2x, large2x) || other.large2x == large2x)&&(identical(other.large, large) || other.large == large)&&(identical(other.medium, medium) || other.medium == medium)&&(identical(other.small, small) || other.small == small)&&(identical(other.portrait, portrait) || other.portrait == portrait)&&(identical(other.landscape, landscape) || other.landscape == landscape)&&(identical(other.tiny, tiny) || other.tiny == tiny));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,original,large2x,large,medium,small,portrait,landscape,tiny);
@override
String toString() {
return 'SrcModel(original: $original, large2x: $large2x, large: $large, medium: $medium, small: $small, portrait: $portrait, landscape: $landscape, tiny: $tiny)';
}
}
/// @nodoc
abstract mixin class $SrcModelCopyWith<$Res> {
factory $SrcModelCopyWith(SrcModel value, $Res Function(SrcModel) _then) = _$SrcModelCopyWithImpl;
@useResult
$Res call({
String original, String large2x, String large, String medium, String small, String portrait, String landscape, String tiny
});
}
/// @nodoc
class _$SrcModelCopyWithImpl<$Res>
implements $SrcModelCopyWith<$Res> {
_$SrcModelCopyWithImpl(this._self, this._then);
final SrcModel _self;
final $Res Function(SrcModel) _then;
/// Create a copy of SrcModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? original = null,Object? large2x = null,Object? large = null,Object? medium = null,Object? small = null,Object? portrait = null,Object? landscape = null,Object? tiny = null,}) {
return _then(_self.copyWith(
original: null == original ? _self.original : original // ignore: cast_nullable_to_non_nullable
as String,large2x: null == large2x ? _self.large2x : large2x // ignore: cast_nullable_to_non_nullable
as String,large: null == large ? _self.large : large // ignore: cast_nullable_to_non_nullable
as String,medium: null == medium ? _self.medium : medium // ignore: cast_nullable_to_non_nullable
as String,small: null == small ? _self.small : small // ignore: cast_nullable_to_non_nullable
as String,portrait: null == portrait ? _self.portrait : portrait // ignore: cast_nullable_to_non_nullable
as String,landscape: null == landscape ? _self.landscape : landscape // ignore: cast_nullable_to_non_nullable
as String,tiny: null == tiny ? _self.tiny : tiny // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [SrcModel].
extension SrcModelPatterns on SrcModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _SrcModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _SrcModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _SrcModel value) $default,){
final _that = this;
switch (_that) {
case _SrcModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _SrcModel value)? $default,){
final _that = this;
switch (_that) {
case _SrcModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String original, String large2x, String large, String medium, String small, String portrait, String landscape, String tiny)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _SrcModel() when $default != null:
return $default(_that.original,_that.large2x,_that.large,_that.medium,_that.small,_that.portrait,_that.landscape,_that.tiny);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String original, String large2x, String large, String medium, String small, String portrait, String landscape, String tiny) $default,) {final _that = this;
switch (_that) {
case _SrcModel():
return $default(_that.original,_that.large2x,_that.large,_that.medium,_that.small,_that.portrait,_that.landscape,_that.tiny);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String original, String large2x, String large, String medium, String small, String portrait, String landscape, String tiny)? $default,) {final _that = this;
switch (_that) {
case _SrcModel() when $default != null:
return $default(_that.original,_that.large2x,_that.large,_that.medium,_that.small,_that.portrait,_that.landscape,_that.tiny);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable(fieldRename: FieldRename.snake)
class _SrcModel implements SrcModel {
const _SrcModel({required this.original, required this.large2x, required this.large, required this.medium, required this.small, required this.portrait, required this.landscape, required this.tiny});
factory _SrcModel.fromJson(Map<String, dynamic> json) => _$SrcModelFromJson(json);
@override final String original;
@override final String large2x;
@override final String large;
@override final String medium;
@override final String small;
@override final String portrait;
@override final String landscape;
@override final String tiny;
/// Create a copy of SrcModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$SrcModelCopyWith<_SrcModel> get copyWith => __$SrcModelCopyWithImpl<_SrcModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$SrcModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _SrcModel&&(identical(other.original, original) || other.original == original)&&(identical(other.large2x, large2x) || other.large2x == large2x)&&(identical(other.large, large) || other.large == large)&&(identical(other.medium, medium) || other.medium == medium)&&(identical(other.small, small) || other.small == small)&&(identical(other.portrait, portrait) || other.portrait == portrait)&&(identical(other.landscape, landscape) || other.landscape == landscape)&&(identical(other.tiny, tiny) || other.tiny == tiny));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,original,large2x,large,medium,small,portrait,landscape,tiny);
@override
String toString() {
return 'SrcModel(original: $original, large2x: $large2x, large: $large, medium: $medium, small: $small, portrait: $portrait, landscape: $landscape, tiny: $tiny)';
}
}
/// @nodoc
abstract mixin class _$SrcModelCopyWith<$Res> implements $SrcModelCopyWith<$Res> {
factory _$SrcModelCopyWith(_SrcModel value, $Res Function(_SrcModel) _then) = __$SrcModelCopyWithImpl;
@override @useResult
$Res call({
String original, String large2x, String large, String medium, String small, String portrait, String landscape, String tiny
});
}
/// @nodoc
class __$SrcModelCopyWithImpl<$Res>
implements _$SrcModelCopyWith<$Res> {
__$SrcModelCopyWithImpl(this._self, this._then);
final _SrcModel _self;
final $Res Function(_SrcModel) _then;
/// Create a copy of SrcModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? original = null,Object? large2x = null,Object? large = null,Object? medium = null,Object? small = null,Object? portrait = null,Object? landscape = null,Object? tiny = null,}) {
return _then(_SrcModel(
original: null == original ? _self.original : original // ignore: cast_nullable_to_non_nullable
as String,large2x: null == large2x ? _self.large2x : large2x // ignore: cast_nullable_to_non_nullable
as String,large: null == large ? _self.large : large // ignore: cast_nullable_to_non_nullable
as String,medium: null == medium ? _self.medium : medium // ignore: cast_nullable_to_non_nullable
as String,small: null == small ? _self.small : small // ignore: cast_nullable_to_non_nullable
as String,portrait: null == portrait ? _self.portrait : portrait // ignore: cast_nullable_to_non_nullable
as String,landscape: null == landscape ? _self.landscape : landscape // ignore: cast_nullable_to_non_nullable
as String,tiny: null == tiny ? _self.tiny : tiny // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View file

@ -0,0 +1,78 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'photo_list_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_PhotoListModel _$PhotoListModelFromJson(Map<String, dynamic> json) =>
_PhotoListModel(
page: (json['page'] as num).toInt(),
perPage: (json['per_page'] as num).toInt(),
photos: (json['photos'] as List<dynamic>)
.map((e) => PhotoModel.fromJson(e as Map<String, dynamic>))
.toList(),
totalResults: (json['total_results'] as num).toInt(),
nextPage: json['next_page'] as String,
);
Map<String, dynamic> _$PhotoListModelToJson(_PhotoListModel instance) =>
<String, dynamic>{
'page': instance.page,
'per_page': instance.perPage,
'photos': instance.photos,
'total_results': instance.totalResults,
'next_page': instance.nextPage,
};
_PhotoModel _$PhotoModelFromJson(Map<String, dynamic> json) => _PhotoModel(
id: (json['id'] as num).toInt(),
width: (json['width'] as num).toInt(),
height: (json['height'] as num).toInt(),
url: json['url'] as String,
photographer: json['photographer'] as String,
photographerUrl: json['photographer_url'] as String,
photographerId: (json['photographer_id'] as num).toInt(),
avgColor: json['avg_color'] as String,
src: SrcModel.fromJson(json['src'] as Map<String, dynamic>),
liked: json['liked'] as bool,
alt: json['alt'] as String,
);
Map<String, dynamic> _$PhotoModelToJson(_PhotoModel instance) =>
<String, dynamic>{
'id': instance.id,
'width': instance.width,
'height': instance.height,
'url': instance.url,
'photographer': instance.photographer,
'photographer_url': instance.photographerUrl,
'photographer_id': instance.photographerId,
'avg_color': instance.avgColor,
'src': instance.src,
'liked': instance.liked,
'alt': instance.alt,
};
_SrcModel _$SrcModelFromJson(Map<String, dynamic> json) => _SrcModel(
original: json['original'] as String,
large2x: json['large2x'] as String,
large: json['large'] as String,
medium: json['medium'] as String,
small: json['small'] as String,
portrait: json['portrait'] as String,
landscape: json['landscape'] as String,
tiny: json['tiny'] as String,
);
Map<String, dynamic> _$SrcModelToJson(_SrcModel instance) => <String, dynamic>{
'original': instance.original,
'large2x': instance.large2x,
'large': instance.large,
'medium': instance.medium,
'small': instance.small,
'portrait': instance.portrait,
'landscape': instance.landscape,
'tiny': instance.tiny,
};

View file

@ -0,0 +1,17 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'quote_model.freezed.dart';
part 'quote_model.g.dart';
@freezed
abstract class QuoteModel with _$QuoteModel {
@JsonSerializable(fieldRename: FieldRename.snake)
const factory QuoteModel({
required int id,
required String text,
required String author,
}) = _QuoteModel;
factory QuoteModel.fromJson(Map<String, dynamic> json) =>
_$QuoteModelFromJson(json);
}

View file

@ -0,0 +1,283 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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 'quote_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$QuoteModel {
int get id; String get text; String get author;
/// Create a copy of QuoteModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$QuoteModelCopyWith<QuoteModel> get copyWith => _$QuoteModelCopyWithImpl<QuoteModel>(this as QuoteModel, _$identity);
/// Serializes this QuoteModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is QuoteModel&&(identical(other.id, id) || other.id == id)&&(identical(other.text, text) || other.text == text)&&(identical(other.author, author) || other.author == author));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,text,author);
@override
String toString() {
return 'QuoteModel(id: $id, text: $text, author: $author)';
}
}
/// @nodoc
abstract mixin class $QuoteModelCopyWith<$Res> {
factory $QuoteModelCopyWith(QuoteModel value, $Res Function(QuoteModel) _then) = _$QuoteModelCopyWithImpl;
@useResult
$Res call({
int id, String text, String author
});
}
/// @nodoc
class _$QuoteModelCopyWithImpl<$Res>
implements $QuoteModelCopyWith<$Res> {
_$QuoteModelCopyWithImpl(this._self, this._then);
final QuoteModel _self;
final $Res Function(QuoteModel) _then;
/// Create a copy of QuoteModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? text = null,Object? author = null,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as int,text: null == text ? _self.text : text // ignore: cast_nullable_to_non_nullable
as String,author: null == author ? _self.author : author // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [QuoteModel].
extension QuoteModelPatterns on QuoteModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _QuoteModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _QuoteModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _QuoteModel value) $default,){
final _that = this;
switch (_that) {
case _QuoteModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _QuoteModel value)? $default,){
final _that = this;
switch (_that) {
case _QuoteModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( int id, String text, String author)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _QuoteModel() when $default != null:
return $default(_that.id,_that.text,_that.author);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( int id, String text, String author) $default,) {final _that = this;
switch (_that) {
case _QuoteModel():
return $default(_that.id,_that.text,_that.author);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( int id, String text, String author)? $default,) {final _that = this;
switch (_that) {
case _QuoteModel() when $default != null:
return $default(_that.id,_that.text,_that.author);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable(fieldRename: FieldRename.snake)
class _QuoteModel implements QuoteModel {
const _QuoteModel({required this.id, required this.text, required this.author});
factory _QuoteModel.fromJson(Map<String, dynamic> json) => _$QuoteModelFromJson(json);
@override final int id;
@override final String text;
@override final String author;
/// Create a copy of QuoteModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$QuoteModelCopyWith<_QuoteModel> get copyWith => __$QuoteModelCopyWithImpl<_QuoteModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$QuoteModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _QuoteModel&&(identical(other.id, id) || other.id == id)&&(identical(other.text, text) || other.text == text)&&(identical(other.author, author) || other.author == author));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,text,author);
@override
String toString() {
return 'QuoteModel(id: $id, text: $text, author: $author)';
}
}
/// @nodoc
abstract mixin class _$QuoteModelCopyWith<$Res> implements $QuoteModelCopyWith<$Res> {
factory _$QuoteModelCopyWith(_QuoteModel value, $Res Function(_QuoteModel) _then) = __$QuoteModelCopyWithImpl;
@override @useResult
$Res call({
int id, String text, String author
});
}
/// @nodoc
class __$QuoteModelCopyWithImpl<$Res>
implements _$QuoteModelCopyWith<$Res> {
__$QuoteModelCopyWithImpl(this._self, this._then);
final _QuoteModel _self;
final $Res Function(_QuoteModel) _then;
/// Create a copy of QuoteModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? text = null,Object? author = null,}) {
return _then(_QuoteModel(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as int,text: null == text ? _self.text : text // ignore: cast_nullable_to_non_nullable
as String,author: null == author ? _self.author : author // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View file

@ -0,0 +1,20 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'quote_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_QuoteModel _$QuoteModelFromJson(Map<String, dynamic> json) => _QuoteModel(
id: (json['id'] as num).toInt(),
text: json['text'] as String,
author: json['author'] as String,
);
Map<String, dynamic> _$QuoteModelToJson(_QuoteModel instance) =>
<String, dynamic>{
'id': instance.id,
'text': instance.text,
'author': instance.author,
};

View file

@ -0,0 +1,13 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'translation_model.freezed.dart';
part 'translation_model.g.dart';
@freezed
abstract class TranslationModel with _$TranslationModel {
const factory TranslationModel({required String id, required String lang}) =
_TranslationModel;
factory TranslationModel.fromJson(Map<String, dynamic> json) =>
_$TranslationModelFromJson(json);
}

View file

@ -0,0 +1,280 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// 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 'translation_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$TranslationModel {
String get id; String get lang;
/// Create a copy of TranslationModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$TranslationModelCopyWith<TranslationModel> get copyWith => _$TranslationModelCopyWithImpl<TranslationModel>(this as TranslationModel, _$identity);
/// Serializes this TranslationModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is TranslationModel&&(identical(other.id, id) || other.id == id)&&(identical(other.lang, lang) || other.lang == lang));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,lang);
@override
String toString() {
return 'TranslationModel(id: $id, lang: $lang)';
}
}
/// @nodoc
abstract mixin class $TranslationModelCopyWith<$Res> {
factory $TranslationModelCopyWith(TranslationModel value, $Res Function(TranslationModel) _then) = _$TranslationModelCopyWithImpl;
@useResult
$Res call({
String id, String lang
});
}
/// @nodoc
class _$TranslationModelCopyWithImpl<$Res>
implements $TranslationModelCopyWith<$Res> {
_$TranslationModelCopyWithImpl(this._self, this._then);
final TranslationModel _self;
final $Res Function(TranslationModel) _then;
/// Create a copy of TranslationModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? lang = null,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,lang: null == lang ? _self.lang : lang // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [TranslationModel].
extension TranslationModelPatterns on TranslationModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _TranslationModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _TranslationModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _TranslationModel value) $default,){
final _that = this;
switch (_that) {
case _TranslationModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _TranslationModel value)? $default,){
final _that = this;
switch (_that) {
case _TranslationModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String lang)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _TranslationModel() when $default != null:
return $default(_that.id,_that.lang);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String lang) $default,) {final _that = this;
switch (_that) {
case _TranslationModel():
return $default(_that.id,_that.lang);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String lang)? $default,) {final _that = this;
switch (_that) {
case _TranslationModel() when $default != null:
return $default(_that.id,_that.lang);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _TranslationModel implements TranslationModel {
const _TranslationModel({required this.id, required this.lang});
factory _TranslationModel.fromJson(Map<String, dynamic> json) => _$TranslationModelFromJson(json);
@override final String id;
@override final String lang;
/// Create a copy of TranslationModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$TranslationModelCopyWith<_TranslationModel> get copyWith => __$TranslationModelCopyWithImpl<_TranslationModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$TranslationModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _TranslationModel&&(identical(other.id, id) || other.id == id)&&(identical(other.lang, lang) || other.lang == lang));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,lang);
@override
String toString() {
return 'TranslationModel(id: $id, lang: $lang)';
}
}
/// @nodoc
abstract mixin class _$TranslationModelCopyWith<$Res> implements $TranslationModelCopyWith<$Res> {
factory _$TranslationModelCopyWith(_TranslationModel value, $Res Function(_TranslationModel) _then) = __$TranslationModelCopyWithImpl;
@override @useResult
$Res call({
String id, String lang
});
}
/// @nodoc
class __$TranslationModelCopyWithImpl<$Res>
implements _$TranslationModelCopyWith<$Res> {
__$TranslationModelCopyWithImpl(this._self, this._then);
final _TranslationModel _self;
final $Res Function(_TranslationModel) _then;
/// Create a copy of TranslationModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? lang = null,}) {
return _then(_TranslationModel(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,lang: null == lang ? _self.lang : lang // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View file

@ -0,0 +1,13 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'translation_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_TranslationModel _$TranslationModelFromJson(Map<String, dynamic> json) =>
_TranslationModel(id: json['id'] as String, lang: json['lang'] as String);
Map<String, dynamic> _$TranslationModelToJson(_TranslationModel instance) =>
<String, dynamic>{'id': instance.id, 'lang': instance.lang};

View file

@ -0,0 +1,89 @@
import 'dart:convert';
import 'package:fpdart/fpdart.dart';
import 'package:http/http.dart';
import 'package:kuwot/core/data/local/translation_target_config.dart';
import 'package:kuwot/core/error/exception.dart';
import 'package:kuwot/core/error/failure.dart';
import 'package:kuwot/core/error/server_error_model.dart';
import 'package:kuwot/features/quote/data/data_sources/remote/kuwot_api_remote_data_source.dart';
import 'package:kuwot/features/quote/domain/entities/background_image.dart';
import 'package:kuwot/features/quote/domain/entities/quote.dart';
import 'package:kuwot/features/quote/domain/entities/translation.dart';
import 'package:kuwot/features/quote/domain/repositories/quote_repository.dart';
class QuoteRepositoryImpl implements QuoteRepository {
final KuwotApiRemoteDataSource quoteDataSource;
QuoteRepositoryImpl({required this.quoteDataSource});
@override
Future<Either<Failure, List<BackgroundImage>>> getBackgroundImages() async {
try {
final images = await quoteDataSource.getRandomImages();
return right(BackgroundImage.fromModels(images));
} on ClientException catch (e) {
return left(
ClientFailure(message: "Failed to connect to the server", cause: e),
);
} on Exception catch (e) {
return left(UnknownFailure(message: e.toString(), cause: e));
}
}
@override
Future<Either<Failure, Quote>> getQuote(
TranslationTarget? translationTarget,
) async {
try {
final query = translationTarget != null
? "lang=${translationTarget.id}"
: null;
final quote = await quoteDataSource.getQuote(query: query);
return right(Quote.fromModel(quote));
} on ClientException catch (e) {
return left(
ClientFailure(message: "Failed to connect to the server", cause: e),
);
} on ServerException catch (e) {
final error = ServerErrorModel.fromJson(jsonDecode(e.message));
return left(
ServerFailure(message: '${error.message} (${error.code})', cause: e),
);
} on Exception catch (e) {
return left(UnknownFailure(message: e.toString(), cause: e));
}
}
@override
Future<Either<Failure, Quote>> getTranslatedQuote(
int id,
TranslationTarget translationTarget,
) async {
try {
final query = "lang=${translationTarget.id}";
final quote = await quoteDataSource.getTranslatedQuote(id, query: query);
return right(Quote.fromModel(quote));
} on ClientException catch (e) {
return left(
ClientFailure(message: "Failed to connect to the server", cause: e),
);
} on Exception catch (e) {
return left(UnknownFailure(message: e.toString(), cause: e));
}
}
@override
Future<Either<Failure, List<Translation>>> getTranslations() async {
try {
final translations = await quoteDataSource.getTranslations();
return right(translations.map((e) => Translation.fromModel(e)).toList());
} on ClientException catch (e) {
return left(
ClientFailure(message: "Failed to connect to the server", cause: e),
);
} on Exception catch (e) {
return left(UnknownFailure(message: e.toString(), cause: e));
}
}
}