diff --git a/lib/app_router.dart b/lib/app_router.dart index f872ddc9..9b5b46de 100644 --- a/lib/app_router.dart +++ b/lib/app_router.dart @@ -133,7 +133,7 @@ class AppRouter { path: '/about-diet-screen', name: 'aboutDietScreen', builder: (context, state) => AboutDietScreen( - datum: state.extra as Datum, + diet: state.extra as Diet, ), ), GoRoute( diff --git a/lib/core/models/base_models.dart b/lib/core/models/base_models.dart new file mode 100644 index 00000000..48de60ef --- /dev/null +++ b/lib/core/models/base_models.dart @@ -0,0 +1,43 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'base_models.freezed.dart'; +part 'base_models.g.dart'; + +@freezed +class Links with _$Links { + const factory Links({ + @JsonKey(name: "first") required String first, + @JsonKey(name: "last") required String last, + @JsonKey(name: "prev") required dynamic prev, + @JsonKey(name: "next") required dynamic next, + }) = _Links; + + factory Links.fromJson(Map json) => _$LinksFromJson(json); +} + +@freezed +class Meta with _$Meta { + const factory Meta({ + @JsonKey(name: "current_page") required int currentPage, + @JsonKey(name: "from") required int from, + @JsonKey(name: "last_page") required int lastPage, + @JsonKey(name: "links") required List links, + @JsonKey(name: "path") required String path, + @JsonKey(name: "per_page") required int perPage, + @JsonKey(name: "to") required int to, + @JsonKey(name: "total") required int total, + }) = _Meta; + + factory Meta.fromJson(Map json) => _$MetaFromJson(json); +} + +@freezed +class Link with _$Link { + const factory Link({ + @JsonKey(name: "url") required String? url, + @JsonKey(name: "label") required String label, + @JsonKey(name: "active") required bool active, + }) = _Link; + + factory Link.fromJson(Map json) => _$LinkFromJson(json); +} diff --git a/lib/core/models/base_models.freezed.dart b/lib/core/models/base_models.freezed.dart new file mode 100644 index 00000000..b62824d5 --- /dev/null +++ b/lib/core/models/base_models.freezed.dart @@ -0,0 +1,721 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'base_models.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +Links _$LinksFromJson(Map json) { + return _Links.fromJson(json); +} + +/// @nodoc +mixin _$Links { + @JsonKey(name: "first") + String get first => throw _privateConstructorUsedError; + @JsonKey(name: "last") + String get last => throw _privateConstructorUsedError; + @JsonKey(name: "prev") + dynamic get prev => throw _privateConstructorUsedError; + @JsonKey(name: "next") + dynamic get next => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $LinksCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LinksCopyWith<$Res> { + factory $LinksCopyWith(Links value, $Res Function(Links) then) = + _$LinksCopyWithImpl<$Res, Links>; + @useResult + $Res call( + {@JsonKey(name: "first") String first, + @JsonKey(name: "last") String last, + @JsonKey(name: "prev") dynamic prev, + @JsonKey(name: "next") dynamic next}); +} + +/// @nodoc +class _$LinksCopyWithImpl<$Res, $Val extends Links> + implements $LinksCopyWith<$Res> { + _$LinksCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? first = null, + Object? last = null, + Object? prev = freezed, + Object? next = freezed, + }) { + return _then(_value.copyWith( + first: null == first + ? _value.first + : first // ignore: cast_nullable_to_non_nullable + as String, + last: null == last + ? _value.last + : last // ignore: cast_nullable_to_non_nullable + as String, + prev: freezed == prev + ? _value.prev + : prev // ignore: cast_nullable_to_non_nullable + as dynamic, + next: freezed == next + ? _value.next + : next // ignore: cast_nullable_to_non_nullable + as dynamic, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$LinksImplCopyWith<$Res> implements $LinksCopyWith<$Res> { + factory _$$LinksImplCopyWith( + _$LinksImpl value, $Res Function(_$LinksImpl) then) = + __$$LinksImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: "first") String first, + @JsonKey(name: "last") String last, + @JsonKey(name: "prev") dynamic prev, + @JsonKey(name: "next") dynamic next}); +} + +/// @nodoc +class __$$LinksImplCopyWithImpl<$Res> + extends _$LinksCopyWithImpl<$Res, _$LinksImpl> + implements _$$LinksImplCopyWith<$Res> { + __$$LinksImplCopyWithImpl( + _$LinksImpl _value, $Res Function(_$LinksImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? first = null, + Object? last = null, + Object? prev = freezed, + Object? next = freezed, + }) { + return _then(_$LinksImpl( + first: null == first + ? _value.first + : first // ignore: cast_nullable_to_non_nullable + as String, + last: null == last + ? _value.last + : last // ignore: cast_nullable_to_non_nullable + as String, + prev: freezed == prev + ? _value.prev + : prev // ignore: cast_nullable_to_non_nullable + as dynamic, + next: freezed == next + ? _value.next + : next // ignore: cast_nullable_to_non_nullable + as dynamic, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$LinksImpl implements _Links { + const _$LinksImpl( + {@JsonKey(name: "first") required this.first, + @JsonKey(name: "last") required this.last, + @JsonKey(name: "prev") required this.prev, + @JsonKey(name: "next") required this.next}); + + factory _$LinksImpl.fromJson(Map json) => + _$$LinksImplFromJson(json); + + @override + @JsonKey(name: "first") + final String first; + @override + @JsonKey(name: "last") + final String last; + @override + @JsonKey(name: "prev") + final dynamic prev; + @override + @JsonKey(name: "next") + final dynamic next; + + @override + String toString() { + return 'Links(first: $first, last: $last, prev: $prev, next: $next)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$LinksImpl && + (identical(other.first, first) || other.first == first) && + (identical(other.last, last) || other.last == last) && + const DeepCollectionEquality().equals(other.prev, prev) && + const DeepCollectionEquality().equals(other.next, next)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, + first, + last, + const DeepCollectionEquality().hash(prev), + const DeepCollectionEquality().hash(next)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$LinksImplCopyWith<_$LinksImpl> get copyWith => + __$$LinksImplCopyWithImpl<_$LinksImpl>(this, _$identity); + + @override + Map toJson() { + return _$$LinksImplToJson( + this, + ); + } +} + +abstract class _Links implements Links { + const factory _Links( + {@JsonKey(name: "first") required final String first, + @JsonKey(name: "last") required final String last, + @JsonKey(name: "prev") required final dynamic prev, + @JsonKey(name: "next") required final dynamic next}) = _$LinksImpl; + + factory _Links.fromJson(Map json) = _$LinksImpl.fromJson; + + @override + @JsonKey(name: "first") + String get first; + @override + @JsonKey(name: "last") + String get last; + @override + @JsonKey(name: "prev") + dynamic get prev; + @override + @JsonKey(name: "next") + dynamic get next; + @override + @JsonKey(ignore: true) + _$$LinksImplCopyWith<_$LinksImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Meta _$MetaFromJson(Map json) { + return _Meta.fromJson(json); +} + +/// @nodoc +mixin _$Meta { + @JsonKey(name: "current_page") + int get currentPage => throw _privateConstructorUsedError; + @JsonKey(name: "from") + int get from => throw _privateConstructorUsedError; + @JsonKey(name: "last_page") + int get lastPage => throw _privateConstructorUsedError; + @JsonKey(name: "links") + List get links => throw _privateConstructorUsedError; + @JsonKey(name: "path") + String get path => throw _privateConstructorUsedError; + @JsonKey(name: "per_page") + int get perPage => throw _privateConstructorUsedError; + @JsonKey(name: "to") + int get to => throw _privateConstructorUsedError; + @JsonKey(name: "total") + int get total => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $MetaCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MetaCopyWith<$Res> { + factory $MetaCopyWith(Meta value, $Res Function(Meta) then) = + _$MetaCopyWithImpl<$Res, Meta>; + @useResult + $Res call( + {@JsonKey(name: "current_page") int currentPage, + @JsonKey(name: "from") int from, + @JsonKey(name: "last_page") int lastPage, + @JsonKey(name: "links") List links, + @JsonKey(name: "path") String path, + @JsonKey(name: "per_page") int perPage, + @JsonKey(name: "to") int to, + @JsonKey(name: "total") int total}); +} + +/// @nodoc +class _$MetaCopyWithImpl<$Res, $Val extends Meta> + implements $MetaCopyWith<$Res> { + _$MetaCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? currentPage = null, + Object? from = null, + Object? lastPage = null, + Object? links = null, + Object? path = null, + Object? perPage = null, + Object? to = null, + Object? total = null, + }) { + return _then(_value.copyWith( + currentPage: null == currentPage + ? _value.currentPage + : currentPage // ignore: cast_nullable_to_non_nullable + as int, + from: null == from + ? _value.from + : from // ignore: cast_nullable_to_non_nullable + as int, + lastPage: null == lastPage + ? _value.lastPage + : lastPage // ignore: cast_nullable_to_non_nullable + as int, + links: null == links + ? _value.links + : links // ignore: cast_nullable_to_non_nullable + as List, + path: null == path + ? _value.path + : path // ignore: cast_nullable_to_non_nullable + as String, + perPage: null == perPage + ? _value.perPage + : perPage // ignore: cast_nullable_to_non_nullable + as int, + to: null == to + ? _value.to + : to // ignore: cast_nullable_to_non_nullable + as int, + total: null == total + ? _value.total + : total // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MetaImplCopyWith<$Res> implements $MetaCopyWith<$Res> { + factory _$$MetaImplCopyWith( + _$MetaImpl value, $Res Function(_$MetaImpl) then) = + __$$MetaImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: "current_page") int currentPage, + @JsonKey(name: "from") int from, + @JsonKey(name: "last_page") int lastPage, + @JsonKey(name: "links") List links, + @JsonKey(name: "path") String path, + @JsonKey(name: "per_page") int perPage, + @JsonKey(name: "to") int to, + @JsonKey(name: "total") int total}); +} + +/// @nodoc +class __$$MetaImplCopyWithImpl<$Res> + extends _$MetaCopyWithImpl<$Res, _$MetaImpl> + implements _$$MetaImplCopyWith<$Res> { + __$$MetaImplCopyWithImpl(_$MetaImpl _value, $Res Function(_$MetaImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? currentPage = null, + Object? from = null, + Object? lastPage = null, + Object? links = null, + Object? path = null, + Object? perPage = null, + Object? to = null, + Object? total = null, + }) { + return _then(_$MetaImpl( + currentPage: null == currentPage + ? _value.currentPage + : currentPage // ignore: cast_nullable_to_non_nullable + as int, + from: null == from + ? _value.from + : from // ignore: cast_nullable_to_non_nullable + as int, + lastPage: null == lastPage + ? _value.lastPage + : lastPage // ignore: cast_nullable_to_non_nullable + as int, + links: null == links + ? _value._links + : links // ignore: cast_nullable_to_non_nullable + as List, + path: null == path + ? _value.path + : path // ignore: cast_nullable_to_non_nullable + as String, + perPage: null == perPage + ? _value.perPage + : perPage // ignore: cast_nullable_to_non_nullable + as int, + to: null == to + ? _value.to + : to // ignore: cast_nullable_to_non_nullable + as int, + total: null == total + ? _value.total + : total // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$MetaImpl implements _Meta { + const _$MetaImpl( + {@JsonKey(name: "current_page") required this.currentPage, + @JsonKey(name: "from") required this.from, + @JsonKey(name: "last_page") required this.lastPage, + @JsonKey(name: "links") required final List links, + @JsonKey(name: "path") required this.path, + @JsonKey(name: "per_page") required this.perPage, + @JsonKey(name: "to") required this.to, + @JsonKey(name: "total") required this.total}) + : _links = links; + + factory _$MetaImpl.fromJson(Map json) => + _$$MetaImplFromJson(json); + + @override + @JsonKey(name: "current_page") + final int currentPage; + @override + @JsonKey(name: "from") + final int from; + @override + @JsonKey(name: "last_page") + final int lastPage; + final List _links; + @override + @JsonKey(name: "links") + List get links { + if (_links is EqualUnmodifiableListView) return _links; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_links); + } + + @override + @JsonKey(name: "path") + final String path; + @override + @JsonKey(name: "per_page") + final int perPage; + @override + @JsonKey(name: "to") + final int to; + @override + @JsonKey(name: "total") + final int total; + + @override + String toString() { + return 'Meta(currentPage: $currentPage, from: $from, lastPage: $lastPage, links: $links, path: $path, perPage: $perPage, to: $to, total: $total)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MetaImpl && + (identical(other.currentPage, currentPage) || + other.currentPage == currentPage) && + (identical(other.from, from) || other.from == from) && + (identical(other.lastPage, lastPage) || + other.lastPage == lastPage) && + const DeepCollectionEquality().equals(other._links, _links) && + (identical(other.path, path) || other.path == path) && + (identical(other.perPage, perPage) || other.perPage == perPage) && + (identical(other.to, to) || other.to == to) && + (identical(other.total, total) || other.total == total)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, currentPage, from, lastPage, + const DeepCollectionEquality().hash(_links), path, perPage, to, total); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$MetaImplCopyWith<_$MetaImpl> get copyWith => + __$$MetaImplCopyWithImpl<_$MetaImpl>(this, _$identity); + + @override + Map toJson() { + return _$$MetaImplToJson( + this, + ); + } +} + +abstract class _Meta implements Meta { + const factory _Meta( + {@JsonKey(name: "current_page") required final int currentPage, + @JsonKey(name: "from") required final int from, + @JsonKey(name: "last_page") required final int lastPage, + @JsonKey(name: "links") required final List links, + @JsonKey(name: "path") required final String path, + @JsonKey(name: "per_page") required final int perPage, + @JsonKey(name: "to") required final int to, + @JsonKey(name: "total") required final int total}) = _$MetaImpl; + + factory _Meta.fromJson(Map json) = _$MetaImpl.fromJson; + + @override + @JsonKey(name: "current_page") + int get currentPage; + @override + @JsonKey(name: "from") + int get from; + @override + @JsonKey(name: "last_page") + int get lastPage; + @override + @JsonKey(name: "links") + List get links; + @override + @JsonKey(name: "path") + String get path; + @override + @JsonKey(name: "per_page") + int get perPage; + @override + @JsonKey(name: "to") + int get to; + @override + @JsonKey(name: "total") + int get total; + @override + @JsonKey(ignore: true) + _$$MetaImplCopyWith<_$MetaImpl> get copyWith => + throw _privateConstructorUsedError; +} + +Link _$LinkFromJson(Map json) { + return _Link.fromJson(json); +} + +/// @nodoc +mixin _$Link { + @JsonKey(name: "url") + String? get url => throw _privateConstructorUsedError; + @JsonKey(name: "label") + String get label => throw _privateConstructorUsedError; + @JsonKey(name: "active") + bool get active => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $LinkCopyWith get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $LinkCopyWith<$Res> { + factory $LinkCopyWith(Link value, $Res Function(Link) then) = + _$LinkCopyWithImpl<$Res, Link>; + @useResult + $Res call( + {@JsonKey(name: "url") String? url, + @JsonKey(name: "label") String label, + @JsonKey(name: "active") bool active}); +} + +/// @nodoc +class _$LinkCopyWithImpl<$Res, $Val extends Link> + implements $LinkCopyWith<$Res> { + _$LinkCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? url = freezed, + Object? label = null, + Object? active = null, + }) { + return _then(_value.copyWith( + url: freezed == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String?, + label: null == label + ? _value.label + : label // ignore: cast_nullable_to_non_nullable + as String, + active: null == active + ? _value.active + : active // ignore: cast_nullable_to_non_nullable + as bool, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$LinkImplCopyWith<$Res> implements $LinkCopyWith<$Res> { + factory _$$LinkImplCopyWith( + _$LinkImpl value, $Res Function(_$LinkImpl) then) = + __$$LinkImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: "url") String? url, + @JsonKey(name: "label") String label, + @JsonKey(name: "active") bool active}); +} + +/// @nodoc +class __$$LinkImplCopyWithImpl<$Res> + extends _$LinkCopyWithImpl<$Res, _$LinkImpl> + implements _$$LinkImplCopyWith<$Res> { + __$$LinkImplCopyWithImpl(_$LinkImpl _value, $Res Function(_$LinkImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? url = freezed, + Object? label = null, + Object? active = null, + }) { + return _then(_$LinkImpl( + url: freezed == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String?, + label: null == label + ? _value.label + : label // ignore: cast_nullable_to_non_nullable + as String, + active: null == active + ? _value.active + : active // ignore: cast_nullable_to_non_nullable + as bool, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$LinkImpl implements _Link { + const _$LinkImpl( + {@JsonKey(name: "url") required this.url, + @JsonKey(name: "label") required this.label, + @JsonKey(name: "active") required this.active}); + + factory _$LinkImpl.fromJson(Map json) => + _$$LinkImplFromJson(json); + + @override + @JsonKey(name: "url") + final String? url; + @override + @JsonKey(name: "label") + final String label; + @override + @JsonKey(name: "active") + final bool active; + + @override + String toString() { + return 'Link(url: $url, label: $label, active: $active)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$LinkImpl && + (identical(other.url, url) || other.url == url) && + (identical(other.label, label) || other.label == label) && + (identical(other.active, active) || other.active == active)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, url, label, active); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$LinkImplCopyWith<_$LinkImpl> get copyWith => + __$$LinkImplCopyWithImpl<_$LinkImpl>(this, _$identity); + + @override + Map toJson() { + return _$$LinkImplToJson( + this, + ); + } +} + +abstract class _Link implements Link { + const factory _Link( + {@JsonKey(name: "url") required final String? url, + @JsonKey(name: "label") required final String label, + @JsonKey(name: "active") required final bool active}) = _$LinkImpl; + + factory _Link.fromJson(Map json) = _$LinkImpl.fromJson; + + @override + @JsonKey(name: "url") + String? get url; + @override + @JsonKey(name: "label") + String get label; + @override + @JsonKey(name: "active") + bool get active; + @override + @JsonKey(ignore: true) + _$$LinkImplCopyWith<_$LinkImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/core/models/base_models.g.dart b/lib/core/models/base_models.g.dart new file mode 100644 index 00000000..5eec9fa3 --- /dev/null +++ b/lib/core/models/base_models.g.dart @@ -0,0 +1,60 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'base_models.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$LinksImpl _$$LinksImplFromJson(Map json) => _$LinksImpl( + first: json['first'] as String, + last: json['last'] as String, + prev: json['prev'], + next: json['next'], + ); + +Map _$$LinksImplToJson(_$LinksImpl instance) => + { + 'first': instance.first, + 'last': instance.last, + 'prev': instance.prev, + 'next': instance.next, + }; + +_$MetaImpl _$$MetaImplFromJson(Map json) => _$MetaImpl( + currentPage: (json['current_page'] as num).toInt(), + from: (json['from'] as num).toInt(), + lastPage: (json['last_page'] as num).toInt(), + links: (json['links'] as List) + .map((e) => Link.fromJson(e as Map)) + .toList(), + path: json['path'] as String, + perPage: (json['per_page'] as num).toInt(), + to: (json['to'] as num).toInt(), + total: (json['total'] as num).toInt(), + ); + +Map _$$MetaImplToJson(_$MetaImpl instance) => + { + 'current_page': instance.currentPage, + 'from': instance.from, + 'last_page': instance.lastPage, + 'links': instance.links, + 'path': instance.path, + 'per_page': instance.perPage, + 'to': instance.to, + 'total': instance.total, + }; + +_$LinkImpl _$$LinkImplFromJson(Map json) => _$LinkImpl( + url: json['url'] as String?, + label: json['label'] as String, + active: json['active'] as bool, + ); + +Map _$$LinkImplToJson(_$LinkImpl instance) => + { + 'url': instance.url, + 'label': instance.label, + 'active': instance.active, + }; diff --git a/lib/features/blog_post/presentation/pages/blog_post_screen.dart b/lib/features/blog_post/presentation/pages/blog_post_screen.dart index b2e827cf..bd4db44e 100644 --- a/lib/features/blog_post/presentation/pages/blog_post_screen.dart +++ b/lib/features/blog_post/presentation/pages/blog_post_screen.dart @@ -320,31 +320,31 @@ class _BlogPostScreenState extends State { ); } - _buildComments(Comment comment) { + _buildComments(CommentModel comment) { return Column( children: [ for (int i = 0; i < comment.data.length; i++) ...[ _comment(comment.data[i]), - if (comment.data[i].childrenComments.isNotEmpty) - for (int j = 0; j < comment.data[i].childrenComments.length; j++) - Padding( - padding: EdgeInsets.only(left: 40), - child: _comment( - comment.data[i].childrenComments[j], - 12, - ), + if (comment.data[i].childrenComments.isNotEmpty) SizedBox(height: 8), + for (int j = 0; j < comment.data[i].childrenComments.length; j++) + Padding( + padding: EdgeInsets.only(left: 40), + child: _comment( + comment.data[i].childrenComments[j], + 12, ), + ), SizedBox(height: 8), ], ], ); } - _comment(Datum datum, [double radius = 16]) { + _comment(Comment comment, [double radius = 16]) { return Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - color: replyId == datum.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white, + color: replyId == comment.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white, borderRadius: BorderRadius.circular(16), ), child: Padding( @@ -353,7 +353,7 @@ class _BlogPostScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ CircleAvatar( - foregroundImage: NetworkImage(datum.authorProfileIcon), + foregroundImage: NetworkImage(comment.authorProfileIcon), radius: radius, ), SizedBox(width: 8), @@ -362,7 +362,7 @@ class _BlogPostScreenState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Text( - datum.authorName, + comment.authorName, style: TextStyle( height: 1, color: Colors.grey.shade600, @@ -371,7 +371,7 @@ class _BlogPostScreenState extends State { ), SizedBox(width: 4), Text( - datum.body, + comment.body, style: TextStyle( height: 1, color: Colors.black, @@ -381,7 +381,7 @@ class _BlogPostScreenState extends State { Row( children: [ Text( - datum.createdAt.format('dd MMMM', 'ru'), + comment.createdAt.format('dd MMMM', 'ru'), style: TextStyle( color: Colors.grey.shade600, fontSize: 12, @@ -393,7 +393,7 @@ class _BlogPostScreenState extends State { GestureDetector( onTap: () { setState(() { - replyId = datum.id; + replyId = comment.id; }); }, child: Text( diff --git a/lib/features/diets/presentation/pages/about_diet_screen.dart b/lib/features/diets/presentation/pages/about_diet_screen.dart index 643f6111..d21de813 100644 --- a/lib/features/diets/presentation/pages/about_diet_screen.dart +++ b/lib/features/diets/presentation/pages/about_diet_screen.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/features/feed/models/comment_model.dart'; -import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart' as Diets; +import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/comments_cubit/comments_cubit.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/comments_cubit/comments_state.dart'; import 'package:eatvio_app/locator_service.dart'; @@ -12,11 +12,11 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class AboutDietScreen extends StatefulWidget { - final Diets.Datum datum; + final Diet diet; late final List selectedIndexes; - AboutDietScreen({super.key, required this.datum}) { - selectedIndexes = List.generate(datum.dailySchedule.length, (_) => 0); + AboutDietScreen({super.key, required this.diet}) { + selectedIndexes = List.generate(diet.dailySchedule.length, (_) => 0); } @override @@ -31,7 +31,7 @@ class _AboutDietScreenState extends State { @override void initState() { super.initState(); - commentsCubit.getDietsComments(widget.datum.id); + commentsCubit.getDietsComments(widget.diet.id); } @override @@ -157,7 +157,7 @@ class _AboutDietScreenState extends State { onTap: () { if (textEditingController.text.length > 2) { commentsCubit.sendDietsComment( - id: widget.datum.id, + id: widget.diet.id, commentText: textEditingController.text, parentCommentId: replyId, ); @@ -210,7 +210,7 @@ class _AboutDietScreenState extends State { actions: [ InkWell( borderRadius: BorderRadius.circular(16), - onTap: () => GoRouter.of(context).pushNamed('profileScreen', extra: widget.datum.author), + onTap: () => GoRouter.of(context).pushNamed('profileScreen', extra: widget.diet.author), child: Ink( padding: const EdgeInsets.symmetric(horizontal: 16), child: Column( @@ -219,11 +219,11 @@ class _AboutDietScreenState extends State { CircleAvatar( maxRadius: 16, minRadius: 16, - backgroundImage: NetworkImage(widget.datum.author.authorProfileIcon), + backgroundImage: NetworkImage(widget.diet.author.authorProfileIcon), ), SizedBox(height: 4), Text( - widget.datum.author.authorName, + widget.diet.author.authorName, style: TextStyle( color: Colors.black, fontSize: 14, @@ -245,7 +245,7 @@ class _AboutDietScreenState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: Text( - widget.datum.name, + widget.diet.name, style: TextStyle( color: Colors.black, fontSize: 24, @@ -262,7 +262,7 @@ class _AboutDietScreenState extends State { Icon(Icons.timer_outlined), SizedBox(width: 4), Text( - widget.datum.duration.toString() + ' дней', + widget.diet.duration.toString() + ' дней', style: TextStyle( color: Colors.black, fontSize: 12, @@ -277,7 +277,7 @@ class _AboutDietScreenState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: Text( - widget.datum.details, + widget.diet.details, style: TextStyle( color: Colors.black, fontSize: 14, @@ -288,7 +288,7 @@ class _AboutDietScreenState extends State { ), SizedBox(height: 12), CachedNetworkImage( - imageUrl: baseUrl + '/storage/' + widget.datum.image, + imageUrl: baseUrl + '/storage/' + widget.diet.image, ), SizedBox(height: 12), ListView.separated( @@ -296,7 +296,7 @@ class _AboutDietScreenState extends State { physics: NeverScrollableScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { - return _dayOfPlan(widget.datum.dailySchedule[index], index); + return _dayOfPlan(widget.diet.dailySchedule[index], index); }, separatorBuilder: (context, index) => Padding( padding: const EdgeInsets.symmetric(vertical: 16), @@ -308,14 +308,14 @@ class _AboutDietScreenState extends State { ), ), ), - itemCount: widget.datum.dailySchedule.length, + itemCount: widget.diet.dailySchedule.length, ), SizedBox(height: 32), Container( padding: EdgeInsets.symmetric(horizontal: 16), alignment: Alignment.centerLeft, child: Text( - widget.datum.totalComments.toString() + ' КОММЕНТАРИЕВ', + widget.diet.totalComments.toString() + ' КОММЕНТАРИЕВ', style: TextStyle( fontSize: 12, color: appTheme.gray500, @@ -339,7 +339,7 @@ class _AboutDietScreenState extends State { ); } - _dayOfPlan(List> day, int dayNumber) { + _dayOfPlan(List> day, int dayNumber) { _choiceChipWidget(int index) { return ChoiceChip( selectedColor: appTheme.blueA400, @@ -410,7 +410,7 @@ class _AboutDietScreenState extends State { ); } - _daily(Diets.DailySchedule daily) { + _daily(DailySchedule daily) { return Row( children: [ Text( @@ -436,7 +436,7 @@ class _AboutDietScreenState extends State { ); } - _buildComments(Comment comment) { + _buildComments(CommentModel comment) { return Column( children: [ for (int i = 0; i < comment.data.length; i++) ...[ @@ -456,11 +456,11 @@ class _AboutDietScreenState extends State { ); } - _comment(Datum datum, [double radius = 16]) { + _comment(Comment diet, [double radius = 16]) { return Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - color: replyId == datum.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white, + color: replyId == diet.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white, borderRadius: BorderRadius.circular(16), ), child: Padding( @@ -469,7 +469,7 @@ class _AboutDietScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ CircleAvatar( - foregroundImage: NetworkImage(datum.authorProfileIcon), + foregroundImage: NetworkImage(diet.authorProfileIcon), radius: radius, ), SizedBox(width: 8), @@ -478,7 +478,7 @@ class _AboutDietScreenState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Text( - datum.authorName, + diet.authorName, style: TextStyle( height: 1, color: Colors.grey.shade600, @@ -487,7 +487,7 @@ class _AboutDietScreenState extends State { ), SizedBox(width: 4), Text( - datum.body, + diet.body, style: TextStyle( height: 1, color: Colors.black, @@ -497,7 +497,7 @@ class _AboutDietScreenState extends State { Row( children: [ Text( - datum.createdAt.format('dd MMMM', 'ru'), + diet.createdAt.format('dd MMMM', 'ru'), style: TextStyle( color: Colors.grey.shade600, fontSize: 12, @@ -509,7 +509,7 @@ class _AboutDietScreenState extends State { GestureDetector( onTap: () { setState(() { - replyId = datum.id; + replyId = diet.id; }); }, child: Text( diff --git a/lib/features/feed/models/comment_model.dart b/lib/features/feed/models/comment_model.dart index 52f163e4..edcc722a 100644 --- a/lib/features/feed/models/comment_model.dart +++ b/lib/features/feed/models/comment_model.dart @@ -1,68 +1,30 @@ +import 'package:eatvio_app/core/models/base_models.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'comment_model.freezed.dart'; part 'comment_model.g.dart'; @freezed -class Comment with _$Comment { - const factory Comment({ - @JsonKey(name: "data") required List data, +class CommentModel with _$CommentModel { + const factory CommentModel({ + @JsonKey(name: "data") required List data, @JsonKey(name: "links") required Links links, @JsonKey(name: "meta") required Meta meta, - }) = _Comment; + }) = _CommentModel; - factory Comment.fromJson(Map json) => _$CommentFromJson(json); + factory CommentModel.fromJson(Map json) => _$CommentModelFromJson(json); } @freezed -class Datum with _$Datum { - const factory Datum({ +class Comment with _$Comment { + const factory Comment({ @JsonKey(name: "id") required int id, @JsonKey(name: "author_name") required String authorName, @JsonKey(name: "author_profile_icon") required String authorProfileIcon, @JsonKey(name: "body") required String body, - @JsonKey(name: "children_comments") required List childrenComments, + @JsonKey(name: "children_comments") required List childrenComments, @JsonKey(name: "created_at") required DateTime createdAt, - }) = _Datum; + }) = _Comment; - factory Datum.fromJson(Map json) => _$DatumFromJson(json); -} - -@freezed -class Links with _$Links { - const factory Links({ - @JsonKey(name: "first") required String first, - @JsonKey(name: "last") required String last, - @JsonKey(name: "prev") required dynamic prev, - @JsonKey(name: "next") required dynamic next, - }) = _Links; - - factory Links.fromJson(Map json) => _$LinksFromJson(json); -} - -@freezed -class Meta with _$Meta { - const factory Meta({ - @JsonKey(name: "current_page") required int currentPage, - @JsonKey(name: "from") required int from, - @JsonKey(name: "last_page") required int lastPage, - @JsonKey(name: "links") required List links, - @JsonKey(name: "path") required String path, - @JsonKey(name: "per_page") required int perPage, - @JsonKey(name: "to") required int to, - @JsonKey(name: "total") required int total, - }) = _Meta; - - factory Meta.fromJson(Map json) => _$MetaFromJson(json); -} - -@freezed -class Link with _$Link { - const factory Link({ - @JsonKey(name: "url") required String? url, - @JsonKey(name: "label") required String label, - @JsonKey(name: "active") required bool active, - }) = _Link; - - factory Link.fromJson(Map json) => _$LinkFromJson(json); + factory Comment.fromJson(Map json) => _$CommentFromJson(json); } diff --git a/lib/features/feed/models/comment_model.freezed.dart b/lib/features/feed/models/comment_model.freezed.dart index 8e33c3bd..d294267f 100644 --- a/lib/features/feed/models/comment_model.freezed.dart +++ b/lib/features/feed/models/comment_model.freezed.dart @@ -14,14 +14,14 @@ T _$identity(T value) => value; final _privateConstructorUsedError = UnsupportedError( 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); -Comment _$CommentFromJson(Map json) { - return _Comment.fromJson(json); +CommentModel _$CommentModelFromJson(Map json) { + return _CommentModel.fromJson(json); } /// @nodoc -mixin _$Comment { +mixin _$CommentModel { @JsonKey(name: "data") - List get data => throw _privateConstructorUsedError; + List get data => throw _privateConstructorUsedError; @JsonKey(name: "links") Links get links => throw _privateConstructorUsedError; @JsonKey(name: "meta") @@ -29,16 +29,18 @@ mixin _$Comment { Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $CommentCopyWith get copyWith => throw _privateConstructorUsedError; + $CommentModelCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc -abstract class $CommentCopyWith<$Res> { - factory $CommentCopyWith(Comment value, $Res Function(Comment) then) = - _$CommentCopyWithImpl<$Res, Comment>; +abstract class $CommentModelCopyWith<$Res> { + factory $CommentModelCopyWith( + CommentModel value, $Res Function(CommentModel) then) = + _$CommentModelCopyWithImpl<$Res, CommentModel>; @useResult $Res call( - {@JsonKey(name: "data") List data, + {@JsonKey(name: "data") List data, @JsonKey(name: "links") Links links, @JsonKey(name: "meta") Meta meta}); @@ -47,9 +49,9 @@ abstract class $CommentCopyWith<$Res> { } /// @nodoc -class _$CommentCopyWithImpl<$Res, $Val extends Comment> - implements $CommentCopyWith<$Res> { - _$CommentCopyWithImpl(this._value, this._then); +class _$CommentModelCopyWithImpl<$Res, $Val extends CommentModel> + implements $CommentModelCopyWith<$Res> { + _$CommentModelCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -67,7 +69,7 @@ class _$CommentCopyWithImpl<$Res, $Val extends Comment> data: null == data ? _value.data : data // ignore: cast_nullable_to_non_nullable - as List, + as List, links: null == links ? _value.links : links // ignore: cast_nullable_to_non_nullable @@ -97,14 +99,15 @@ class _$CommentCopyWithImpl<$Res, $Val extends Comment> } /// @nodoc -abstract class _$$CommentImplCopyWith<$Res> implements $CommentCopyWith<$Res> { - factory _$$CommentImplCopyWith( - _$CommentImpl value, $Res Function(_$CommentImpl) then) = - __$$CommentImplCopyWithImpl<$Res>; +abstract class _$$CommentModelImplCopyWith<$Res> + implements $CommentModelCopyWith<$Res> { + factory _$$CommentModelImplCopyWith( + _$CommentModelImpl value, $Res Function(_$CommentModelImpl) then) = + __$$CommentModelImplCopyWithImpl<$Res>; @override @useResult $Res call( - {@JsonKey(name: "data") List data, + {@JsonKey(name: "data") List data, @JsonKey(name: "links") Links links, @JsonKey(name: "meta") Meta meta}); @@ -115,11 +118,11 @@ abstract class _$$CommentImplCopyWith<$Res> implements $CommentCopyWith<$Res> { } /// @nodoc -class __$$CommentImplCopyWithImpl<$Res> - extends _$CommentCopyWithImpl<$Res, _$CommentImpl> - implements _$$CommentImplCopyWith<$Res> { - __$$CommentImplCopyWithImpl( - _$CommentImpl _value, $Res Function(_$CommentImpl) _then) +class __$$CommentModelImplCopyWithImpl<$Res> + extends _$CommentModelCopyWithImpl<$Res, _$CommentModelImpl> + implements _$$CommentModelImplCopyWith<$Res> { + __$$CommentModelImplCopyWithImpl( + _$CommentModelImpl _value, $Res Function(_$CommentModelImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -129,11 +132,11 @@ class __$$CommentImplCopyWithImpl<$Res> Object? links = null, Object? meta = null, }) { - return _then(_$CommentImpl( + return _then(_$CommentModelImpl( data: null == data ? _value._data : data // ignore: cast_nullable_to_non_nullable - as List, + as List, links: null == links ? _value.links : links // ignore: cast_nullable_to_non_nullable @@ -148,20 +151,20 @@ class __$$CommentImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$CommentImpl implements _Comment { - const _$CommentImpl( - {@JsonKey(name: "data") required final List data, +class _$CommentModelImpl implements _CommentModel { + const _$CommentModelImpl( + {@JsonKey(name: "data") required final List data, @JsonKey(name: "links") required this.links, @JsonKey(name: "meta") required this.meta}) : _data = data; - factory _$CommentImpl.fromJson(Map json) => - _$$CommentImplFromJson(json); + factory _$CommentModelImpl.fromJson(Map json) => + _$$CommentModelImplFromJson(json); - final List _data; + final List _data; @override @JsonKey(name: "data") - List get data { + List get data { if (_data is EqualUnmodifiableListView) return _data; // ignore: implicit_dynamic_type return EqualUnmodifiableListView(_data); @@ -176,14 +179,14 @@ class _$CommentImpl implements _Comment { @override String toString() { - return 'Comment(data: $data, links: $links, meta: $meta)'; + return 'CommentModel(data: $data, links: $links, meta: $meta)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$CommentImpl && + other is _$CommentModelImpl && const DeepCollectionEquality().equals(other._data, _data) && (identical(other.links, links) || other.links == links) && (identical(other.meta, meta) || other.meta == meta)); @@ -197,28 +200,29 @@ class _$CommentImpl implements _Comment { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$CommentImplCopyWith<_$CommentImpl> get copyWith => - __$$CommentImplCopyWithImpl<_$CommentImpl>(this, _$identity); + _$$CommentModelImplCopyWith<_$CommentModelImpl> get copyWith => + __$$CommentModelImplCopyWithImpl<_$CommentModelImpl>(this, _$identity); @override Map toJson() { - return _$$CommentImplToJson( + return _$$CommentModelImplToJson( this, ); } } -abstract class _Comment implements Comment { - const factory _Comment( - {@JsonKey(name: "data") required final List data, +abstract class _CommentModel implements CommentModel { + const factory _CommentModel( + {@JsonKey(name: "data") required final List data, @JsonKey(name: "links") required final Links links, - @JsonKey(name: "meta") required final Meta meta}) = _$CommentImpl; + @JsonKey(name: "meta") required final Meta meta}) = _$CommentModelImpl; - factory _Comment.fromJson(Map json) = _$CommentImpl.fromJson; + factory _CommentModel.fromJson(Map json) = + _$CommentModelImpl.fromJson; @override @JsonKey(name: "data") - List get data; + List get data; @override @JsonKey(name: "links") Links get links; @@ -227,16 +231,16 @@ abstract class _Comment implements Comment { Meta get meta; @override @JsonKey(ignore: true) - _$$CommentImplCopyWith<_$CommentImpl> get copyWith => + _$$CommentModelImplCopyWith<_$CommentModelImpl> get copyWith => throw _privateConstructorUsedError; } -Datum _$DatumFromJson(Map json) { - return _Datum.fromJson(json); +Comment _$CommentFromJson(Map json) { + return _Comment.fromJson(json); } /// @nodoc -mixin _$Datum { +mixin _$Comment { @JsonKey(name: "id") int get id => throw _privateConstructorUsedError; @JsonKey(name: "author_name") @@ -246,33 +250,33 @@ mixin _$Datum { @JsonKey(name: "body") String get body => throw _privateConstructorUsedError; @JsonKey(name: "children_comments") - List get childrenComments => throw _privateConstructorUsedError; + List get childrenComments => throw _privateConstructorUsedError; @JsonKey(name: "created_at") DateTime get createdAt => throw _privateConstructorUsedError; Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $DatumCopyWith get copyWith => throw _privateConstructorUsedError; + $CommentCopyWith get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $DatumCopyWith<$Res> { - factory $DatumCopyWith(Datum value, $Res Function(Datum) then) = - _$DatumCopyWithImpl<$Res, Datum>; +abstract class $CommentCopyWith<$Res> { + factory $CommentCopyWith(Comment value, $Res Function(Comment) then) = + _$CommentCopyWithImpl<$Res, Comment>; @useResult $Res call( {@JsonKey(name: "id") int id, @JsonKey(name: "author_name") String authorName, @JsonKey(name: "author_profile_icon") String authorProfileIcon, @JsonKey(name: "body") String body, - @JsonKey(name: "children_comments") List childrenComments, + @JsonKey(name: "children_comments") List childrenComments, @JsonKey(name: "created_at") DateTime createdAt}); } /// @nodoc -class _$DatumCopyWithImpl<$Res, $Val extends Datum> - implements $DatumCopyWith<$Res> { - _$DatumCopyWithImpl(this._value, this._then); +class _$CommentCopyWithImpl<$Res, $Val extends Comment> + implements $CommentCopyWith<$Res> { + _$CommentCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -309,7 +313,7 @@ class _$DatumCopyWithImpl<$Res, $Val extends Datum> childrenComments: null == childrenComments ? _value.childrenComments : childrenComments // ignore: cast_nullable_to_non_nullable - as List, + as List, createdAt: null == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -319,10 +323,10 @@ class _$DatumCopyWithImpl<$Res, $Val extends Datum> } /// @nodoc -abstract class _$$DatumImplCopyWith<$Res> implements $DatumCopyWith<$Res> { - factory _$$DatumImplCopyWith( - _$DatumImpl value, $Res Function(_$DatumImpl) then) = - __$$DatumImplCopyWithImpl<$Res>; +abstract class _$$CommentImplCopyWith<$Res> implements $CommentCopyWith<$Res> { + factory _$$CommentImplCopyWith( + _$CommentImpl value, $Res Function(_$CommentImpl) then) = + __$$CommentImplCopyWithImpl<$Res>; @override @useResult $Res call( @@ -330,16 +334,16 @@ abstract class _$$DatumImplCopyWith<$Res> implements $DatumCopyWith<$Res> { @JsonKey(name: "author_name") String authorName, @JsonKey(name: "author_profile_icon") String authorProfileIcon, @JsonKey(name: "body") String body, - @JsonKey(name: "children_comments") List childrenComments, + @JsonKey(name: "children_comments") List childrenComments, @JsonKey(name: "created_at") DateTime createdAt}); } /// @nodoc -class __$$DatumImplCopyWithImpl<$Res> - extends _$DatumCopyWithImpl<$Res, _$DatumImpl> - implements _$$DatumImplCopyWith<$Res> { - __$$DatumImplCopyWithImpl( - _$DatumImpl _value, $Res Function(_$DatumImpl) _then) +class __$$CommentImplCopyWithImpl<$Res> + extends _$CommentCopyWithImpl<$Res, _$CommentImpl> + implements _$$CommentImplCopyWith<$Res> { + __$$CommentImplCopyWithImpl( + _$CommentImpl _value, $Res Function(_$CommentImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -352,7 +356,7 @@ class __$$DatumImplCopyWithImpl<$Res> Object? childrenComments = null, Object? createdAt = null, }) { - return _then(_$DatumImpl( + return _then(_$CommentImpl( id: null == id ? _value.id : id // ignore: cast_nullable_to_non_nullable @@ -372,7 +376,7 @@ class __$$DatumImplCopyWithImpl<$Res> childrenComments: null == childrenComments ? _value._childrenComments : childrenComments // ignore: cast_nullable_to_non_nullable - as List, + as List, createdAt: null == createdAt ? _value.createdAt : createdAt // ignore: cast_nullable_to_non_nullable @@ -383,19 +387,19 @@ class __$$DatumImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$DatumImpl implements _Datum { - const _$DatumImpl( +class _$CommentImpl implements _Comment { + const _$CommentImpl( {@JsonKey(name: "id") required this.id, @JsonKey(name: "author_name") required this.authorName, @JsonKey(name: "author_profile_icon") required this.authorProfileIcon, @JsonKey(name: "body") required this.body, @JsonKey(name: "children_comments") - required final List childrenComments, + required final List childrenComments, @JsonKey(name: "created_at") required this.createdAt}) : _childrenComments = childrenComments; - factory _$DatumImpl.fromJson(Map json) => - _$$DatumImplFromJson(json); + factory _$CommentImpl.fromJson(Map json) => + _$$CommentImplFromJson(json); @override @JsonKey(name: "id") @@ -409,10 +413,10 @@ class _$DatumImpl implements _Datum { @override @JsonKey(name: "body") final String body; - final List _childrenComments; + final List _childrenComments; @override @JsonKey(name: "children_comments") - List get childrenComments { + List get childrenComments { if (_childrenComments is EqualUnmodifiableListView) return _childrenComments; // ignore: implicit_dynamic_type @@ -425,14 +429,14 @@ class _$DatumImpl implements _Datum { @override String toString() { - return 'Datum(id: $id, authorName: $authorName, authorProfileIcon: $authorProfileIcon, body: $body, childrenComments: $childrenComments, createdAt: $createdAt)'; + return 'Comment(id: $id, authorName: $authorName, authorProfileIcon: $authorProfileIcon, body: $body, childrenComments: $childrenComments, createdAt: $createdAt)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$DatumImpl && + other is _$CommentImpl && (identical(other.id, id) || other.id == id) && (identical(other.authorName, authorName) || other.authorName == authorName) && @@ -459,30 +463,30 @@ class _$DatumImpl implements _Datum { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$DatumImplCopyWith<_$DatumImpl> get copyWith => - __$$DatumImplCopyWithImpl<_$DatumImpl>(this, _$identity); + _$$CommentImplCopyWith<_$CommentImpl> get copyWith => + __$$CommentImplCopyWithImpl<_$CommentImpl>(this, _$identity); @override Map toJson() { - return _$$DatumImplToJson( + return _$$CommentImplToJson( this, ); } } -abstract class _Datum implements Datum { - const factory _Datum( +abstract class _Comment implements Comment { + const factory _Comment( {@JsonKey(name: "id") required final int id, @JsonKey(name: "author_name") required final String authorName, @JsonKey(name: "author_profile_icon") required final String authorProfileIcon, @JsonKey(name: "body") required final String body, @JsonKey(name: "children_comments") - required final List childrenComments, + required final List childrenComments, @JsonKey(name: "created_at") required final DateTime createdAt}) = - _$DatumImpl; + _$CommentImpl; - factory _Datum.fromJson(Map json) = _$DatumImpl.fromJson; + factory _Comment.fromJson(Map json) = _$CommentImpl.fromJson; @override @JsonKey(name: "id") @@ -498,718 +502,12 @@ abstract class _Datum implements Datum { String get body; @override @JsonKey(name: "children_comments") - List get childrenComments; + List get childrenComments; @override @JsonKey(name: "created_at") DateTime get createdAt; @override @JsonKey(ignore: true) - _$$DatumImplCopyWith<_$DatumImpl> get copyWith => - throw _privateConstructorUsedError; -} - -Links _$LinksFromJson(Map json) { - return _Links.fromJson(json); -} - -/// @nodoc -mixin _$Links { - @JsonKey(name: "first") - String get first => throw _privateConstructorUsedError; - @JsonKey(name: "last") - String get last => throw _privateConstructorUsedError; - @JsonKey(name: "prev") - dynamic get prev => throw _privateConstructorUsedError; - @JsonKey(name: "next") - dynamic get next => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $LinksCopyWith get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LinksCopyWith<$Res> { - factory $LinksCopyWith(Links value, $Res Function(Links) then) = - _$LinksCopyWithImpl<$Res, Links>; - @useResult - $Res call( - {@JsonKey(name: "first") String first, - @JsonKey(name: "last") String last, - @JsonKey(name: "prev") dynamic prev, - @JsonKey(name: "next") dynamic next}); -} - -/// @nodoc -class _$LinksCopyWithImpl<$Res, $Val extends Links> - implements $LinksCopyWith<$Res> { - _$LinksCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? first = null, - Object? last = null, - Object? prev = freezed, - Object? next = freezed, - }) { - return _then(_value.copyWith( - first: null == first - ? _value.first - : first // ignore: cast_nullable_to_non_nullable - as String, - last: null == last - ? _value.last - : last // ignore: cast_nullable_to_non_nullable - as String, - prev: freezed == prev - ? _value.prev - : prev // ignore: cast_nullable_to_non_nullable - as dynamic, - next: freezed == next - ? _value.next - : next // ignore: cast_nullable_to_non_nullable - as dynamic, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$LinksImplCopyWith<$Res> implements $LinksCopyWith<$Res> { - factory _$$LinksImplCopyWith( - _$LinksImpl value, $Res Function(_$LinksImpl) then) = - __$$LinksImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {@JsonKey(name: "first") String first, - @JsonKey(name: "last") String last, - @JsonKey(name: "prev") dynamic prev, - @JsonKey(name: "next") dynamic next}); -} - -/// @nodoc -class __$$LinksImplCopyWithImpl<$Res> - extends _$LinksCopyWithImpl<$Res, _$LinksImpl> - implements _$$LinksImplCopyWith<$Res> { - __$$LinksImplCopyWithImpl( - _$LinksImpl _value, $Res Function(_$LinksImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? first = null, - Object? last = null, - Object? prev = freezed, - Object? next = freezed, - }) { - return _then(_$LinksImpl( - first: null == first - ? _value.first - : first // ignore: cast_nullable_to_non_nullable - as String, - last: null == last - ? _value.last - : last // ignore: cast_nullable_to_non_nullable - as String, - prev: freezed == prev - ? _value.prev - : prev // ignore: cast_nullable_to_non_nullable - as dynamic, - next: freezed == next - ? _value.next - : next // ignore: cast_nullable_to_non_nullable - as dynamic, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$LinksImpl implements _Links { - const _$LinksImpl( - {@JsonKey(name: "first") required this.first, - @JsonKey(name: "last") required this.last, - @JsonKey(name: "prev") required this.prev, - @JsonKey(name: "next") required this.next}); - - factory _$LinksImpl.fromJson(Map json) => - _$$LinksImplFromJson(json); - - @override - @JsonKey(name: "first") - final String first; - @override - @JsonKey(name: "last") - final String last; - @override - @JsonKey(name: "prev") - final dynamic prev; - @override - @JsonKey(name: "next") - final dynamic next; - - @override - String toString() { - return 'Links(first: $first, last: $last, prev: $prev, next: $next)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$LinksImpl && - (identical(other.first, first) || other.first == first) && - (identical(other.last, last) || other.last == last) && - const DeepCollectionEquality().equals(other.prev, prev) && - const DeepCollectionEquality().equals(other.next, next)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash( - runtimeType, - first, - last, - const DeepCollectionEquality().hash(prev), - const DeepCollectionEquality().hash(next)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$LinksImplCopyWith<_$LinksImpl> get copyWith => - __$$LinksImplCopyWithImpl<_$LinksImpl>(this, _$identity); - - @override - Map toJson() { - return _$$LinksImplToJson( - this, - ); - } -} - -abstract class _Links implements Links { - const factory _Links( - {@JsonKey(name: "first") required final String first, - @JsonKey(name: "last") required final String last, - @JsonKey(name: "prev") required final dynamic prev, - @JsonKey(name: "next") required final dynamic next}) = _$LinksImpl; - - factory _Links.fromJson(Map json) = _$LinksImpl.fromJson; - - @override - @JsonKey(name: "first") - String get first; - @override - @JsonKey(name: "last") - String get last; - @override - @JsonKey(name: "prev") - dynamic get prev; - @override - @JsonKey(name: "next") - dynamic get next; - @override - @JsonKey(ignore: true) - _$$LinksImplCopyWith<_$LinksImpl> get copyWith => - throw _privateConstructorUsedError; -} - -Meta _$MetaFromJson(Map json) { - return _Meta.fromJson(json); -} - -/// @nodoc -mixin _$Meta { - @JsonKey(name: "current_page") - int get currentPage => throw _privateConstructorUsedError; - @JsonKey(name: "from") - int get from => throw _privateConstructorUsedError; - @JsonKey(name: "last_page") - int get lastPage => throw _privateConstructorUsedError; - @JsonKey(name: "links") - List get links => throw _privateConstructorUsedError; - @JsonKey(name: "path") - String get path => throw _privateConstructorUsedError; - @JsonKey(name: "per_page") - int get perPage => throw _privateConstructorUsedError; - @JsonKey(name: "to") - int get to => throw _privateConstructorUsedError; - @JsonKey(name: "total") - int get total => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $MetaCopyWith get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MetaCopyWith<$Res> { - factory $MetaCopyWith(Meta value, $Res Function(Meta) then) = - _$MetaCopyWithImpl<$Res, Meta>; - @useResult - $Res call( - {@JsonKey(name: "current_page") int currentPage, - @JsonKey(name: "from") int from, - @JsonKey(name: "last_page") int lastPage, - @JsonKey(name: "links") List links, - @JsonKey(name: "path") String path, - @JsonKey(name: "per_page") int perPage, - @JsonKey(name: "to") int to, - @JsonKey(name: "total") int total}); -} - -/// @nodoc -class _$MetaCopyWithImpl<$Res, $Val extends Meta> - implements $MetaCopyWith<$Res> { - _$MetaCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? currentPage = null, - Object? from = null, - Object? lastPage = null, - Object? links = null, - Object? path = null, - Object? perPage = null, - Object? to = null, - Object? total = null, - }) { - return _then(_value.copyWith( - currentPage: null == currentPage - ? _value.currentPage - : currentPage // ignore: cast_nullable_to_non_nullable - as int, - from: null == from - ? _value.from - : from // ignore: cast_nullable_to_non_nullable - as int, - lastPage: null == lastPage - ? _value.lastPage - : lastPage // ignore: cast_nullable_to_non_nullable - as int, - links: null == links - ? _value.links - : links // ignore: cast_nullable_to_non_nullable - as List, - path: null == path - ? _value.path - : path // ignore: cast_nullable_to_non_nullable - as String, - perPage: null == perPage - ? _value.perPage - : perPage // ignore: cast_nullable_to_non_nullable - as int, - to: null == to - ? _value.to - : to // ignore: cast_nullable_to_non_nullable - as int, - total: null == total - ? _value.total - : total // ignore: cast_nullable_to_non_nullable - as int, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$MetaImplCopyWith<$Res> implements $MetaCopyWith<$Res> { - factory _$$MetaImplCopyWith( - _$MetaImpl value, $Res Function(_$MetaImpl) then) = - __$$MetaImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {@JsonKey(name: "current_page") int currentPage, - @JsonKey(name: "from") int from, - @JsonKey(name: "last_page") int lastPage, - @JsonKey(name: "links") List links, - @JsonKey(name: "path") String path, - @JsonKey(name: "per_page") int perPage, - @JsonKey(name: "to") int to, - @JsonKey(name: "total") int total}); -} - -/// @nodoc -class __$$MetaImplCopyWithImpl<$Res> - extends _$MetaCopyWithImpl<$Res, _$MetaImpl> - implements _$$MetaImplCopyWith<$Res> { - __$$MetaImplCopyWithImpl(_$MetaImpl _value, $Res Function(_$MetaImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? currentPage = null, - Object? from = null, - Object? lastPage = null, - Object? links = null, - Object? path = null, - Object? perPage = null, - Object? to = null, - Object? total = null, - }) { - return _then(_$MetaImpl( - currentPage: null == currentPage - ? _value.currentPage - : currentPage // ignore: cast_nullable_to_non_nullable - as int, - from: null == from - ? _value.from - : from // ignore: cast_nullable_to_non_nullable - as int, - lastPage: null == lastPage - ? _value.lastPage - : lastPage // ignore: cast_nullable_to_non_nullable - as int, - links: null == links - ? _value._links - : links // ignore: cast_nullable_to_non_nullable - as List, - path: null == path - ? _value.path - : path // ignore: cast_nullable_to_non_nullable - as String, - perPage: null == perPage - ? _value.perPage - : perPage // ignore: cast_nullable_to_non_nullable - as int, - to: null == to - ? _value.to - : to // ignore: cast_nullable_to_non_nullable - as int, - total: null == total - ? _value.total - : total // ignore: cast_nullable_to_non_nullable - as int, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$MetaImpl implements _Meta { - const _$MetaImpl( - {@JsonKey(name: "current_page") required this.currentPage, - @JsonKey(name: "from") required this.from, - @JsonKey(name: "last_page") required this.lastPage, - @JsonKey(name: "links") required final List links, - @JsonKey(name: "path") required this.path, - @JsonKey(name: "per_page") required this.perPage, - @JsonKey(name: "to") required this.to, - @JsonKey(name: "total") required this.total}) - : _links = links; - - factory _$MetaImpl.fromJson(Map json) => - _$$MetaImplFromJson(json); - - @override - @JsonKey(name: "current_page") - final int currentPage; - @override - @JsonKey(name: "from") - final int from; - @override - @JsonKey(name: "last_page") - final int lastPage; - final List _links; - @override - @JsonKey(name: "links") - List get links { - if (_links is EqualUnmodifiableListView) return _links; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_links); - } - - @override - @JsonKey(name: "path") - final String path; - @override - @JsonKey(name: "per_page") - final int perPage; - @override - @JsonKey(name: "to") - final int to; - @override - @JsonKey(name: "total") - final int total; - - @override - String toString() { - return 'Meta(currentPage: $currentPage, from: $from, lastPage: $lastPage, links: $links, path: $path, perPage: $perPage, to: $to, total: $total)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$MetaImpl && - (identical(other.currentPage, currentPage) || - other.currentPage == currentPage) && - (identical(other.from, from) || other.from == from) && - (identical(other.lastPage, lastPage) || - other.lastPage == lastPage) && - const DeepCollectionEquality().equals(other._links, _links) && - (identical(other.path, path) || other.path == path) && - (identical(other.perPage, perPage) || other.perPage == perPage) && - (identical(other.to, to) || other.to == to) && - (identical(other.total, total) || other.total == total)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, currentPage, from, lastPage, - const DeepCollectionEquality().hash(_links), path, perPage, to, total); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$MetaImplCopyWith<_$MetaImpl> get copyWith => - __$$MetaImplCopyWithImpl<_$MetaImpl>(this, _$identity); - - @override - Map toJson() { - return _$$MetaImplToJson( - this, - ); - } -} - -abstract class _Meta implements Meta { - const factory _Meta( - {@JsonKey(name: "current_page") required final int currentPage, - @JsonKey(name: "from") required final int from, - @JsonKey(name: "last_page") required final int lastPage, - @JsonKey(name: "links") required final List links, - @JsonKey(name: "path") required final String path, - @JsonKey(name: "per_page") required final int perPage, - @JsonKey(name: "to") required final int to, - @JsonKey(name: "total") required final int total}) = _$MetaImpl; - - factory _Meta.fromJson(Map json) = _$MetaImpl.fromJson; - - @override - @JsonKey(name: "current_page") - int get currentPage; - @override - @JsonKey(name: "from") - int get from; - @override - @JsonKey(name: "last_page") - int get lastPage; - @override - @JsonKey(name: "links") - List get links; - @override - @JsonKey(name: "path") - String get path; - @override - @JsonKey(name: "per_page") - int get perPage; - @override - @JsonKey(name: "to") - int get to; - @override - @JsonKey(name: "total") - int get total; - @override - @JsonKey(ignore: true) - _$$MetaImplCopyWith<_$MetaImpl> get copyWith => - throw _privateConstructorUsedError; -} - -Link _$LinkFromJson(Map json) { - return _Link.fromJson(json); -} - -/// @nodoc -mixin _$Link { - @JsonKey(name: "url") - String? get url => throw _privateConstructorUsedError; - @JsonKey(name: "label") - String get label => throw _privateConstructorUsedError; - @JsonKey(name: "active") - bool get active => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $LinkCopyWith get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LinkCopyWith<$Res> { - factory $LinkCopyWith(Link value, $Res Function(Link) then) = - _$LinkCopyWithImpl<$Res, Link>; - @useResult - $Res call( - {@JsonKey(name: "url") String? url, - @JsonKey(name: "label") String label, - @JsonKey(name: "active") bool active}); -} - -/// @nodoc -class _$LinkCopyWithImpl<$Res, $Val extends Link> - implements $LinkCopyWith<$Res> { - _$LinkCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? url = freezed, - Object? label = null, - Object? active = null, - }) { - return _then(_value.copyWith( - url: freezed == url - ? _value.url - : url // ignore: cast_nullable_to_non_nullable - as String?, - label: null == label - ? _value.label - : label // ignore: cast_nullable_to_non_nullable - as String, - active: null == active - ? _value.active - : active // ignore: cast_nullable_to_non_nullable - as bool, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$LinkImplCopyWith<$Res> implements $LinkCopyWith<$Res> { - factory _$$LinkImplCopyWith( - _$LinkImpl value, $Res Function(_$LinkImpl) then) = - __$$LinkImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {@JsonKey(name: "url") String? url, - @JsonKey(name: "label") String label, - @JsonKey(name: "active") bool active}); -} - -/// @nodoc -class __$$LinkImplCopyWithImpl<$Res> - extends _$LinkCopyWithImpl<$Res, _$LinkImpl> - implements _$$LinkImplCopyWith<$Res> { - __$$LinkImplCopyWithImpl(_$LinkImpl _value, $Res Function(_$LinkImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? url = freezed, - Object? label = null, - Object? active = null, - }) { - return _then(_$LinkImpl( - url: freezed == url - ? _value.url - : url // ignore: cast_nullable_to_non_nullable - as String?, - label: null == label - ? _value.label - : label // ignore: cast_nullable_to_non_nullable - as String, - active: null == active - ? _value.active - : active // ignore: cast_nullable_to_non_nullable - as bool, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$LinkImpl implements _Link { - const _$LinkImpl( - {@JsonKey(name: "url") required this.url, - @JsonKey(name: "label") required this.label, - @JsonKey(name: "active") required this.active}); - - factory _$LinkImpl.fromJson(Map json) => - _$$LinkImplFromJson(json); - - @override - @JsonKey(name: "url") - final String? url; - @override - @JsonKey(name: "label") - final String label; - @override - @JsonKey(name: "active") - final bool active; - - @override - String toString() { - return 'Link(url: $url, label: $label, active: $active)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$LinkImpl && - (identical(other.url, url) || other.url == url) && - (identical(other.label, label) || other.label == label) && - (identical(other.active, active) || other.active == active)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, url, label, active); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$LinkImplCopyWith<_$LinkImpl> get copyWith => - __$$LinkImplCopyWithImpl<_$LinkImpl>(this, _$identity); - - @override - Map toJson() { - return _$$LinkImplToJson( - this, - ); - } -} - -abstract class _Link implements Link { - const factory _Link( - {@JsonKey(name: "url") required final String? url, - @JsonKey(name: "label") required final String label, - @JsonKey(name: "active") required final bool active}) = _$LinkImpl; - - factory _Link.fromJson(Map json) = _$LinkImpl.fromJson; - - @override - @JsonKey(name: "url") - String? get url; - @override - @JsonKey(name: "label") - String get label; - @override - @JsonKey(name: "active") - bool get active; - @override - @JsonKey(ignore: true) - _$$LinkImplCopyWith<_$LinkImpl> get copyWith => + _$$CommentImplCopyWith<_$CommentImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/lib/features/feed/models/comment_model.g.dart b/lib/features/feed/models/comment_model.g.dart index 0c92d582..1410cfcc 100644 --- a/lib/features/feed/models/comment_model.g.dart +++ b/lib/features/feed/models/comment_model.g.dart @@ -6,34 +6,35 @@ part of 'comment_model.dart'; // JsonSerializableGenerator // ************************************************************************** -_$CommentImpl _$$CommentImplFromJson(Map json) => - _$CommentImpl( +_$CommentModelImpl _$$CommentModelImplFromJson(Map json) => + _$CommentModelImpl( data: (json['data'] as List) - .map((e) => Datum.fromJson(e as Map)) + .map((e) => Comment.fromJson(e as Map)) .toList(), links: Links.fromJson(json['links'] as Map), meta: Meta.fromJson(json['meta'] as Map), ); -Map _$$CommentImplToJson(_$CommentImpl instance) => +Map _$$CommentModelImplToJson(_$CommentModelImpl instance) => { 'data': instance.data, 'links': instance.links, 'meta': instance.meta, }; -_$DatumImpl _$$DatumImplFromJson(Map json) => _$DatumImpl( +_$CommentImpl _$$CommentImplFromJson(Map json) => + _$CommentImpl( id: (json['id'] as num).toInt(), authorName: json['author_name'] as String, authorProfileIcon: json['author_profile_icon'] as String, body: json['body'] as String, childrenComments: (json['children_comments'] as List) - .map((e) => Datum.fromJson(e as Map)) + .map((e) => Comment.fromJson(e as Map)) .toList(), createdAt: DateTime.parse(json['created_at'] as String), ); -Map _$$DatumImplToJson(_$DatumImpl instance) => +Map _$$CommentImplToJson(_$CommentImpl instance) => { 'id': instance.id, 'author_name': instance.authorName, @@ -42,56 +43,3 @@ Map _$$DatumImplToJson(_$DatumImpl instance) => 'children_comments': instance.childrenComments, 'created_at': instance.createdAt.toIso8601String(), }; - -_$LinksImpl _$$LinksImplFromJson(Map json) => _$LinksImpl( - first: json['first'] as String, - last: json['last'] as String, - prev: json['prev'], - next: json['next'], - ); - -Map _$$LinksImplToJson(_$LinksImpl instance) => - { - 'first': instance.first, - 'last': instance.last, - 'prev': instance.prev, - 'next': instance.next, - }; - -_$MetaImpl _$$MetaImplFromJson(Map json) => _$MetaImpl( - currentPage: (json['current_page'] as num).toInt(), - from: (json['from'] as num).toInt(), - lastPage: (json['last_page'] as num).toInt(), - links: (json['links'] as List) - .map((e) => Link.fromJson(e as Map)) - .toList(), - path: json['path'] as String, - perPage: (json['per_page'] as num).toInt(), - to: (json['to'] as num).toInt(), - total: (json['total'] as num).toInt(), - ); - -Map _$$MetaImplToJson(_$MetaImpl instance) => - { - 'current_page': instance.currentPage, - 'from': instance.from, - 'last_page': instance.lastPage, - 'links': instance.links, - 'path': instance.path, - 'per_page': instance.perPage, - 'to': instance.to, - 'total': instance.total, - }; - -_$LinkImpl _$$LinkImplFromJson(Map json) => _$LinkImpl( - url: json['url'] as String?, - label: json['label'] as String, - active: json['active'] as bool, - ); - -Map _$$LinkImplToJson(_$LinkImpl instance) => - { - 'url': instance.url, - 'label': instance.label, - 'active': instance.active, - }; diff --git a/lib/features/feed/models/diets_pagination_model.dart b/lib/features/feed/models/diets_pagination_model.dart index 10fb6afb..f56c606c 100644 --- a/lib/features/feed/models/diets_pagination_model.dart +++ b/lib/features/feed/models/diets_pagination_model.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/core/models/base_models.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'diets_pagination_model.freezed.dart'; @@ -6,7 +7,7 @@ part 'diets_pagination_model.g.dart'; @freezed class DietsPagination with _$DietsPagination { const factory DietsPagination({ - @JsonKey(name: "data") required List data, + @JsonKey(name: "data") required List data, @JsonKey(name: "links") required Links links, @JsonKey(name: "meta") required Meta meta, }) = _DietsPagination; @@ -15,23 +16,23 @@ class DietsPagination with _$DietsPagination { } @freezed -class Datum with _$Datum { - const factory Datum({ +class Diet with _$Diet { + const factory Diet({ @JsonKey(name: "id") required int id, @JsonKey(name: "name") required String name, @JsonKey(name: "image") required String image, @JsonKey(name: "duration") required int duration, @JsonKey(name: "state") required String state, - @JsonKey(name: "type") required Type type, + @JsonKey(name: "type") required DietType type, @JsonKey(name: "details") required String details, @JsonKey(name: "daily_schedule") required List>> dailySchedule, @JsonKey(name: "author") required Author author, @JsonKey(name: "total_likes") required int totalLikes, @JsonKey(name: "total_views") required int totalViews, @JsonKey(name: "total_comments") required int totalComments, - }) = _Datum; + }) = _Diet; - factory Datum.fromJson(Map json) => _$DatumFromJson(json); + factory Diet.fromJson(Map json) => _$DietFromJson(json); } @freezed @@ -70,54 +71,15 @@ enum Portion { final portionValues = EnumValues({"grams": Portion.GRAMS, "milliliters": Portion.MILLILITERS, "pcs": Portion.PCS}); @freezed -class Type with _$Type { - const factory Type({ +class DietType with _$DietType { + const factory DietType({ @JsonKey(name: "alko") bool? alko, @JsonKey(name: "veg") bool? veg, @JsonKey(name: "corb") bool? corb, @JsonKey(name: "meat") bool? meat, - }) = _Type; + }) = _DietType; - factory Type.fromJson(Map json) => _$TypeFromJson(json); -} - -@freezed -class Links with _$Links { - const factory Links({ - @JsonKey(name: "first") required String first, - @JsonKey(name: "last") required String last, - @JsonKey(name: "prev") required dynamic prev, - @JsonKey(name: "next") required dynamic next, - }) = _Links; - - factory Links.fromJson(Map json) => _$LinksFromJson(json); -} - -@freezed -class Meta with _$Meta { - const factory Meta({ - @JsonKey(name: "current_page") required int currentPage, - @JsonKey(name: "from") required int from, - @JsonKey(name: "last_page") required int lastPage, - @JsonKey(name: "links") required List links, - @JsonKey(name: "path") required String path, - @JsonKey(name: "per_page") required int perPage, - @JsonKey(name: "to") required int to, - @JsonKey(name: "total") required int total, - }) = _Meta; - - factory Meta.fromJson(Map json) => _$MetaFromJson(json); -} - -@freezed -class Link with _$Link { - const factory Link({ - @JsonKey(name: "url") required String? url, - @JsonKey(name: "label") required String label, - @JsonKey(name: "active") required bool active, - }) = _Link; - - factory Link.fromJson(Map json) => _$LinkFromJson(json); + factory DietType.fromJson(Map json) => _$DietTypeFromJson(json); } class EnumValues { diff --git a/lib/features/feed/models/diets_pagination_model.freezed.dart b/lib/features/feed/models/diets_pagination_model.freezed.dart index 2c402671..04835daf 100644 --- a/lib/features/feed/models/diets_pagination_model.freezed.dart +++ b/lib/features/feed/models/diets_pagination_model.freezed.dart @@ -21,7 +21,7 @@ DietsPagination _$DietsPaginationFromJson(Map json) { /// @nodoc mixin _$DietsPagination { @JsonKey(name: "data") - List get data => throw _privateConstructorUsedError; + List get data => throw _privateConstructorUsedError; @JsonKey(name: "links") Links get links => throw _privateConstructorUsedError; @JsonKey(name: "meta") @@ -40,7 +40,7 @@ abstract class $DietsPaginationCopyWith<$Res> { _$DietsPaginationCopyWithImpl<$Res, DietsPagination>; @useResult $Res call( - {@JsonKey(name: "data") List data, + {@JsonKey(name: "data") List data, @JsonKey(name: "links") Links links, @JsonKey(name: "meta") Meta meta}); @@ -69,7 +69,7 @@ class _$DietsPaginationCopyWithImpl<$Res, $Val extends DietsPagination> data: null == data ? _value.data : data // ignore: cast_nullable_to_non_nullable - as List, + as List, links: null == links ? _value.links : links // ignore: cast_nullable_to_non_nullable @@ -107,7 +107,7 @@ abstract class _$$DietsPaginationImplCopyWith<$Res> @override @useResult $Res call( - {@JsonKey(name: "data") List data, + {@JsonKey(name: "data") List data, @JsonKey(name: "links") Links links, @JsonKey(name: "meta") Meta meta}); @@ -136,7 +136,7 @@ class __$$DietsPaginationImplCopyWithImpl<$Res> data: null == data ? _value._data : data // ignore: cast_nullable_to_non_nullable - as List, + as List, links: null == links ? _value.links : links // ignore: cast_nullable_to_non_nullable @@ -153,7 +153,7 @@ class __$$DietsPaginationImplCopyWithImpl<$Res> @JsonSerializable() class _$DietsPaginationImpl implements _DietsPagination { const _$DietsPaginationImpl( - {@JsonKey(name: "data") required final List data, + {@JsonKey(name: "data") required final List data, @JsonKey(name: "links") required this.links, @JsonKey(name: "meta") required this.meta}) : _data = data; @@ -161,10 +161,10 @@ class _$DietsPaginationImpl implements _DietsPagination { factory _$DietsPaginationImpl.fromJson(Map json) => _$$DietsPaginationImplFromJson(json); - final List _data; + final List _data; @override @JsonKey(name: "data") - List get data { + List get data { if (_data is EqualUnmodifiableListView) return _data; // ignore: implicit_dynamic_type return EqualUnmodifiableListView(_data); @@ -214,7 +214,7 @@ class _$DietsPaginationImpl implements _DietsPagination { abstract class _DietsPagination implements DietsPagination { const factory _DietsPagination( - {@JsonKey(name: "data") required final List data, + {@JsonKey(name: "data") required final List data, @JsonKey(name: "links") required final Links links, @JsonKey(name: "meta") required final Meta meta}) = _$DietsPaginationImpl; @@ -223,7 +223,7 @@ abstract class _DietsPagination implements DietsPagination { @override @JsonKey(name: "data") - List get data; + List get data; @override @JsonKey(name: "links") Links get links; @@ -236,12 +236,12 @@ abstract class _DietsPagination implements DietsPagination { throw _privateConstructorUsedError; } -Datum _$DatumFromJson(Map json) { - return _Datum.fromJson(json); +Diet _$DietFromJson(Map json) { + return _Diet.fromJson(json); } /// @nodoc -mixin _$Datum { +mixin _$Diet { @JsonKey(name: "id") int get id => throw _privateConstructorUsedError; @JsonKey(name: "name") @@ -253,7 +253,7 @@ mixin _$Datum { @JsonKey(name: "state") String get state => throw _privateConstructorUsedError; @JsonKey(name: "type") - Type get type => throw _privateConstructorUsedError; + DietType get type => throw _privateConstructorUsedError; @JsonKey(name: "details") String get details => throw _privateConstructorUsedError; @JsonKey(name: "daily_schedule") @@ -270,13 +270,13 @@ mixin _$Datum { Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $DatumCopyWith get copyWith => throw _privateConstructorUsedError; + $DietCopyWith get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $DatumCopyWith<$Res> { - factory $DatumCopyWith(Datum value, $Res Function(Datum) then) = - _$DatumCopyWithImpl<$Res, Datum>; +abstract class $DietCopyWith<$Res> { + factory $DietCopyWith(Diet value, $Res Function(Diet) then) = + _$DietCopyWithImpl<$Res, Diet>; @useResult $Res call( {@JsonKey(name: "id") int id, @@ -284,7 +284,7 @@ abstract class $DatumCopyWith<$Res> { @JsonKey(name: "image") String image, @JsonKey(name: "duration") int duration, @JsonKey(name: "state") String state, - @JsonKey(name: "type") Type type, + @JsonKey(name: "type") DietType type, @JsonKey(name: "details") String details, @JsonKey(name: "daily_schedule") List>> dailySchedule, @@ -293,14 +293,14 @@ abstract class $DatumCopyWith<$Res> { @JsonKey(name: "total_views") int totalViews, @JsonKey(name: "total_comments") int totalComments}); - $TypeCopyWith<$Res> get type; + $DietTypeCopyWith<$Res> get type; $AuthorCopyWith<$Res> get author; } /// @nodoc -class _$DatumCopyWithImpl<$Res, $Val extends Datum> - implements $DatumCopyWith<$Res> { - _$DatumCopyWithImpl(this._value, this._then); +class _$DietCopyWithImpl<$Res, $Val extends Diet> + implements $DietCopyWith<$Res> { + _$DietCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -347,7 +347,7 @@ class _$DatumCopyWithImpl<$Res, $Val extends Datum> type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable - as Type, + as DietType, details: null == details ? _value.details : details // ignore: cast_nullable_to_non_nullable @@ -377,8 +377,8 @@ class _$DatumCopyWithImpl<$Res, $Val extends Datum> @override @pragma('vm:prefer-inline') - $TypeCopyWith<$Res> get type { - return $TypeCopyWith<$Res>(_value.type, (value) { + $DietTypeCopyWith<$Res> get type { + return $DietTypeCopyWith<$Res>(_value.type, (value) { return _then(_value.copyWith(type: value) as $Val); }); } @@ -393,10 +393,10 @@ class _$DatumCopyWithImpl<$Res, $Val extends Datum> } /// @nodoc -abstract class _$$DatumImplCopyWith<$Res> implements $DatumCopyWith<$Res> { - factory _$$DatumImplCopyWith( - _$DatumImpl value, $Res Function(_$DatumImpl) then) = - __$$DatumImplCopyWithImpl<$Res>; +abstract class _$$DietImplCopyWith<$Res> implements $DietCopyWith<$Res> { + factory _$$DietImplCopyWith( + _$DietImpl value, $Res Function(_$DietImpl) then) = + __$$DietImplCopyWithImpl<$Res>; @override @useResult $Res call( @@ -405,7 +405,7 @@ abstract class _$$DatumImplCopyWith<$Res> implements $DatumCopyWith<$Res> { @JsonKey(name: "image") String image, @JsonKey(name: "duration") int duration, @JsonKey(name: "state") String state, - @JsonKey(name: "type") Type type, + @JsonKey(name: "type") DietType type, @JsonKey(name: "details") String details, @JsonKey(name: "daily_schedule") List>> dailySchedule, @@ -415,17 +415,16 @@ abstract class _$$DatumImplCopyWith<$Res> implements $DatumCopyWith<$Res> { @JsonKey(name: "total_comments") int totalComments}); @override - $TypeCopyWith<$Res> get type; + $DietTypeCopyWith<$Res> get type; @override $AuthorCopyWith<$Res> get author; } /// @nodoc -class __$$DatumImplCopyWithImpl<$Res> - extends _$DatumCopyWithImpl<$Res, _$DatumImpl> - implements _$$DatumImplCopyWith<$Res> { - __$$DatumImplCopyWithImpl( - _$DatumImpl _value, $Res Function(_$DatumImpl) _then) +class __$$DietImplCopyWithImpl<$Res> + extends _$DietCopyWithImpl<$Res, _$DietImpl> + implements _$$DietImplCopyWith<$Res> { + __$$DietImplCopyWithImpl(_$DietImpl _value, $Res Function(_$DietImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -444,7 +443,7 @@ class __$$DatumImplCopyWithImpl<$Res> Object? totalViews = null, Object? totalComments = null, }) { - return _then(_$DatumImpl( + return _then(_$DietImpl( id: null == id ? _value.id : id // ignore: cast_nullable_to_non_nullable @@ -468,7 +467,7 @@ class __$$DatumImplCopyWithImpl<$Res> type: null == type ? _value.type : type // ignore: cast_nullable_to_non_nullable - as Type, + as DietType, details: null == details ? _value.details : details // ignore: cast_nullable_to_non_nullable @@ -499,8 +498,8 @@ class __$$DatumImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$DatumImpl implements _Datum { - const _$DatumImpl( +class _$DietImpl implements _Diet { + const _$DietImpl( {@JsonKey(name: "id") required this.id, @JsonKey(name: "name") required this.name, @JsonKey(name: "image") required this.image, @@ -516,8 +515,8 @@ class _$DatumImpl implements _Datum { @JsonKey(name: "total_comments") required this.totalComments}) : _dailySchedule = dailySchedule; - factory _$DatumImpl.fromJson(Map json) => - _$$DatumImplFromJson(json); + factory _$DietImpl.fromJson(Map json) => + _$$DietImplFromJson(json); @override @JsonKey(name: "id") @@ -536,7 +535,7 @@ class _$DatumImpl implements _Datum { final String state; @override @JsonKey(name: "type") - final Type type; + final DietType type; @override @JsonKey(name: "details") final String details; @@ -564,14 +563,14 @@ class _$DatumImpl implements _Datum { @override String toString() { - return 'Datum(id: $id, name: $name, image: $image, duration: $duration, state: $state, type: $type, details: $details, dailySchedule: $dailySchedule, author: $author, totalLikes: $totalLikes, totalViews: $totalViews, totalComments: $totalComments)'; + return 'Diet(id: $id, name: $name, image: $image, duration: $duration, state: $state, type: $type, details: $details, dailySchedule: $dailySchedule, author: $author, totalLikes: $totalLikes, totalViews: $totalViews, totalComments: $totalComments)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$DatumImpl && + other is _$DietImpl && (identical(other.id, id) || other.id == id) && (identical(other.name, name) || other.name == name) && (identical(other.image, image) || other.image == image) && @@ -611,25 +610,25 @@ class _$DatumImpl implements _Datum { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$DatumImplCopyWith<_$DatumImpl> get copyWith => - __$$DatumImplCopyWithImpl<_$DatumImpl>(this, _$identity); + _$$DietImplCopyWith<_$DietImpl> get copyWith => + __$$DietImplCopyWithImpl<_$DietImpl>(this, _$identity); @override Map toJson() { - return _$$DatumImplToJson( + return _$$DietImplToJson( this, ); } } -abstract class _Datum implements Datum { - const factory _Datum( +abstract class _Diet implements Diet { + const factory _Diet( {@JsonKey(name: "id") required final int id, @JsonKey(name: "name") required final String name, @JsonKey(name: "image") required final String image, @JsonKey(name: "duration") required final int duration, @JsonKey(name: "state") required final String state, - @JsonKey(name: "type") required final Type type, + @JsonKey(name: "type") required final DietType type, @JsonKey(name: "details") required final String details, @JsonKey(name: "daily_schedule") required final List>> dailySchedule, @@ -637,9 +636,9 @@ abstract class _Datum implements Datum { @JsonKey(name: "total_likes") required final int totalLikes, @JsonKey(name: "total_views") required final int totalViews, @JsonKey(name: "total_comments") required final int totalComments}) = - _$DatumImpl; + _$DietImpl; - factory _Datum.fromJson(Map json) = _$DatumImpl.fromJson; + factory _Diet.fromJson(Map json) = _$DietImpl.fromJson; @override @JsonKey(name: "id") @@ -658,7 +657,7 @@ abstract class _Datum implements Datum { String get state; @override @JsonKey(name: "type") - Type get type; + DietType get type; @override @JsonKey(name: "details") String get details; @@ -679,7 +678,7 @@ abstract class _Datum implements Datum { int get totalComments; @override @JsonKey(ignore: true) - _$$DatumImplCopyWith<_$DatumImpl> get copyWith => + _$$DietImplCopyWith<_$DietImpl> get copyWith => throw _privateConstructorUsedError; } @@ -1112,12 +1111,12 @@ abstract class _DailySchedule implements DailySchedule { throw _privateConstructorUsedError; } -Type _$TypeFromJson(Map json) { - return _Type.fromJson(json); +DietType _$DietTypeFromJson(Map json) { + return _DietType.fromJson(json); } /// @nodoc -mixin _$Type { +mixin _$DietType { @JsonKey(name: "alko") bool? get alko => throw _privateConstructorUsedError; @JsonKey(name: "veg") @@ -1129,13 +1128,14 @@ mixin _$Type { Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $TypeCopyWith get copyWith => throw _privateConstructorUsedError; + $DietTypeCopyWith get copyWith => + throw _privateConstructorUsedError; } /// @nodoc -abstract class $TypeCopyWith<$Res> { - factory $TypeCopyWith(Type value, $Res Function(Type) then) = - _$TypeCopyWithImpl<$Res, Type>; +abstract class $DietTypeCopyWith<$Res> { + factory $DietTypeCopyWith(DietType value, $Res Function(DietType) then) = + _$DietTypeCopyWithImpl<$Res, DietType>; @useResult $Res call( {@JsonKey(name: "alko") bool? alko, @@ -1145,9 +1145,9 @@ abstract class $TypeCopyWith<$Res> { } /// @nodoc -class _$TypeCopyWithImpl<$Res, $Val extends Type> - implements $TypeCopyWith<$Res> { - _$TypeCopyWithImpl(this._value, this._then); +class _$DietTypeCopyWithImpl<$Res, $Val extends DietType> + implements $DietTypeCopyWith<$Res> { + _$DietTypeCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -1184,10 +1184,11 @@ class _$TypeCopyWithImpl<$Res, $Val extends Type> } /// @nodoc -abstract class _$$TypeImplCopyWith<$Res> implements $TypeCopyWith<$Res> { - factory _$$TypeImplCopyWith( - _$TypeImpl value, $Res Function(_$TypeImpl) then) = - __$$TypeImplCopyWithImpl<$Res>; +abstract class _$$DietTypeImplCopyWith<$Res> + implements $DietTypeCopyWith<$Res> { + factory _$$DietTypeImplCopyWith( + _$DietTypeImpl value, $Res Function(_$DietTypeImpl) then) = + __$$DietTypeImplCopyWithImpl<$Res>; @override @useResult $Res call( @@ -1198,10 +1199,11 @@ abstract class _$$TypeImplCopyWith<$Res> implements $TypeCopyWith<$Res> { } /// @nodoc -class __$$TypeImplCopyWithImpl<$Res> - extends _$TypeCopyWithImpl<$Res, _$TypeImpl> - implements _$$TypeImplCopyWith<$Res> { - __$$TypeImplCopyWithImpl(_$TypeImpl _value, $Res Function(_$TypeImpl) _then) +class __$$DietTypeImplCopyWithImpl<$Res> + extends _$DietTypeCopyWithImpl<$Res, _$DietTypeImpl> + implements _$$DietTypeImplCopyWith<$Res> { + __$$DietTypeImplCopyWithImpl( + _$DietTypeImpl _value, $Res Function(_$DietTypeImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -1212,7 +1214,7 @@ class __$$TypeImplCopyWithImpl<$Res> Object? corb = freezed, Object? meat = freezed, }) { - return _then(_$TypeImpl( + return _then(_$DietTypeImpl( alko: freezed == alko ? _value.alko : alko // ignore: cast_nullable_to_non_nullable @@ -1235,15 +1237,15 @@ class __$$TypeImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$TypeImpl implements _Type { - const _$TypeImpl( +class _$DietTypeImpl implements _DietType { + const _$DietTypeImpl( {@JsonKey(name: "alko") this.alko, @JsonKey(name: "veg") this.veg, @JsonKey(name: "corb") this.corb, @JsonKey(name: "meat") this.meat}); - factory _$TypeImpl.fromJson(Map json) => - _$$TypeImplFromJson(json); + factory _$DietTypeImpl.fromJson(Map json) => + _$$DietTypeImplFromJson(json); @override @JsonKey(name: "alko") @@ -1260,14 +1262,14 @@ class _$TypeImpl implements _Type { @override String toString() { - return 'Type(alko: $alko, veg: $veg, corb: $corb, meat: $meat)'; + return 'DietType(alko: $alko, veg: $veg, corb: $corb, meat: $meat)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$TypeImpl && + other is _$DietTypeImpl && (identical(other.alko, alko) || other.alko == alko) && (identical(other.veg, veg) || other.veg == veg) && (identical(other.corb, corb) || other.corb == corb) && @@ -1281,25 +1283,26 @@ class _$TypeImpl implements _Type { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$TypeImplCopyWith<_$TypeImpl> get copyWith => - __$$TypeImplCopyWithImpl<_$TypeImpl>(this, _$identity); + _$$DietTypeImplCopyWith<_$DietTypeImpl> get copyWith => + __$$DietTypeImplCopyWithImpl<_$DietTypeImpl>(this, _$identity); @override Map toJson() { - return _$$TypeImplToJson( + return _$$DietTypeImplToJson( this, ); } } -abstract class _Type implements Type { - const factory _Type( +abstract class _DietType implements DietType { + const factory _DietType( {@JsonKey(name: "alko") final bool? alko, @JsonKey(name: "veg") final bool? veg, @JsonKey(name: "corb") final bool? corb, - @JsonKey(name: "meat") final bool? meat}) = _$TypeImpl; + @JsonKey(name: "meat") final bool? meat}) = _$DietTypeImpl; - factory _Type.fromJson(Map json) = _$TypeImpl.fromJson; + factory _DietType.fromJson(Map json) = + _$DietTypeImpl.fromJson; @override @JsonKey(name: "alko") @@ -1315,712 +1318,6 @@ abstract class _Type implements Type { bool? get meat; @override @JsonKey(ignore: true) - _$$TypeImplCopyWith<_$TypeImpl> get copyWith => - throw _privateConstructorUsedError; -} - -Links _$LinksFromJson(Map json) { - return _Links.fromJson(json); -} - -/// @nodoc -mixin _$Links { - @JsonKey(name: "first") - String get first => throw _privateConstructorUsedError; - @JsonKey(name: "last") - String get last => throw _privateConstructorUsedError; - @JsonKey(name: "prev") - dynamic get prev => throw _privateConstructorUsedError; - @JsonKey(name: "next") - dynamic get next => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $LinksCopyWith get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LinksCopyWith<$Res> { - factory $LinksCopyWith(Links value, $Res Function(Links) then) = - _$LinksCopyWithImpl<$Res, Links>; - @useResult - $Res call( - {@JsonKey(name: "first") String first, - @JsonKey(name: "last") String last, - @JsonKey(name: "prev") dynamic prev, - @JsonKey(name: "next") dynamic next}); -} - -/// @nodoc -class _$LinksCopyWithImpl<$Res, $Val extends Links> - implements $LinksCopyWith<$Res> { - _$LinksCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? first = null, - Object? last = null, - Object? prev = freezed, - Object? next = freezed, - }) { - return _then(_value.copyWith( - first: null == first - ? _value.first - : first // ignore: cast_nullable_to_non_nullable - as String, - last: null == last - ? _value.last - : last // ignore: cast_nullable_to_non_nullable - as String, - prev: freezed == prev - ? _value.prev - : prev // ignore: cast_nullable_to_non_nullable - as dynamic, - next: freezed == next - ? _value.next - : next // ignore: cast_nullable_to_non_nullable - as dynamic, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$LinksImplCopyWith<$Res> implements $LinksCopyWith<$Res> { - factory _$$LinksImplCopyWith( - _$LinksImpl value, $Res Function(_$LinksImpl) then) = - __$$LinksImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {@JsonKey(name: "first") String first, - @JsonKey(name: "last") String last, - @JsonKey(name: "prev") dynamic prev, - @JsonKey(name: "next") dynamic next}); -} - -/// @nodoc -class __$$LinksImplCopyWithImpl<$Res> - extends _$LinksCopyWithImpl<$Res, _$LinksImpl> - implements _$$LinksImplCopyWith<$Res> { - __$$LinksImplCopyWithImpl( - _$LinksImpl _value, $Res Function(_$LinksImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? first = null, - Object? last = null, - Object? prev = freezed, - Object? next = freezed, - }) { - return _then(_$LinksImpl( - first: null == first - ? _value.first - : first // ignore: cast_nullable_to_non_nullable - as String, - last: null == last - ? _value.last - : last // ignore: cast_nullable_to_non_nullable - as String, - prev: freezed == prev - ? _value.prev - : prev // ignore: cast_nullable_to_non_nullable - as dynamic, - next: freezed == next - ? _value.next - : next // ignore: cast_nullable_to_non_nullable - as dynamic, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$LinksImpl implements _Links { - const _$LinksImpl( - {@JsonKey(name: "first") required this.first, - @JsonKey(name: "last") required this.last, - @JsonKey(name: "prev") required this.prev, - @JsonKey(name: "next") required this.next}); - - factory _$LinksImpl.fromJson(Map json) => - _$$LinksImplFromJson(json); - - @override - @JsonKey(name: "first") - final String first; - @override - @JsonKey(name: "last") - final String last; - @override - @JsonKey(name: "prev") - final dynamic prev; - @override - @JsonKey(name: "next") - final dynamic next; - - @override - String toString() { - return 'Links(first: $first, last: $last, prev: $prev, next: $next)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$LinksImpl && - (identical(other.first, first) || other.first == first) && - (identical(other.last, last) || other.last == last) && - const DeepCollectionEquality().equals(other.prev, prev) && - const DeepCollectionEquality().equals(other.next, next)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash( - runtimeType, - first, - last, - const DeepCollectionEquality().hash(prev), - const DeepCollectionEquality().hash(next)); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$LinksImplCopyWith<_$LinksImpl> get copyWith => - __$$LinksImplCopyWithImpl<_$LinksImpl>(this, _$identity); - - @override - Map toJson() { - return _$$LinksImplToJson( - this, - ); - } -} - -abstract class _Links implements Links { - const factory _Links( - {@JsonKey(name: "first") required final String first, - @JsonKey(name: "last") required final String last, - @JsonKey(name: "prev") required final dynamic prev, - @JsonKey(name: "next") required final dynamic next}) = _$LinksImpl; - - factory _Links.fromJson(Map json) = _$LinksImpl.fromJson; - - @override - @JsonKey(name: "first") - String get first; - @override - @JsonKey(name: "last") - String get last; - @override - @JsonKey(name: "prev") - dynamic get prev; - @override - @JsonKey(name: "next") - dynamic get next; - @override - @JsonKey(ignore: true) - _$$LinksImplCopyWith<_$LinksImpl> get copyWith => - throw _privateConstructorUsedError; -} - -Meta _$MetaFromJson(Map json) { - return _Meta.fromJson(json); -} - -/// @nodoc -mixin _$Meta { - @JsonKey(name: "current_page") - int get currentPage => throw _privateConstructorUsedError; - @JsonKey(name: "from") - int get from => throw _privateConstructorUsedError; - @JsonKey(name: "last_page") - int get lastPage => throw _privateConstructorUsedError; - @JsonKey(name: "links") - List get links => throw _privateConstructorUsedError; - @JsonKey(name: "path") - String get path => throw _privateConstructorUsedError; - @JsonKey(name: "per_page") - int get perPage => throw _privateConstructorUsedError; - @JsonKey(name: "to") - int get to => throw _privateConstructorUsedError; - @JsonKey(name: "total") - int get total => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $MetaCopyWith get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $MetaCopyWith<$Res> { - factory $MetaCopyWith(Meta value, $Res Function(Meta) then) = - _$MetaCopyWithImpl<$Res, Meta>; - @useResult - $Res call( - {@JsonKey(name: "current_page") int currentPage, - @JsonKey(name: "from") int from, - @JsonKey(name: "last_page") int lastPage, - @JsonKey(name: "links") List links, - @JsonKey(name: "path") String path, - @JsonKey(name: "per_page") int perPage, - @JsonKey(name: "to") int to, - @JsonKey(name: "total") int total}); -} - -/// @nodoc -class _$MetaCopyWithImpl<$Res, $Val extends Meta> - implements $MetaCopyWith<$Res> { - _$MetaCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? currentPage = null, - Object? from = null, - Object? lastPage = null, - Object? links = null, - Object? path = null, - Object? perPage = null, - Object? to = null, - Object? total = null, - }) { - return _then(_value.copyWith( - currentPage: null == currentPage - ? _value.currentPage - : currentPage // ignore: cast_nullable_to_non_nullable - as int, - from: null == from - ? _value.from - : from // ignore: cast_nullable_to_non_nullable - as int, - lastPage: null == lastPage - ? _value.lastPage - : lastPage // ignore: cast_nullable_to_non_nullable - as int, - links: null == links - ? _value.links - : links // ignore: cast_nullable_to_non_nullable - as List, - path: null == path - ? _value.path - : path // ignore: cast_nullable_to_non_nullable - as String, - perPage: null == perPage - ? _value.perPage - : perPage // ignore: cast_nullable_to_non_nullable - as int, - to: null == to - ? _value.to - : to // ignore: cast_nullable_to_non_nullable - as int, - total: null == total - ? _value.total - : total // ignore: cast_nullable_to_non_nullable - as int, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$MetaImplCopyWith<$Res> implements $MetaCopyWith<$Res> { - factory _$$MetaImplCopyWith( - _$MetaImpl value, $Res Function(_$MetaImpl) then) = - __$$MetaImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {@JsonKey(name: "current_page") int currentPage, - @JsonKey(name: "from") int from, - @JsonKey(name: "last_page") int lastPage, - @JsonKey(name: "links") List links, - @JsonKey(name: "path") String path, - @JsonKey(name: "per_page") int perPage, - @JsonKey(name: "to") int to, - @JsonKey(name: "total") int total}); -} - -/// @nodoc -class __$$MetaImplCopyWithImpl<$Res> - extends _$MetaCopyWithImpl<$Res, _$MetaImpl> - implements _$$MetaImplCopyWith<$Res> { - __$$MetaImplCopyWithImpl(_$MetaImpl _value, $Res Function(_$MetaImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? currentPage = null, - Object? from = null, - Object? lastPage = null, - Object? links = null, - Object? path = null, - Object? perPage = null, - Object? to = null, - Object? total = null, - }) { - return _then(_$MetaImpl( - currentPage: null == currentPage - ? _value.currentPage - : currentPage // ignore: cast_nullable_to_non_nullable - as int, - from: null == from - ? _value.from - : from // ignore: cast_nullable_to_non_nullable - as int, - lastPage: null == lastPage - ? _value.lastPage - : lastPage // ignore: cast_nullable_to_non_nullable - as int, - links: null == links - ? _value._links - : links // ignore: cast_nullable_to_non_nullable - as List, - path: null == path - ? _value.path - : path // ignore: cast_nullable_to_non_nullable - as String, - perPage: null == perPage - ? _value.perPage - : perPage // ignore: cast_nullable_to_non_nullable - as int, - to: null == to - ? _value.to - : to // ignore: cast_nullable_to_non_nullable - as int, - total: null == total - ? _value.total - : total // ignore: cast_nullable_to_non_nullable - as int, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$MetaImpl implements _Meta { - const _$MetaImpl( - {@JsonKey(name: "current_page") required this.currentPage, - @JsonKey(name: "from") required this.from, - @JsonKey(name: "last_page") required this.lastPage, - @JsonKey(name: "links") required final List links, - @JsonKey(name: "path") required this.path, - @JsonKey(name: "per_page") required this.perPage, - @JsonKey(name: "to") required this.to, - @JsonKey(name: "total") required this.total}) - : _links = links; - - factory _$MetaImpl.fromJson(Map json) => - _$$MetaImplFromJson(json); - - @override - @JsonKey(name: "current_page") - final int currentPage; - @override - @JsonKey(name: "from") - final int from; - @override - @JsonKey(name: "last_page") - final int lastPage; - final List _links; - @override - @JsonKey(name: "links") - List get links { - if (_links is EqualUnmodifiableListView) return _links; - // ignore: implicit_dynamic_type - return EqualUnmodifiableListView(_links); - } - - @override - @JsonKey(name: "path") - final String path; - @override - @JsonKey(name: "per_page") - final int perPage; - @override - @JsonKey(name: "to") - final int to; - @override - @JsonKey(name: "total") - final int total; - - @override - String toString() { - return 'Meta(currentPage: $currentPage, from: $from, lastPage: $lastPage, links: $links, path: $path, perPage: $perPage, to: $to, total: $total)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$MetaImpl && - (identical(other.currentPage, currentPage) || - other.currentPage == currentPage) && - (identical(other.from, from) || other.from == from) && - (identical(other.lastPage, lastPage) || - other.lastPage == lastPage) && - const DeepCollectionEquality().equals(other._links, _links) && - (identical(other.path, path) || other.path == path) && - (identical(other.perPage, perPage) || other.perPage == perPage) && - (identical(other.to, to) || other.to == to) && - (identical(other.total, total) || other.total == total)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, currentPage, from, lastPage, - const DeepCollectionEquality().hash(_links), path, perPage, to, total); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$MetaImplCopyWith<_$MetaImpl> get copyWith => - __$$MetaImplCopyWithImpl<_$MetaImpl>(this, _$identity); - - @override - Map toJson() { - return _$$MetaImplToJson( - this, - ); - } -} - -abstract class _Meta implements Meta { - const factory _Meta( - {@JsonKey(name: "current_page") required final int currentPage, - @JsonKey(name: "from") required final int from, - @JsonKey(name: "last_page") required final int lastPage, - @JsonKey(name: "links") required final List links, - @JsonKey(name: "path") required final String path, - @JsonKey(name: "per_page") required final int perPage, - @JsonKey(name: "to") required final int to, - @JsonKey(name: "total") required final int total}) = _$MetaImpl; - - factory _Meta.fromJson(Map json) = _$MetaImpl.fromJson; - - @override - @JsonKey(name: "current_page") - int get currentPage; - @override - @JsonKey(name: "from") - int get from; - @override - @JsonKey(name: "last_page") - int get lastPage; - @override - @JsonKey(name: "links") - List get links; - @override - @JsonKey(name: "path") - String get path; - @override - @JsonKey(name: "per_page") - int get perPage; - @override - @JsonKey(name: "to") - int get to; - @override - @JsonKey(name: "total") - int get total; - @override - @JsonKey(ignore: true) - _$$MetaImplCopyWith<_$MetaImpl> get copyWith => - throw _privateConstructorUsedError; -} - -Link _$LinkFromJson(Map json) { - return _Link.fromJson(json); -} - -/// @nodoc -mixin _$Link { - @JsonKey(name: "url") - String? get url => throw _privateConstructorUsedError; - @JsonKey(name: "label") - String get label => throw _privateConstructorUsedError; - @JsonKey(name: "active") - bool get active => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $LinkCopyWith get copyWith => throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $LinkCopyWith<$Res> { - factory $LinkCopyWith(Link value, $Res Function(Link) then) = - _$LinkCopyWithImpl<$Res, Link>; - @useResult - $Res call( - {@JsonKey(name: "url") String? url, - @JsonKey(name: "label") String label, - @JsonKey(name: "active") bool active}); -} - -/// @nodoc -class _$LinkCopyWithImpl<$Res, $Val extends Link> - implements $LinkCopyWith<$Res> { - _$LinkCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? url = freezed, - Object? label = null, - Object? active = null, - }) { - return _then(_value.copyWith( - url: freezed == url - ? _value.url - : url // ignore: cast_nullable_to_non_nullable - as String?, - label: null == label - ? _value.label - : label // ignore: cast_nullable_to_non_nullable - as String, - active: null == active - ? _value.active - : active // ignore: cast_nullable_to_non_nullable - as bool, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$LinkImplCopyWith<$Res> implements $LinkCopyWith<$Res> { - factory _$$LinkImplCopyWith( - _$LinkImpl value, $Res Function(_$LinkImpl) then) = - __$$LinkImplCopyWithImpl<$Res>; - @override - @useResult - $Res call( - {@JsonKey(name: "url") String? url, - @JsonKey(name: "label") String label, - @JsonKey(name: "active") bool active}); -} - -/// @nodoc -class __$$LinkImplCopyWithImpl<$Res> - extends _$LinkCopyWithImpl<$Res, _$LinkImpl> - implements _$$LinkImplCopyWith<$Res> { - __$$LinkImplCopyWithImpl(_$LinkImpl _value, $Res Function(_$LinkImpl) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? url = freezed, - Object? label = null, - Object? active = null, - }) { - return _then(_$LinkImpl( - url: freezed == url - ? _value.url - : url // ignore: cast_nullable_to_non_nullable - as String?, - label: null == label - ? _value.label - : label // ignore: cast_nullable_to_non_nullable - as String, - active: null == active - ? _value.active - : active // ignore: cast_nullable_to_non_nullable - as bool, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$LinkImpl implements _Link { - const _$LinkImpl( - {@JsonKey(name: "url") required this.url, - @JsonKey(name: "label") required this.label, - @JsonKey(name: "active") required this.active}); - - factory _$LinkImpl.fromJson(Map json) => - _$$LinkImplFromJson(json); - - @override - @JsonKey(name: "url") - final String? url; - @override - @JsonKey(name: "label") - final String label; - @override - @JsonKey(name: "active") - final bool active; - - @override - String toString() { - return 'Link(url: $url, label: $label, active: $active)'; - } - - @override - bool operator ==(Object other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$LinkImpl && - (identical(other.url, url) || other.url == url) && - (identical(other.label, label) || other.label == label) && - (identical(other.active, active) || other.active == active)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, url, label, active); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$LinkImplCopyWith<_$LinkImpl> get copyWith => - __$$LinkImplCopyWithImpl<_$LinkImpl>(this, _$identity); - - @override - Map toJson() { - return _$$LinkImplToJson( - this, - ); - } -} - -abstract class _Link implements Link { - const factory _Link( - {@JsonKey(name: "url") required final String? url, - @JsonKey(name: "label") required final String label, - @JsonKey(name: "active") required final bool active}) = _$LinkImpl; - - factory _Link.fromJson(Map json) = _$LinkImpl.fromJson; - - @override - @JsonKey(name: "url") - String? get url; - @override - @JsonKey(name: "label") - String get label; - @override - @JsonKey(name: "active") - bool get active; - @override - @JsonKey(ignore: true) - _$$LinkImplCopyWith<_$LinkImpl> get copyWith => + _$$DietTypeImplCopyWith<_$DietTypeImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/lib/features/feed/models/diets_pagination_model.g.dart b/lib/features/feed/models/diets_pagination_model.g.dart index 0a745095..7fcab8cd 100644 --- a/lib/features/feed/models/diets_pagination_model.g.dart +++ b/lib/features/feed/models/diets_pagination_model.g.dart @@ -10,7 +10,7 @@ _$DietsPaginationImpl _$$DietsPaginationImplFromJson( Map json) => _$DietsPaginationImpl( data: (json['data'] as List) - .map((e) => Datum.fromJson(e as Map)) + .map((e) => Diet.fromJson(e as Map)) .toList(), links: Links.fromJson(json['links'] as Map), meta: Meta.fromJson(json['meta'] as Map), @@ -24,13 +24,13 @@ Map _$$DietsPaginationImplToJson( 'meta': instance.meta, }; -_$DatumImpl _$$DatumImplFromJson(Map json) => _$DatumImpl( +_$DietImpl _$$DietImplFromJson(Map json) => _$DietImpl( id: (json['id'] as num).toInt(), name: json['name'] as String, image: json['image'] as String, duration: (json['duration'] as num).toInt(), state: json['state'] as String, - type: Type.fromJson(json['type'] as Map), + type: DietType.fromJson(json['type'] as Map), details: json['details'] as String, dailySchedule: (json['daily_schedule'] as List) .map((e) => (e as List) @@ -45,7 +45,7 @@ _$DatumImpl _$$DatumImplFromJson(Map json) => _$DatumImpl( totalComments: (json['total_comments'] as num).toInt(), ); -Map _$$DatumImplToJson(_$DatumImpl instance) => +Map _$$DietImplToJson(_$DietImpl instance) => { 'id': instance.id, 'name': instance.name, @@ -98,70 +98,18 @@ const _$PortionEnumMap = { Portion.PCS: 'pcs', }; -_$TypeImpl _$$TypeImplFromJson(Map json) => _$TypeImpl( +_$DietTypeImpl _$$DietTypeImplFromJson(Map json) => + _$DietTypeImpl( alko: json['alko'] as bool?, veg: json['veg'] as bool?, corb: json['corb'] as bool?, meat: json['meat'] as bool?, ); -Map _$$TypeImplToJson(_$TypeImpl instance) => +Map _$$DietTypeImplToJson(_$DietTypeImpl instance) => { 'alko': instance.alko, 'veg': instance.veg, 'corb': instance.corb, 'meat': instance.meat, }; - -_$LinksImpl _$$LinksImplFromJson(Map json) => _$LinksImpl( - first: json['first'] as String, - last: json['last'] as String, - prev: json['prev'], - next: json['next'], - ); - -Map _$$LinksImplToJson(_$LinksImpl instance) => - { - 'first': instance.first, - 'last': instance.last, - 'prev': instance.prev, - 'next': instance.next, - }; - -_$MetaImpl _$$MetaImplFromJson(Map json) => _$MetaImpl( - currentPage: (json['current_page'] as num).toInt(), - from: (json['from'] as num).toInt(), - lastPage: (json['last_page'] as num).toInt(), - links: (json['links'] as List) - .map((e) => Link.fromJson(e as Map)) - .toList(), - path: json['path'] as String, - perPage: (json['per_page'] as num).toInt(), - to: (json['to'] as num).toInt(), - total: (json['total'] as num).toInt(), - ); - -Map _$$MetaImplToJson(_$MetaImpl instance) => - { - 'current_page': instance.currentPage, - 'from': instance.from, - 'last_page': instance.lastPage, - 'links': instance.links, - 'path': instance.path, - 'per_page': instance.perPage, - 'to': instance.to, - 'total': instance.total, - }; - -_$LinkImpl _$$LinkImplFromJson(Map json) => _$LinkImpl( - url: json['url'] as String?, - label: json['label'] as String, - active: json['active'] as bool, - ); - -Map _$$LinkImplToJson(_$LinkImpl instance) => - { - 'url': instance.url, - 'label': instance.label, - 'active': instance.active, - }; diff --git a/lib/features/feed/models/feed_blog_post_settings_model.dart b/lib/features/feed/models/feed_blog_post_settings_model.dart index 66e0ecf3..2dcd22a1 100644 --- a/lib/features/feed/models/feed_blog_post_settings_model.dart +++ b/lib/features/feed/models/feed_blog_post_settings_model.dart @@ -1,4 +1,4 @@ -import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; +import 'package:eatvio_app/core/models/base_models.dart'; import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; diff --git a/lib/features/feed/presentation/bloc/comments_cubit/comments_state.dart b/lib/features/feed/presentation/bloc/comments_cubit/comments_state.dart index 2f910856..1be83081 100644 --- a/lib/features/feed/presentation/bloc/comments_cubit/comments_state.dart +++ b/lib/features/feed/presentation/bloc/comments_cubit/comments_state.dart @@ -10,7 +10,7 @@ abstract class CommentsState with _$CommentsState { const factory CommentsState.loading() = CommentsStateLoading; const factory CommentsState.loaded({ - required Comment comment, + required CommentModel comment, }) = CommentsStateLoaded; const factory CommentsState.error({ diff --git a/lib/features/feed/presentation/bloc/comments_cubit/comments_state.freezed.dart b/lib/features/feed/presentation/bloc/comments_cubit/comments_state.freezed.dart index da3d0345..d4993b5b 100644 --- a/lib/features/feed/presentation/bloc/comments_cubit/comments_state.freezed.dart +++ b/lib/features/feed/presentation/bloc/comments_cubit/comments_state.freezed.dart @@ -20,7 +20,7 @@ mixin _$CommentsState { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Comment comment) loaded, + required TResult Function(CommentModel comment) loaded, required TResult Function(String errorMessage) error, }) => throw _privateConstructorUsedError; @@ -28,7 +28,7 @@ mixin _$CommentsState { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Comment comment)? loaded, + TResult? Function(CommentModel comment)? loaded, TResult? Function(String errorMessage)? error, }) => throw _privateConstructorUsedError; @@ -36,7 +36,7 @@ mixin _$CommentsState { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Comment comment)? loaded, + TResult Function(CommentModel comment)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) => @@ -126,7 +126,7 @@ class _$CommentsStateImpl implements _CommentsState { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Comment comment) loaded, + required TResult Function(CommentModel comment) loaded, required TResult Function(String errorMessage) error, }) { return $default(); @@ -137,7 +137,7 @@ class _$CommentsStateImpl implements _CommentsState { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Comment comment)? loaded, + TResult? Function(CommentModel comment)? loaded, TResult? Function(String errorMessage)? error, }) { return $default?.call(); @@ -148,7 +148,7 @@ class _$CommentsStateImpl implements _CommentsState { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Comment comment)? loaded, + TResult Function(CommentModel comment)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -241,7 +241,7 @@ class _$CommentsStateLoadingImpl implements CommentsStateLoading { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Comment comment) loaded, + required TResult Function(CommentModel comment) loaded, required TResult Function(String errorMessage) error, }) { return loading(); @@ -252,7 +252,7 @@ class _$CommentsStateLoadingImpl implements CommentsStateLoading { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Comment comment)? loaded, + TResult? Function(CommentModel comment)? loaded, TResult? Function(String errorMessage)? error, }) { return loading?.call(); @@ -263,7 +263,7 @@ class _$CommentsStateLoadingImpl implements CommentsStateLoading { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Comment comment)? loaded, + TResult Function(CommentModel comment)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -321,9 +321,9 @@ abstract class _$$CommentsStateLoadedImplCopyWith<$Res> { $Res Function(_$CommentsStateLoadedImpl) then) = __$$CommentsStateLoadedImplCopyWithImpl<$Res>; @useResult - $Res call({Comment comment}); + $Res call({CommentModel comment}); - $CommentCopyWith<$Res> get comment; + $CommentModelCopyWith<$Res> get comment; } /// @nodoc @@ -343,14 +343,14 @@ class __$$CommentsStateLoadedImplCopyWithImpl<$Res> comment: null == comment ? _value.comment : comment // ignore: cast_nullable_to_non_nullable - as Comment, + as CommentModel, )); } @override @pragma('vm:prefer-inline') - $CommentCopyWith<$Res> get comment { - return $CommentCopyWith<$Res>(_value.comment, (value) { + $CommentModelCopyWith<$Res> get comment { + return $CommentModelCopyWith<$Res>(_value.comment, (value) { return _then(_value.copyWith(comment: value)); }); } @@ -362,7 +362,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded { const _$CommentsStateLoadedImpl({required this.comment}); @override - final Comment comment; + final CommentModel comment; @override String toString() { @@ -392,7 +392,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Comment comment) loaded, + required TResult Function(CommentModel comment) loaded, required TResult Function(String errorMessage) error, }) { return loaded(comment); @@ -403,7 +403,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Comment comment)? loaded, + TResult? Function(CommentModel comment)? loaded, TResult? Function(String errorMessage)? error, }) { return loaded?.call(comment); @@ -414,7 +414,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Comment comment)? loaded, + TResult Function(CommentModel comment)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -463,10 +463,10 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded { } abstract class CommentsStateLoaded implements CommentsState { - const factory CommentsStateLoaded({required final Comment comment}) = + const factory CommentsStateLoaded({required final CommentModel comment}) = _$CommentsStateLoadedImpl; - Comment get comment; + CommentModel get comment; @JsonKey(ignore: true) _$$CommentsStateLoadedImplCopyWith<_$CommentsStateLoadedImpl> get copyWith => throw _privateConstructorUsedError; @@ -540,7 +540,7 @@ class _$CommentsStateErrorImpl implements CommentsStateError { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(Comment comment) loaded, + required TResult Function(CommentModel comment) loaded, required TResult Function(String errorMessage) error, }) { return error(errorMessage); @@ -551,7 +551,7 @@ class _$CommentsStateErrorImpl implements CommentsStateError { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(Comment comment)? loaded, + TResult? Function(CommentModel comment)? loaded, TResult? Function(String errorMessage)? error, }) { return error?.call(errorMessage); @@ -562,7 +562,7 @@ class _$CommentsStateErrorImpl implements CommentsStateError { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(Comment comment)? loaded, + TResult Function(CommentModel comment)? loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { diff --git a/lib/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart b/lib/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart index 8cd8a522..abad1c19 100644 --- a/lib/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart +++ b/lib/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart @@ -1,18 +1,47 @@ import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart'; import 'package:eatvio_app/features/feed/repositories/feed_repository.dart'; +import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart'; +import 'package:eatvio_app/features/recipes/reporitories/recipe_repository.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; class RecipesCubit extends Cubit { final FeedRepository feedRepository; + final RecipeRepository recipeRepository; + Set _selectedTags = {}; - RecipesCubit({required this.feedRepository}) : super(const RecipesState.loading()); + RecipesCubit({ + required this.feedRepository, + required this.recipeRepository, + }) : super(const RecipesState.loading()); - loadRecipesList() async { + loadRecipesList({ + String? query, + }) async { + emit(const RecipesState.loading()); try { - final recipesList = await feedRepository.getRecipes(); - emit(RecipesState.loaded(recipesList: recipesList)); + print('asdasdasdasda'); + print(query); + final recipesList = await feedRepository.getRecipes( + tags: _selectedTags.toList(), + query: query, + ); + final recipesTags = (await recipeRepository.getRecipesTags()); + emit(RecipesState.loaded( + recipesList: recipesList, + recipesTags: recipesTags, + selectedTags: _selectedTags, + selectedTagsCounter: _selectedTags.length, + )); } catch (e) { emit(RecipesState.error(errorMessage: e.toString())); } } + + updateTags(RecipeTag tag) { + _selectedTags.contains(tag.id) ? _selectedTags.remove(tag.id) : _selectedTags.add(tag.id); + emit((state as RecipesStateLoaded).copyWith( + selectedTags: _selectedTags, + selectedTagsCounter: _selectedTags.length, + )); + } } diff --git a/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart b/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart index ecdf17c2..1c2e7f23 100644 --- a/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart +++ b/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart @@ -1,4 +1,5 @@ import 'package:eatvio_app/features/feed/models/recipes_model.dart'; +import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; part 'recipes_state.freezed.dart'; @@ -11,6 +12,9 @@ abstract class RecipesState with _$RecipesState { const factory RecipesState.loaded({ required List recipesList, + required List recipesTags, + required Set selectedTags, + required int selectedTagsCounter, }) = RecipesStateLoaded; const factory RecipesState.error({ diff --git a/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.freezed.dart b/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.freezed.dart index e8aa88e0..fc7fe0c6 100644 --- a/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.freezed.dart +++ b/lib/features/feed/presentation/bloc/recipes_cubit/recipes_state.freezed.dart @@ -20,7 +20,12 @@ mixin _$RecipesState { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(List recipesList) loaded, + required TResult Function( + List recipesList, + List recipesTags, + Set selectedTags, + int selectedTagsCounter) + loaded, required TResult Function(String errorMessage) error, }) => throw _privateConstructorUsedError; @@ -28,7 +33,9 @@ mixin _$RecipesState { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(List recipesList)? loaded, + TResult? Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult? Function(String errorMessage)? error, }) => throw _privateConstructorUsedError; @@ -36,7 +43,9 @@ mixin _$RecipesState { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(List recipesList)? loaded, + TResult Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) => @@ -126,7 +135,12 @@ class _$RecipesStateImpl implements _RecipesState { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(List recipesList) loaded, + required TResult Function( + List recipesList, + List recipesTags, + Set selectedTags, + int selectedTagsCounter) + loaded, required TResult Function(String errorMessage) error, }) { return $default(); @@ -137,7 +151,9 @@ class _$RecipesStateImpl implements _RecipesState { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(List recipesList)? loaded, + TResult? Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult? Function(String errorMessage)? error, }) { return $default?.call(); @@ -148,7 +164,9 @@ class _$RecipesStateImpl implements _RecipesState { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(List recipesList)? loaded, + TResult Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -241,7 +259,12 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(List recipesList) loaded, + required TResult Function( + List recipesList, + List recipesTags, + Set selectedTags, + int selectedTagsCounter) + loaded, required TResult Function(String errorMessage) error, }) { return loading(); @@ -252,7 +275,9 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(List recipesList)? loaded, + TResult? Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult? Function(String errorMessage)? error, }) { return loading?.call(); @@ -263,7 +288,9 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(List recipesList)? loaded, + TResult Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { @@ -321,7 +348,11 @@ abstract class _$$RecipesStateLoadedImplCopyWith<$Res> { $Res Function(_$RecipesStateLoadedImpl) then) = __$$RecipesStateLoadedImplCopyWithImpl<$Res>; @useResult - $Res call({List recipesList}); + $Res call( + {List recipesList, + List recipesTags, + Set selectedTags, + int selectedTagsCounter}); } /// @nodoc @@ -336,12 +367,27 @@ class __$$RecipesStateLoadedImplCopyWithImpl<$Res> @override $Res call({ Object? recipesList = null, + Object? recipesTags = null, + Object? selectedTags = null, + Object? selectedTagsCounter = null, }) { return _then(_$RecipesStateLoadedImpl( recipesList: null == recipesList ? _value._recipesList : recipesList // ignore: cast_nullable_to_non_nullable as List, + recipesTags: null == recipesTags + ? _value._recipesTags + : recipesTags // ignore: cast_nullable_to_non_nullable + as List, + selectedTags: null == selectedTags + ? _value._selectedTags + : selectedTags // ignore: cast_nullable_to_non_nullable + as Set, + selectedTagsCounter: null == selectedTagsCounter + ? _value.selectedTagsCounter + : selectedTagsCounter // ignore: cast_nullable_to_non_nullable + as int, )); } } @@ -349,8 +395,14 @@ class __$$RecipesStateLoadedImplCopyWithImpl<$Res> /// @nodoc class _$RecipesStateLoadedImpl implements RecipesStateLoaded { - const _$RecipesStateLoadedImpl({required final List recipesList}) - : _recipesList = recipesList; + const _$RecipesStateLoadedImpl( + {required final List recipesList, + required final List recipesTags, + required final Set selectedTags, + required this.selectedTagsCounter}) + : _recipesList = recipesList, + _recipesTags = recipesTags, + _selectedTags = selectedTags; final List _recipesList; @override @@ -360,9 +412,28 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded { return EqualUnmodifiableListView(_recipesList); } + final List _recipesTags; + @override + List get recipesTags { + if (_recipesTags is EqualUnmodifiableListView) return _recipesTags; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_recipesTags); + } + + final Set _selectedTags; + @override + Set get selectedTags { + if (_selectedTags is EqualUnmodifiableSetView) return _selectedTags; + // ignore: implicit_dynamic_type + return EqualUnmodifiableSetView(_selectedTags); + } + + @override + final int selectedTagsCounter; + @override String toString() { - return 'RecipesState.loaded(recipesList: $recipesList)'; + return 'RecipesState.loaded(recipesList: $recipesList, recipesTags: $recipesTags, selectedTags: $selectedTags, selectedTagsCounter: $selectedTagsCounter)'; } @override @@ -371,12 +442,22 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded { (other.runtimeType == runtimeType && other is _$RecipesStateLoadedImpl && const DeepCollectionEquality() - .equals(other._recipesList, _recipesList)); + .equals(other._recipesList, _recipesList) && + const DeepCollectionEquality() + .equals(other._recipesTags, _recipesTags) && + const DeepCollectionEquality() + .equals(other._selectedTags, _selectedTags) && + (identical(other.selectedTagsCounter, selectedTagsCounter) || + other.selectedTagsCounter == selectedTagsCounter)); } @override int get hashCode => Object.hash( - runtimeType, const DeepCollectionEquality().hash(_recipesList)); + runtimeType, + const DeepCollectionEquality().hash(_recipesList), + const DeepCollectionEquality().hash(_recipesTags), + const DeepCollectionEquality().hash(_selectedTags), + selectedTagsCounter); @JsonKey(ignore: true) @override @@ -390,10 +471,15 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(List recipesList) loaded, + required TResult Function( + List recipesList, + List recipesTags, + Set selectedTags, + int selectedTagsCounter) + loaded, required TResult Function(String errorMessage) error, }) { - return loaded(recipesList); + return loaded(recipesList, recipesTags, selectedTags, selectedTagsCounter); } @override @@ -401,10 +487,13 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(List recipesList)? loaded, + TResult? Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult? Function(String errorMessage)? error, }) { - return loaded?.call(recipesList); + return loaded?.call( + recipesList, recipesTags, selectedTags, selectedTagsCounter); } @override @@ -412,12 +501,15 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(List recipesList)? loaded, + TResult Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { if (loaded != null) { - return loaded(recipesList); + return loaded( + recipesList, recipesTags, selectedTags, selectedTagsCounter); } return orElse(); } @@ -461,10 +553,16 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded { } abstract class RecipesStateLoaded implements RecipesState { - const factory RecipesStateLoaded({required final List recipesList}) = - _$RecipesStateLoadedImpl; + const factory RecipesStateLoaded( + {required final List recipesList, + required final List recipesTags, + required final Set selectedTags, + required final int selectedTagsCounter}) = _$RecipesStateLoadedImpl; List get recipesList; + List get recipesTags; + Set get selectedTags; + int get selectedTagsCounter; @JsonKey(ignore: true) _$$RecipesStateLoadedImplCopyWith<_$RecipesStateLoadedImpl> get copyWith => throw _privateConstructorUsedError; @@ -538,7 +636,12 @@ class _$RecipesStateErrorImpl implements RecipesStateError { TResult when( TResult Function() $default, { required TResult Function() loading, - required TResult Function(List recipesList) loaded, + required TResult Function( + List recipesList, + List recipesTags, + Set selectedTags, + int selectedTagsCounter) + loaded, required TResult Function(String errorMessage) error, }) { return error(errorMessage); @@ -549,7 +652,9 @@ class _$RecipesStateErrorImpl implements RecipesStateError { TResult? whenOrNull( TResult? Function()? $default, { TResult? Function()? loading, - TResult? Function(List recipesList)? loaded, + TResult? Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult? Function(String errorMessage)? error, }) { return error?.call(errorMessage); @@ -560,7 +665,9 @@ class _$RecipesStateErrorImpl implements RecipesStateError { TResult maybeWhen( TResult Function()? $default, { TResult Function()? loading, - TResult Function(List recipesList)? loaded, + TResult Function(List recipesList, List recipesTags, + Set selectedTags, int selectedTagsCounter)? + loaded, TResult Function(String errorMessage)? error, required TResult orElse(), }) { diff --git a/lib/features/feed/presentation/pages/feed_screen.dart b/lib/features/feed/presentation/pages/feed_screen.dart index 662c06ec..241d454a 100644 --- a/lib/features/feed/presentation/pages/feed_screen.dart +++ b/lib/features/feed/presentation/pages/feed_screen.dart @@ -1,3 +1,4 @@ +import 'package:easy_debounce/easy_debounce.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_state.dart'; import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart'; @@ -7,6 +8,7 @@ import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes import 'package:eatvio_app/features/feed/presentation/widgets/blog_post_widget.dart'; import 'package:eatvio_app/features/feed/presentation/widgets/diets_widget.dart'; import 'package:eatvio_app/features/feed/presentation/widgets/recipes_widget.dart'; +import 'package:eatvio_app/features/feed/presentation/widgets/tags_modal_widget.dart'; import 'package:eatvio_app/theme/theme_helper.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -21,13 +23,44 @@ class FeedScreen extends StatefulWidget { } class _FeedScreenState extends State { + final searchController = TextEditingController(); final List chipsLabelList = ['Все', 'Рецепты', 'Диеты', 'Планы питания', 'Консультанты']; - int _selectedChipIndex = 0; @override Widget build(BuildContext context) { return Scaffold( + floatingActionButton: _selectedChipIndex == 1 + ? FloatingActionButton.small( + backgroundColor: appTheme.blueA400, + shape: CircleBorder(), + child: Icon( + Icons.filter_list_rounded, + color: Colors.white, + ), + onPressed: () async { + await showModalBottomSheet( + useRootNavigator: true, + context: context, + builder: (context) { + return BlocBuilder( + builder: (BuildContext context, RecipesState state) { + if (state is RecipesStateLoaded) { + return TagsModalWidget( + tagsList: state.recipesTags, + selectedTags: state.selectedTags, + ); + } else { + return Container(); + } + }, + ); + }, + ); + context.read().loadRecipesList(); + }, + ) + : null, appBar: AppBar( backgroundColor: Colors.white, toolbarHeight: 0, @@ -85,7 +118,7 @@ class _FeedScreenState extends State { shrinkWrap: true, physics: BouncingScrollPhysics(), itemBuilder: (context, index) { - return DietsWidget(datum: state.diets.data[index]); + return DietsWidget(diet: state.diets.data[index]); }, separatorBuilder: (context, index) { return SizedBox(height: 8); @@ -247,9 +280,35 @@ class _FeedScreenState extends State { height: 40, width: MediaQuery.of(context).size.width - 84, child: TextFormField( + controller: searchController, style: TextStyle( fontSize: 12, ), + onChanged: (query) { + if (query.length > 2) { + EasyDebounce.debounce( + 'searchFeed', + Duration(milliseconds: 500), + () { + switch (_selectedChipIndex) { + case 1: + context.read().loadRecipesList(query: query); + } + }, + ); + } else { + EasyDebounce.debounce( + 'searchFeed', + Duration(milliseconds: 500), + () { + switch (_selectedChipIndex) { + case 1: + context.read().loadRecipesList(query: query); + } + }, + ); + } + }, decoration: InputDecoration( hintText: 'Поиск', hintStyle: TextStyle( @@ -304,6 +363,8 @@ class _FeedScreenState extends State { onSelected: (bool selected) { setState(() { _selectedChipIndex = index; + searchController.clear(); + FocusScope.of(context).requestFocus(new FocusNode()); }); }, ); diff --git a/lib/features/feed/presentation/widgets/diets_widget.dart b/lib/features/feed/presentation/widgets/diets_widget.dart index 38f589cf..bf94f9aa 100644 --- a/lib/features/feed/presentation/widgets/diets_widget.dart +++ b/lib/features/feed/presentation/widgets/diets_widget.dart @@ -5,9 +5,9 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; class DietsWidget extends StatefulWidget { - final Datum datum; + final Diet diet; - const DietsWidget({super.key, required this.datum}); + const DietsWidget({super.key, required this.diet}); @override State createState() => _DietsWidgetState(); @@ -18,7 +18,7 @@ class _DietsWidgetState extends State { Widget build(BuildContext context) { return InkWell( borderRadius: BorderRadius.circular(12), - onTap: () => GoRouter.of(context).pushNamed('aboutDietScreen', extra: widget.datum), + onTap: () => GoRouter.of(context).pushNamed('aboutDietScreen', extra: widget.diet), child: Ink( decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), @@ -33,7 +33,7 @@ class _DietsWidgetState extends State { ClipRRect( borderRadius: BorderRadius.vertical(top: Radius.circular(12)), child: CachedNetworkImage( - imageUrl: baseUrl + '/storage/' + widget.datum.image, + imageUrl: baseUrl + '/storage/' + widget.diet.image, ), ), Positioned( @@ -44,9 +44,9 @@ class _DietsWidgetState extends State { children: [ _iconButton(Icons.fastfood, '139.9 ккал'), SizedBox(width: 8), - _iconButton(Icons.timer_rounded, widget.datum.state), + _iconButton(Icons.timer_rounded, widget.diet.state), SizedBox(width: 8), - _iconButton(Icons.fast_forward_rounded, widget.datum.duration.toString()), + _iconButton(Icons.fast_forward_rounded, widget.diet.duration.toString()), ], ), ), @@ -68,7 +68,7 @@ class _DietsWidgetState extends State { ), SizedBox(width: 4), Text( - widget.datum.totalLikes.toString(), + widget.diet.totalLikes.toString(), style: TextStyle( fontSize: 12, color: Colors.black, @@ -97,7 +97,7 @@ class _DietsWidgetState extends State { ), SizedBox(width: 4), Text( - widget.datum.totalViews.toString(), + widget.diet.totalViews.toString(), style: TextStyle( fontSize: 12, color: Colors.black, @@ -114,7 +114,7 @@ class _DietsWidgetState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 12), child: Text( - widget.datum.name, + widget.diet.name, style: TextStyle( fontWeight: FontWeight.w600, color: Colors.black87, @@ -125,7 +125,7 @@ class _DietsWidgetState extends State { Padding( padding: const EdgeInsets.symmetric(horizontal: 12), child: Text( - widget.datum.details, + widget.diet.details, style: TextStyle( color: Colors.black87, ), diff --git a/lib/features/feed/presentation/widgets/tags_modal_widget.dart b/lib/features/feed/presentation/widgets/tags_modal_widget.dart new file mode 100644 index 00000000..724f91a8 --- /dev/null +++ b/lib/features/feed/presentation/widgets/tags_modal_widget.dart @@ -0,0 +1,65 @@ +import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart'; +import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart'; +import 'package:eatvio_app/theme/theme_helper.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class TagsModalWidget extends StatefulWidget { + final List tagsList; + final Set selectedTags; + + const TagsModalWidget({ + super.key, + required this.tagsList, + required this.selectedTags, + }); + + @override + State createState() => _TagsModalWidgetState(); +} + +class _TagsModalWidgetState extends State { + @override + Widget build(BuildContext context) { + return Container( + padding: EdgeInsets.all(16), + width: MediaQuery.of(context).size.width, + child: Wrap( + spacing: 8, + runSpacing: -8, + children: [ + for (int i = 0; i < widget.tagsList.length; i++) + _tagChip( + tag: widget.tagsList[i], + isSelected: widget.selectedTags.contains(widget.tagsList[i].id), + ), + ], + ), + ); + } + + _tagChip({ + required RecipeTag tag, + required bool isSelected, + }) { + return ChoiceChip( + selectedColor: appTheme.blueA400, + pressElevation: 0, + showCheckmark: false, + side: BorderSide.none, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + ), + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + label: Text(tag.name), + labelStyle: TextStyle( + color: isSelected ? Colors.white : appTheme.gray600, + fontWeight: FontWeight.w500, + fontSize: 12, + ), + selected: isSelected, + backgroundColor: appTheme.gray100, + onSelected: (bool selected) => context.read().updateTags(tag), + ); + } +} diff --git a/lib/features/feed/repositories/feed_repository.dart b/lib/features/feed/repositories/feed_repository.dart index 78cc2106..23089824 100644 --- a/lib/features/feed/repositories/feed_repository.dart +++ b/lib/features/feed/repositories/feed_repository.dart @@ -17,9 +17,16 @@ class FeedRepository { } } - Future> getRecipes() async { + Future> getRecipes({ + String? query, + List? tags, + }) async { try { - return (await feedService.getRecipes()).recipesList; + return (await feedService.getRecipes( + query: query, + tags: tags, + )) + .recipesList; } catch (e) { rethrow; } @@ -33,7 +40,7 @@ class FeedRepository { } } - Future getBlogPostComments(int id) async { + Future getBlogPostComments(int id) async { try { return (await feedService.getBlogPostComments(id: id)); } catch (e) { @@ -57,7 +64,7 @@ class FeedRepository { } } - Future getDietsComments(int id) async { + Future getDietsComments(int id) async { try { return (await feedService.getDietsComments(id: id)); } catch (e) { @@ -81,7 +88,7 @@ class FeedRepository { } } - Future getRecipesComments(String id) async { + Future getRecipesComments(String id) async { try { return (await feedService.getRecipesComments(id: id)); } catch (e) { diff --git a/lib/features/feed/services/feed_service.dart b/lib/features/feed/services/feed_service.dart index 44f5e33f..f282547e 100644 --- a/lib/features/feed/services/feed_service.dart +++ b/lib/features/feed/services/feed_service.dart @@ -17,13 +17,16 @@ abstract class FeedService { }); @GET('/api/recipes/index') - Future getRecipes(); + Future getRecipes({ + @Query('filters[tags][tags.id][\$in][]') required List? tags, + @Query('filters[title][\$contains]') required String? query, + }); @GET('/api/diets/index') Future getDiets(); @GET('/api/blogPosts/{id}/comments/show') - Future getBlogPostComments({ + Future getBlogPostComments({ @Path() required int id, }); @@ -35,7 +38,7 @@ abstract class FeedService { }); @GET('/api/diets/{id}/comments/show') - Future getDietsComments({ + Future getDietsComments({ @Path() required int id, }); @@ -47,7 +50,7 @@ abstract class FeedService { }); @GET('/api/recipes/{id}/comments/show') - Future getRecipesComments({ + Future getRecipesComments({ @Path() required String id, }); diff --git a/lib/features/feed/services/feed_service.g.dart b/lib/features/feed/services/feed_service.g.dart index 6ae8ffef..84016757 100644 --- a/lib/features/feed/services/feed_service.g.dart +++ b/lib/features/feed/services/feed_service.g.dart @@ -55,9 +55,16 @@ class _FeedService implements FeedService { } @override - Future getRecipes() async { + Future getRecipes({ + List? tags, + String? query, + }) async { final _extra = {}; - final queryParameters = {}; + final queryParameters = { + r'filters[tags][tags.id][$in][]': tags, + r'filters[title][$contains]': query, + }; + queryParameters.removeWhere((k, v) => v == null); final _headers = {}; const Map? _data = null; final _options = _setStreamType(Options( @@ -121,12 +128,12 @@ class _FeedService implements FeedService { } @override - Future getBlogPostComments({required int id}) async { + Future getBlogPostComments({required int id}) async { final _extra = {}; final queryParameters = {}; final _headers = {}; const Map? _data = null; - final _options = _setStreamType(Options( + final _options = _setStreamType(Options( method: 'GET', headers: _headers, extra: _extra, @@ -143,9 +150,9 @@ class _FeedService implements FeedService { baseUrl, ))); final _result = await _dio.fetch>(_options); - late Comment _value; + late CommentModel _value; try { - _value = Comment.fromJson(_result.data!); + _value = CommentModel.fromJson(_result.data!); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; @@ -194,12 +201,12 @@ class _FeedService implements FeedService { } @override - Future getDietsComments({required int id}) async { + Future getDietsComments({required int id}) async { final _extra = {}; final queryParameters = {}; final _headers = {}; const Map? _data = null; - final _options = _setStreamType(Options( + final _options = _setStreamType(Options( method: 'GET', headers: _headers, extra: _extra, @@ -216,9 +223,9 @@ class _FeedService implements FeedService { baseUrl, ))); final _result = await _dio.fetch>(_options); - late Comment _value; + late CommentModel _value; try { - _value = Comment.fromJson(_result.data!); + _value = CommentModel.fromJson(_result.data!); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; @@ -267,12 +274,12 @@ class _FeedService implements FeedService { } @override - Future getRecipesComments({required String id}) async { + Future getRecipesComments({required String id}) async { final _extra = {}; final queryParameters = {}; final _headers = {}; const Map? _data = null; - final _options = _setStreamType(Options( + final _options = _setStreamType(Options( method: 'GET', headers: _headers, extra: _extra, @@ -289,9 +296,9 @@ class _FeedService implements FeedService { baseUrl, ))); final _result = await _dio.fetch>(_options); - late Comment _value; + late CommentModel _value; try { - _value = Comment.fromJson(_result.data!); + _value = CommentModel.fromJson(_result.data!); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; diff --git a/lib/features/profile/models/profile_model.dart b/lib/features/profile/models/profile_model.dart index 62dfc065..6aa5fc1a 100644 --- a/lib/features/profile/models/profile_model.dart +++ b/lib/features/profile/models/profile_model.dart @@ -6,7 +6,7 @@ part 'profile_model.g.dart'; class ProfileModel with _$ProfileModel { const factory ProfileModel({ @JsonKey(name: "user") required User user, - @JsonKey(name: "chartPoints") required List chartPoints, + @JsonKey(name: "chartPoints") required List chartPoints, @JsonKey(name: "userDetails") required UserDetails userDetails, @JsonKey(name: "circumferences") required List circumferences, @JsonKey(name: "finishedPlans") required List finishedPlans, @@ -96,15 +96,15 @@ class UserDetails with _$UserDetails { } @freezed -class ChartPoint with _$ChartPoint { - const factory ChartPoint({ +class ChartPointModel with _$ChartPointModel { + const factory ChartPointModel({ @JsonKey(name: "id") required int id, @JsonKey(name: "user_id") required int userId, @JsonKey(name: "weight") required double weight, @JsonKey(name: "bmi") required double bmi, @JsonKey(name: "created_at") required DateTime createdAt, @JsonKey(name: "updated_at") required DateTime updatedAt, - }) = _ChartPoint; + }) = _ChartPointModel; - factory ChartPoint.fromJson(Map json) => _$ChartPointFromJson(json); + factory ChartPointModel.fromJson(Map json) => _$ChartPointModelFromJson(json); } diff --git a/lib/features/profile/models/profile_model.freezed.dart b/lib/features/profile/models/profile_model.freezed.dart index 21954c15..ed199108 100644 --- a/lib/features/profile/models/profile_model.freezed.dart +++ b/lib/features/profile/models/profile_model.freezed.dart @@ -23,7 +23,7 @@ mixin _$ProfileModel { @JsonKey(name: "user") User get user => throw _privateConstructorUsedError; @JsonKey(name: "chartPoints") - List get chartPoints => throw _privateConstructorUsedError; + List get chartPoints => throw _privateConstructorUsedError; @JsonKey(name: "userDetails") UserDetails get userDetails => throw _privateConstructorUsedError; @JsonKey(name: "circumferences") @@ -55,7 +55,7 @@ abstract class $ProfileModelCopyWith<$Res> { @useResult $Res call( {@JsonKey(name: "user") User user, - @JsonKey(name: "chartPoints") List chartPoints, + @JsonKey(name: "chartPoints") List chartPoints, @JsonKey(name: "userDetails") UserDetails userDetails, @JsonKey(name: "circumferences") List circumferences, @JsonKey(name: "finishedPlans") List finishedPlans, @@ -101,7 +101,7 @@ class _$ProfileModelCopyWithImpl<$Res, $Val extends ProfileModel> chartPoints: null == chartPoints ? _value.chartPoints : chartPoints // ignore: cast_nullable_to_non_nullable - as List, + as List, userDetails: null == userDetails ? _value.userDetails : userDetails // ignore: cast_nullable_to_non_nullable @@ -164,7 +164,7 @@ abstract class _$$ProfileModelImplCopyWith<$Res> @useResult $Res call( {@JsonKey(name: "user") User user, - @JsonKey(name: "chartPoints") List chartPoints, + @JsonKey(name: "chartPoints") List chartPoints, @JsonKey(name: "userDetails") UserDetails userDetails, @JsonKey(name: "circumferences") List circumferences, @JsonKey(name: "finishedPlans") List finishedPlans, @@ -210,7 +210,7 @@ class __$$ProfileModelImplCopyWithImpl<$Res> chartPoints: null == chartPoints ? _value._chartPoints : chartPoints // ignore: cast_nullable_to_non_nullable - as List, + as List, userDetails: null == userDetails ? _value.userDetails : userDetails // ignore: cast_nullable_to_non_nullable @@ -252,7 +252,8 @@ class __$$ProfileModelImplCopyWithImpl<$Res> class _$ProfileModelImpl implements _ProfileModel { const _$ProfileModelImpl( {@JsonKey(name: "user") required this.user, - @JsonKey(name: "chartPoints") required final List chartPoints, + @JsonKey(name: "chartPoints") + required final List chartPoints, @JsonKey(name: "userDetails") required this.userDetails, @JsonKey(name: "circumferences") required final List circumferences, @@ -280,10 +281,10 @@ class _$ProfileModelImpl implements _ProfileModel { @override @JsonKey(name: "user") final User user; - final List _chartPoints; + final List _chartPoints; @override @JsonKey(name: "chartPoints") - List get chartPoints { + List get chartPoints { if (_chartPoints is EqualUnmodifiableListView) return _chartPoints; // ignore: implicit_dynamic_type return EqualUnmodifiableListView(_chartPoints); @@ -417,7 +418,8 @@ class _$ProfileModelImpl implements _ProfileModel { abstract class _ProfileModel implements ProfileModel { const factory _ProfileModel( {@JsonKey(name: "user") required final User user, - @JsonKey(name: "chartPoints") required final List chartPoints, + @JsonKey(name: "chartPoints") + required final List chartPoints, @JsonKey(name: "userDetails") required final UserDetails userDetails, @JsonKey(name: "circumferences") required final List circumferences, @@ -440,7 +442,7 @@ abstract class _ProfileModel implements ProfileModel { User get user; @override @JsonKey(name: "chartPoints") - List get chartPoints; + List get chartPoints; @override @JsonKey(name: "userDetails") UserDetails get userDetails; @@ -2110,12 +2112,12 @@ abstract class _UserDetails implements UserDetails { throw _privateConstructorUsedError; } -ChartPoint _$ChartPointFromJson(Map json) { - return _ChartPoint.fromJson(json); +ChartPointModel _$ChartPointModelFromJson(Map json) { + return _ChartPointModel.fromJson(json); } /// @nodoc -mixin _$ChartPoint { +mixin _$ChartPointModel { @JsonKey(name: "id") int get id => throw _privateConstructorUsedError; @JsonKey(name: "user_id") @@ -2131,15 +2133,15 @@ mixin _$ChartPoint { Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) - $ChartPointCopyWith get copyWith => + $ChartPointModelCopyWith get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class $ChartPointCopyWith<$Res> { - factory $ChartPointCopyWith( - ChartPoint value, $Res Function(ChartPoint) then) = - _$ChartPointCopyWithImpl<$Res, ChartPoint>; +abstract class $ChartPointModelCopyWith<$Res> { + factory $ChartPointModelCopyWith( + ChartPointModel value, $Res Function(ChartPointModel) then) = + _$ChartPointModelCopyWithImpl<$Res, ChartPointModel>; @useResult $Res call( {@JsonKey(name: "id") int id, @@ -2151,9 +2153,9 @@ abstract class $ChartPointCopyWith<$Res> { } /// @nodoc -class _$ChartPointCopyWithImpl<$Res, $Val extends ChartPoint> - implements $ChartPointCopyWith<$Res> { - _$ChartPointCopyWithImpl(this._value, this._then); +class _$ChartPointModelCopyWithImpl<$Res, $Val extends ChartPointModel> + implements $ChartPointModelCopyWith<$Res> { + _$ChartPointModelCopyWithImpl(this._value, this._then); // ignore: unused_field final $Val _value; @@ -2200,11 +2202,11 @@ class _$ChartPointCopyWithImpl<$Res, $Val extends ChartPoint> } /// @nodoc -abstract class _$$ChartPointImplCopyWith<$Res> - implements $ChartPointCopyWith<$Res> { - factory _$$ChartPointImplCopyWith( - _$ChartPointImpl value, $Res Function(_$ChartPointImpl) then) = - __$$ChartPointImplCopyWithImpl<$Res>; +abstract class _$$ChartPointModelImplCopyWith<$Res> + implements $ChartPointModelCopyWith<$Res> { + factory _$$ChartPointModelImplCopyWith(_$ChartPointModelImpl value, + $Res Function(_$ChartPointModelImpl) then) = + __$$ChartPointModelImplCopyWithImpl<$Res>; @override @useResult $Res call( @@ -2217,11 +2219,11 @@ abstract class _$$ChartPointImplCopyWith<$Res> } /// @nodoc -class __$$ChartPointImplCopyWithImpl<$Res> - extends _$ChartPointCopyWithImpl<$Res, _$ChartPointImpl> - implements _$$ChartPointImplCopyWith<$Res> { - __$$ChartPointImplCopyWithImpl( - _$ChartPointImpl _value, $Res Function(_$ChartPointImpl) _then) +class __$$ChartPointModelImplCopyWithImpl<$Res> + extends _$ChartPointModelCopyWithImpl<$Res, _$ChartPointModelImpl> + implements _$$ChartPointModelImplCopyWith<$Res> { + __$$ChartPointModelImplCopyWithImpl( + _$ChartPointModelImpl _value, $Res Function(_$ChartPointModelImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -2234,7 +2236,7 @@ class __$$ChartPointImplCopyWithImpl<$Res> Object? createdAt = null, Object? updatedAt = null, }) { - return _then(_$ChartPointImpl( + return _then(_$ChartPointModelImpl( id: null == id ? _value.id : id // ignore: cast_nullable_to_non_nullable @@ -2265,8 +2267,8 @@ class __$$ChartPointImplCopyWithImpl<$Res> /// @nodoc @JsonSerializable() -class _$ChartPointImpl implements _ChartPoint { - const _$ChartPointImpl( +class _$ChartPointModelImpl implements _ChartPointModel { + const _$ChartPointModelImpl( {@JsonKey(name: "id") required this.id, @JsonKey(name: "user_id") required this.userId, @JsonKey(name: "weight") required this.weight, @@ -2274,8 +2276,8 @@ class _$ChartPointImpl implements _ChartPoint { @JsonKey(name: "created_at") required this.createdAt, @JsonKey(name: "updated_at") required this.updatedAt}); - factory _$ChartPointImpl.fromJson(Map json) => - _$$ChartPointImplFromJson(json); + factory _$ChartPointModelImpl.fromJson(Map json) => + _$$ChartPointModelImplFromJson(json); @override @JsonKey(name: "id") @@ -2298,14 +2300,14 @@ class _$ChartPointImpl implements _ChartPoint { @override String toString() { - return 'ChartPoint(id: $id, userId: $userId, weight: $weight, bmi: $bmi, createdAt: $createdAt, updatedAt: $updatedAt)'; + return 'ChartPointModel(id: $id, userId: $userId, weight: $weight, bmi: $bmi, createdAt: $createdAt, updatedAt: $updatedAt)'; } @override bool operator ==(Object other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ChartPointImpl && + other is _$ChartPointModelImpl && (identical(other.id, id) || other.id == id) && (identical(other.userId, userId) || other.userId == userId) && (identical(other.weight, weight) || other.weight == weight) && @@ -2324,29 +2326,30 @@ class _$ChartPointImpl implements _ChartPoint { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$ChartPointImplCopyWith<_$ChartPointImpl> get copyWith => - __$$ChartPointImplCopyWithImpl<_$ChartPointImpl>(this, _$identity); + _$$ChartPointModelImplCopyWith<_$ChartPointModelImpl> get copyWith => + __$$ChartPointModelImplCopyWithImpl<_$ChartPointModelImpl>( + this, _$identity); @override Map toJson() { - return _$$ChartPointImplToJson( + return _$$ChartPointModelImplToJson( this, ); } } -abstract class _ChartPoint implements ChartPoint { - const factory _ChartPoint( +abstract class _ChartPointModel implements ChartPointModel { + const factory _ChartPointModel( {@JsonKey(name: "id") required final int id, @JsonKey(name: "user_id") required final int userId, @JsonKey(name: "weight") required final double weight, @JsonKey(name: "bmi") required final double bmi, @JsonKey(name: "created_at") required final DateTime createdAt, @JsonKey(name: "updated_at") required final DateTime updatedAt}) = - _$ChartPointImpl; + _$ChartPointModelImpl; - factory _ChartPoint.fromJson(Map json) = - _$ChartPointImpl.fromJson; + factory _ChartPointModel.fromJson(Map json) = + _$ChartPointModelImpl.fromJson; @override @JsonKey(name: "id") @@ -2368,6 +2371,6 @@ abstract class _ChartPoint implements ChartPoint { DateTime get updatedAt; @override @JsonKey(ignore: true) - _$$ChartPointImplCopyWith<_$ChartPointImpl> get copyWith => + _$$ChartPointModelImplCopyWith<_$ChartPointModelImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/lib/features/profile/models/profile_model.g.dart b/lib/features/profile/models/profile_model.g.dart index 020ffca1..42ee3d8c 100644 --- a/lib/features/profile/models/profile_model.g.dart +++ b/lib/features/profile/models/profile_model.g.dart @@ -10,7 +10,7 @@ _$ProfileModelImpl _$$ProfileModelImplFromJson(Map json) => _$ProfileModelImpl( user: User.fromJson(json['user'] as Map), chartPoints: (json['chartPoints'] as List) - .map((e) => ChartPoint.fromJson(e as Map)) + .map((e) => ChartPointModel.fromJson(e as Map)) .toList(), userDetails: UserDetails.fromJson(json['userDetails'] as Map), @@ -164,8 +164,9 @@ Map _$$UserDetailsImplToJson(_$UserDetailsImpl instance) => 'activity_coefficient': instance.activityCoefficient, }; -_$ChartPointImpl _$$ChartPointImplFromJson(Map json) => - _$ChartPointImpl( +_$ChartPointModelImpl _$$ChartPointModelImplFromJson( + Map json) => + _$ChartPointModelImpl( id: (json['id'] as num).toInt(), userId: (json['user_id'] as num).toInt(), weight: (json['weight'] as num).toDouble(), @@ -174,7 +175,8 @@ _$ChartPointImpl _$$ChartPointImplFromJson(Map json) => updatedAt: DateTime.parse(json['updated_at'] as String), ); -Map _$$ChartPointImplToJson(_$ChartPointImpl instance) => +Map _$$ChartPointModelImplToJson( + _$ChartPointModelImpl instance) => { 'id': instance.id, 'user_id': instance.userId, diff --git a/lib/features/profile/presentation/pages/profile_screen.dart b/lib/features/profile/presentation/pages/profile_screen.dart index f85417fa..b0aeb788 100644 --- a/lib/features/profile/presentation/pages/profile_screen.dart +++ b/lib/features/profile/presentation/pages/profile_screen.dart @@ -21,7 +21,7 @@ class ProfileScreen extends StatefulWidget { class _ProfileScreenState extends State { List chartData = []; - List chartPoints = []; + List chartPoints = []; final List chipsLabelList = ['Вес', 'Замеры', 'ИМТ']; final List chipsIntervalLabelList = ['1М', '3М', '6М', '1Г', 'ВСЁ ВРЕМЯ']; int _selectedChipIndex = 0; @@ -49,95 +49,98 @@ class _ProfileScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - padding: const EdgeInsets.all(16), decoration: BoxDecoration( - borderRadius: BorderRadius.vertical(bottom: Radius.circular(16)), color: Colors.white, + borderRadius: BorderRadius.vertical( + bottom: Radius.circular(16), + ), ), - child: Row( + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, children: [ - CircleAvatar( - radius: 32, - backgroundImage: NetworkImage(state.profile.user.profilePhotoUrl), - ), - const SizedBox(width: 12), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - state.profile.user.name, - style: TextStyle( - color: Colors.black, - fontWeight: FontWeight.w500, - height: 1, + Padding( + padding: const EdgeInsets.only(left: 16, right: 16, bottom: 16), + child: Row( + children: [ + CircleAvatar( + radius: 32, + backgroundImage: NetworkImage(state.profile.user.profilePhotoUrl), ), - ), - if (state.profile.userDetails.additionalInfo.isNotEmpty) - Text( - state.profile.userDetails.additionalInfo, - style: TextStyle( - color: Colors.black.withOpacity(0.4), - height: 1, + const SizedBox(width: 12), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + state.profile.user.name, + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w500, + height: 1, + ), + ), + if (state.profile.userDetails.additionalInfo.isNotEmpty) + Text( + state.profile.userDetails.additionalInfo, + style: TextStyle( + color: Colors.black.withOpacity(0.4), + height: 1, + ), + ), + ], + ), + ], + ), + ), + if (widget.author == null) _divider(context), + if (widget.author == null) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 8), + SingleChildScrollView( + padding: EdgeInsets.symmetric(horizontal: 16), + scrollDirection: Axis.horizontal, + child: Row( + children: [ + _choiceChipWidget(0), + SizedBox(width: 8), + _choiceChipWidget(1), + SizedBox(width: 8), + _choiceChipWidget(2), + ], ), ), - ], - ), + Builder( + builder: (context) { + if (_selectedChipIndex == 0) return WeightChartWidget(chartPoints: chartPoints); + if (_selectedChipIndex == 1) return CircumferenceChartWidget(chartData: chartData); + if (_selectedChipIndex == 2) + return ImtChartWidget(chartPoints: chartPoints); + else + return Container(); + }, + ), + SizedBox(height: 8), + Row( + children: [ + SizedBox(width: 16), + _choiceIntervalChipWidget(0), + SizedBox(width: 8), + _choiceIntervalChipWidget(1), + SizedBox(width: 8), + _choiceIntervalChipWidget(2), + SizedBox(width: 8), + _choiceIntervalChipWidget(3), + SizedBox(width: 8), + _choiceIntervalChipWidget(4), + ], + ), + SizedBox(height: 8), + ], + ), ], ), ), - if (widget.author == null) SizedBox(height: 8), - if (widget.author == null) - Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(16), - color: Colors.white, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox(height: 8), - SingleChildScrollView( - padding: EdgeInsets.symmetric(horizontal: 16), - scrollDirection: Axis.horizontal, - child: Row( - children: [ - _choiceChipWidget(0), - SizedBox(width: 8), - _choiceChipWidget(1), - SizedBox(width: 8), - _choiceChipWidget(2), - ], - ), - ), - Builder( - builder: (context) { - if (_selectedChipIndex == 0) return WeightChartWidget(chartPoints: chartPoints); - if (_selectedChipIndex == 1) return CircumferenceChartWidget(chartData: chartData); - if (_selectedChipIndex == 2) - return ImtChartWidget(chartPoints: chartPoints); - else - return Container(); - }, - ), - SizedBox(height: 8), - Row( - children: [ - SizedBox(width: 16), - _choiceIntervalChipWidget(0), - SizedBox(width: 8), - _choiceIntervalChipWidget(1), - SizedBox(width: 8), - _choiceIntervalChipWidget(2), - SizedBox(width: 8), - _choiceIntervalChipWidget(3), - SizedBox(width: 8), - _choiceIntervalChipWidget(4), - ], - ), - SizedBox(height: 8), - ], - ), - ), SizedBox(height: 16), ListView.separated( shrinkWrap: true, @@ -174,6 +177,17 @@ class _ProfileScreenState extends State { ); } + _divider(BuildContext context) { + return Container( + height: 0.4, + width: MediaQuery.of(context).size.width - 32, + decoration: BoxDecoration( + color: Colors.black26, + borderRadius: BorderRadius.circular(16), + ), + ); + } + _choiceIntervalChipWidget(int index) { return ChoiceChip( selectedColor: Colors.grey.withOpacity(0.1), diff --git a/lib/features/profile/presentation/widgets/circumference_chart_widget.dart b/lib/features/profile/presentation/widgets/circumference_chart_widget.dart index f4849df1..9294a361 100644 --- a/lib/features/profile/presentation/widgets/circumference_chart_widget.dart +++ b/lib/features/profile/presentation/widgets/circumference_chart_widget.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/features/profile/models/profile_model.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; @@ -15,91 +16,101 @@ class CircumferenceChartWidget extends StatelessWidget { Widget build(BuildContext context) { return Column( children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + SingleChildScrollView( + padding: EdgeInsets.symmetric(horizontal: 16), + scrollDirection: Axis.horizontal, + physics: const BouncingScrollPhysics(), child: Row( children: [ Text( - 'Грудь ${chartData.last.chestCircumference} см', + '${chartData.last.chestCircumference} см', style: TextStyle( color: Colors.black, - fontSize: 18, + fontSize: 48, fontWeight: FontWeight.w500, ), ), chartData.last.chestCircumference > chartData[chartData.length - 2].chestCircumference ? Icon( Icons.arrow_drop_up, - size: 18, + size: 48, color: Colors.grey, ) : Icon( Icons.arrow_drop_down, - size: 18, + size: 48, color: Colors.grey, ), Text( - 'Талия ${chartData.last.waistCircumference} см', + '${chartData.last.waistCircumference} см', style: TextStyle( color: Colors.black, - fontSize: 18, + fontSize: 48, fontWeight: FontWeight.w500, ), ), chartData.last.waistCircumference > chartData[chartData.length - 2].waistCircumference ? Icon( Icons.arrow_drop_up, - size: 18, + size: 48, color: Colors.grey, ) : Icon( Icons.arrow_drop_down, - size: 18, + size: 48, color: Colors.grey, ), Text( - 'Бёдра ${chartData.last.hipCircumference} см', + '${chartData.last.hipCircumference} см', style: TextStyle( color: Colors.black, - fontSize: 18, + fontSize: 48, fontWeight: FontWeight.w500, ), ), chartData.last.hipCircumference > chartData[chartData.length - 2].hipCircumference ? Icon( Icons.arrow_drop_up, - size: 18, + size: 48, color: Colors.grey, ) : Icon( Icons.arrow_drop_down, - size: 18, + size: 48, color: Colors.grey, ), ], ), ), SfCartesianChart( - margin: EdgeInsets.zero, + margin: EdgeInsets.symmetric(horizontal: 8), enableAxisAnimation: true, - enableSideBySideSeriesPlacement: true, - legend: const Legend( - isVisible: true, - opacity: 0.7, - position: LegendPosition.bottom, - ), plotAreaBorderWidth: 0, trackballBehavior: TrackballBehavior( enable: true, activationMode: ActivationMode.singleTap, + tooltipDisplayMode: TrackballDisplayMode.groupAllPoints, + tooltipSettings: InteractiveTooltip(), + lineType: TrackballLineType.vertical, ), primaryXAxis: DateTimeCategoryAxis( + tickPosition: TickPosition.inside, + majorTickLines: MajorTickLines( + size: 0, + ), + edgeLabelPlacement: EdgeLabelPlacement.shift, dateFormat: DateFormat.MMMd('ru'), + labelStyle: TextStyle( + color: Colors.grey, + ), + majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)), axisLine: AxisLine( - width: 1, + color: Colors.grey.withOpacity(0.3), + width: 0.4, ), ), primaryYAxis: NumericAxis( + isVisible: false, labelFormat: '{value} см', axisLine: AxisLine( width: 1, @@ -115,57 +126,81 @@ class CircumferenceChartWidget extends StatelessWidget { List> _getSplineSeries() { final Color seriesColor1 = Colors.red; - final Color seriesColor2 = Colors.blue; + final Color seriesColor2 = appTheme.blueA400; final Color seriesColor3 = Colors.green; return >[ - SplineSeries( + SplineAreaSeries( markerSettings: MarkerSettings( isVisible: true, color: seriesColor1, - height: 12, - width: 12, + height: 8, + width: 8, ), dataLabelSettings: DataLabelSettings( labelAlignment: ChartDataLabelAlignment.top, isVisible: true, ), dataSource: chartData, - color: seriesColor1, + borderColor: seriesColor1, + gradient: LinearGradient( + colors: [ + seriesColor1.withOpacity(0.14), + Colors.transparent, + ], + begin: Alignment.topCenter, + end: Alignment(0, 0.6), + ), name: 'Грудь', xValueMapper: (Circumference value, int index) => value.createdAt, yValueMapper: (Circumference value, int index) => value.chestCircumference, ), - SplineSeries( + SplineAreaSeries( markerSettings: MarkerSettings( isVisible: true, color: seriesColor2, - height: 12, - width: 12, + height: 8, + width: 8, ), dataLabelSettings: DataLabelSettings( labelAlignment: ChartDataLabelAlignment.top, isVisible: true, ), dataSource: chartData, - color: seriesColor2, + borderColor: seriesColor2, + gradient: LinearGradient( + colors: [ + seriesColor2.withOpacity(0.14), + Colors.transparent, + ], + begin: Alignment.topCenter, + end: Alignment(0, 0.6), + ), name: 'Талия', xValueMapper: (Circumference value, int index) => value.createdAt, yValueMapper: (Circumference value, int index) => value.waistCircumference, ), - SplineSeries( + SplineAreaSeries( markerSettings: MarkerSettings( isVisible: true, color: seriesColor3, - height: 12, - width: 12, + height: 8, + width: 8, ), dataLabelSettings: DataLabelSettings( labelAlignment: ChartDataLabelAlignment.top, isVisible: true, ), dataSource: chartData, - color: seriesColor3, + borderColor: seriesColor3, + gradient: LinearGradient( + colors: [ + seriesColor3.withOpacity(0.14), + Colors.transparent, + ], + begin: Alignment.topCenter, + end: Alignment(0, 0.6), + ), name: 'Бёдра', xValueMapper: (Circumference value, int index) => value.createdAt, yValueMapper: (Circumference value, int index) => value.hipCircumference, diff --git a/lib/features/profile/presentation/widgets/imt_chart_widget.dart b/lib/features/profile/presentation/widgets/imt_chart_widget.dart index 0dc06899..eaf5808a 100644 --- a/lib/features/profile/presentation/widgets/imt_chart_widget.dart +++ b/lib/features/profile/presentation/widgets/imt_chart_widget.dart @@ -1,10 +1,11 @@ -import 'package:eatvio_app/features/profile/models/profile_model.dart' as ProfileModel; +import 'package:eatvio_app/features/profile/models/profile_model.dart'; +import 'package:eatvio_app/theme/theme_helper.dart'; import 'package:flutter/material.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; import 'package:intl/intl.dart'; class ImtChartWidget extends StatelessWidget { - final List chartPoints; + final List chartPoints; const ImtChartWidget({ super.key, @@ -30,39 +31,49 @@ class ImtChartWidget extends StatelessWidget { ), chartPoints.last.bmi > chartPoints[chartPoints.length - 2].bmi ? Icon( - Icons.arrow_drop_up, - size: 48, - color: Colors.grey, - ) + Icons.arrow_drop_up, + size: 48, + color: Colors.grey, + ) : Icon( - Icons.arrow_drop_down, - size: 48, - color: Colors.grey, - ), + Icons.arrow_drop_down, + size: 48, + color: Colors.grey, + ), ], ), ), SfCartesianChart( - margin: EdgeInsets.zero, + margin: EdgeInsets.symmetric(horizontal: 8), enableAxisAnimation: true, - enableSideBySideSeriesPlacement: true, plotAreaBorderWidth: 0, trackballBehavior: TrackballBehavior( enable: true, activationMode: ActivationMode.singleTap, + tooltipDisplayMode: TrackballDisplayMode.groupAllPoints, + tooltipSettings: InteractiveTooltip(), + lineType: TrackballLineType.vertical, ), primaryXAxis: DateTimeCategoryAxis( + initialVisibleMinimum: chartPoints.first.createdAt, + initialVisibleMaximum: chartPoints.last.createdAt, + tickPosition: TickPosition.inside, + majorTickLines: MajorTickLines( + size: 0, + ), + edgeLabelPlacement: EdgeLabelPlacement.shift, dateFormat: DateFormat.MMMd('ru'), + labelStyle: TextStyle( + color: Colors.grey, + ), + majorGridLines: MajorGridLines(dashArray: [1], color: Colors.grey.withOpacity(0.3)), axisLine: AxisLine( - width: 1, + color: Colors.grey.withOpacity(0.3), + width: 0.4, ), ), primaryYAxis: NumericAxis( - labelFormat: '{value} кг/м²', - axisLine: AxisLine( - width: 1, - ), - majorTickLines: MajorTickLines(size: 0), + isVisible: false, ), series: _getSplineSeries(), tooltipBehavior: TooltipBehavior(enable: true), @@ -71,24 +82,32 @@ class ImtChartWidget extends StatelessWidget { ); } - List> _getSplineSeries() { - return >[ - SplineSeries( + List> _getSplineSeries() { + return >[ + SplineAreaSeries( markerSettings: MarkerSettings( isVisible: true, - color: Colors.blue, - height: 12, - width: 12, + color: appTheme.blueA400, + height: 8, + width: 8, ), dataLabelSettings: DataLabelSettings( labelAlignment: ChartDataLabelAlignment.top, isVisible: true, ), dataSource: chartPoints, - color: Colors.blue, + borderColor: appTheme.blueA400, + gradient: LinearGradient( + colors: [ + appTheme.blueA400.withOpacity(0.14), + Colors.transparent, + ], + begin: Alignment.topCenter, + end: Alignment(0, 0.6), + ), name: 'ИМТ', - xValueMapper: (ProfileModel.ChartPoint value, int index) => value.createdAt, - yValueMapper: (ProfileModel.ChartPoint value, int index) => value.bmi, + xValueMapper: (ChartPointModel value, int index) => value.createdAt, + yValueMapper: (ChartPointModel value, int index) => double.parse(value.bmi.toStringAsFixed(2)), ), ]; } diff --git a/lib/features/profile/presentation/widgets/weight_chart_widget.dart b/lib/features/profile/presentation/widgets/weight_chart_widget.dart index f799cc0d..7c75ad61 100644 --- a/lib/features/profile/presentation/widgets/weight_chart_widget.dart +++ b/lib/features/profile/presentation/widgets/weight_chart_widget.dart @@ -1,11 +1,11 @@ import 'package:eatvio_app/core/app_export.dart'; -import 'package:eatvio_app/features/profile/models/profile_model.dart' as ProfileModel; +import 'package:eatvio_app/features/profile/models/profile_model.dart'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; class WeightChartWidget extends StatelessWidget { - final List chartPoints; + final List chartPoints; const WeightChartWidget({ super.key, @@ -22,7 +22,7 @@ class WeightChartWidget extends StatelessWidget { child: Row( children: [ Text( - '${chartPoints.last.weight} кг', + '${chartPoints.last.weight.toStringAsFixed(2)} кг', style: TextStyle( color: Colors.black, fontSize: 48, @@ -88,9 +88,9 @@ class WeightChartWidget extends StatelessWidget { ); } - List> _getSplineSeries() { - return >[ - SplineAreaSeries( + List> _getSplineSeries() { + return >[ + SplineAreaSeries( markerSettings: MarkerSettings( isVisible: true, color: appTheme.blueA400, @@ -112,8 +112,8 @@ class WeightChartWidget extends StatelessWidget { end: Alignment(0, 0.6), ), name: 'Вес', - xValueMapper: (ProfileModel.ChartPoint value, int index) => value.createdAt, - yValueMapper: (ProfileModel.ChartPoint value, int index) => value.weight, + xValueMapper: (ChartPointModel value, int index) => value.createdAt, + yValueMapper: (ChartPointModel value, int index) => value.weight, ), ]; } diff --git a/lib/features/profile/repositories/profile_repository.dart b/lib/features/profile/repositories/profile_repository.dart index d03e39d8..2261f74b 100644 --- a/lib/features/profile/repositories/profile_repository.dart +++ b/lib/features/profile/repositories/profile_repository.dart @@ -41,7 +41,7 @@ class ProfileRepository { } } - Future addWeight({ + Future addWeight({ required int weight, }) async { try { diff --git a/lib/features/profile/services/profile_service.dart b/lib/features/profile/services/profile_service.dart index 2ec6cee0..94a4bdc9 100644 --- a/lib/features/profile/services/profile_service.dart +++ b/lib/features/profile/services/profile_service.dart @@ -25,7 +25,7 @@ abstract class ProfileService { }); @POST('/api/profile/addWeight') - Future> addWeight({ + Future> addWeight({ @Part() required int weight, }); diff --git a/lib/features/profile/services/profile_service.g.dart b/lib/features/profile/services/profile_service.g.dart index ab9461bf..366a5226 100644 --- a/lib/features/profile/services/profile_service.g.dart +++ b/lib/features/profile/services/profile_service.g.dart @@ -138,7 +138,7 @@ class _ProfileService implements ProfileService { } @override - Future> addWeight({required int weight}) async { + Future> addWeight({required int weight}) async { final _extra = {}; final queryParameters = {}; final _headers = {}; @@ -147,7 +147,7 @@ class _ProfileService implements ProfileService { 'weight', weight.toString(), )); - final _options = _setStreamType>(Options( + final _options = _setStreamType>(Options( method: 'POST', headers: _headers, extra: _extra, @@ -164,10 +164,10 @@ class _ProfileService implements ProfileService { baseUrl, ))); final _result = await _dio.fetch>(_options); - late Map _value; + late Map _value; try { _value = _result.data!.map((k, dynamic v) => - MapEntry(k, ChartPoint.fromJson(v as Map))); + MapEntry(k, ChartPointModel.fromJson(v as Map))); } on Object catch (e, s) { errorLogger?.logError(e, s, _options); rethrow; diff --git a/lib/features/recipes/models/recipe_tag.dart b/lib/features/recipes/models/recipe_tag.dart deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/features/recipes/models/recipe_tag_model.dart b/lib/features/recipes/models/recipe_tag_model.dart new file mode 100644 index 00000000..8cd13054 --- /dev/null +++ b/lib/features/recipes/models/recipe_tag_model.dart @@ -0,0 +1,28 @@ +import 'package:eatvio_app/core/models/base_models.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'recipe_tag_model.freezed.dart'; +part 'recipe_tag_model.g.dart'; + +@freezed +class RecipeTagModel with _$RecipeTagModel { + const factory RecipeTagModel({ + @JsonKey(name: "data") required List data, + @JsonKey(name: "links") required Links links, + @JsonKey(name: "meta") required Meta meta, + }) = _RecipeTagModel; + + factory RecipeTagModel.fromJson(Map json) => _$RecipeTagModelFromJson(json); +} + +@freezed +class RecipeTag with _$RecipeTag { + const factory RecipeTag({ + @JsonKey(name: "id") required int id, + @JsonKey(name: "name") required String name, + @JsonKey(name: "created_at") required DateTime createdAt, + @JsonKey(name: "updated_at") required DateTime updatedAt, + }) = _RecipeTag; + + factory RecipeTag.fromJson(Map json) => _$RecipeTagFromJson(json); +} diff --git a/lib/features/recipes/models/recipe_tag_model.freezed.dart b/lib/features/recipes/models/recipe_tag_model.freezed.dart new file mode 100644 index 00000000..db917d4a --- /dev/null +++ b/lib/features/recipes/models/recipe_tag_model.freezed.dart @@ -0,0 +1,451 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'recipe_tag_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +RecipeTagModel _$RecipeTagModelFromJson(Map json) { + return _RecipeTagModel.fromJson(json); +} + +/// @nodoc +mixin _$RecipeTagModel { + @JsonKey(name: "data") + List get data => throw _privateConstructorUsedError; + @JsonKey(name: "links") + Links get links => throw _privateConstructorUsedError; + @JsonKey(name: "meta") + Meta get meta => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $RecipeTagModelCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RecipeTagModelCopyWith<$Res> { + factory $RecipeTagModelCopyWith( + RecipeTagModel value, $Res Function(RecipeTagModel) then) = + _$RecipeTagModelCopyWithImpl<$Res, RecipeTagModel>; + @useResult + $Res call( + {@JsonKey(name: "data") List data, + @JsonKey(name: "links") Links links, + @JsonKey(name: "meta") Meta meta}); + + $LinksCopyWith<$Res> get links; + $MetaCopyWith<$Res> get meta; +} + +/// @nodoc +class _$RecipeTagModelCopyWithImpl<$Res, $Val extends RecipeTagModel> + implements $RecipeTagModelCopyWith<$Res> { + _$RecipeTagModelCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? data = null, + Object? links = null, + Object? meta = null, + }) { + return _then(_value.copyWith( + data: null == data + ? _value.data + : data // ignore: cast_nullable_to_non_nullable + as List, + links: null == links + ? _value.links + : links // ignore: cast_nullable_to_non_nullable + as Links, + meta: null == meta + ? _value.meta + : meta // ignore: cast_nullable_to_non_nullable + as Meta, + ) as $Val); + } + + @override + @pragma('vm:prefer-inline') + $LinksCopyWith<$Res> get links { + return $LinksCopyWith<$Res>(_value.links, (value) { + return _then(_value.copyWith(links: value) as $Val); + }); + } + + @override + @pragma('vm:prefer-inline') + $MetaCopyWith<$Res> get meta { + return $MetaCopyWith<$Res>(_value.meta, (value) { + return _then(_value.copyWith(meta: value) as $Val); + }); + } +} + +/// @nodoc +abstract class _$$RecipeTagModelImplCopyWith<$Res> + implements $RecipeTagModelCopyWith<$Res> { + factory _$$RecipeTagModelImplCopyWith(_$RecipeTagModelImpl value, + $Res Function(_$RecipeTagModelImpl) then) = + __$$RecipeTagModelImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: "data") List data, + @JsonKey(name: "links") Links links, + @JsonKey(name: "meta") Meta meta}); + + @override + $LinksCopyWith<$Res> get links; + @override + $MetaCopyWith<$Res> get meta; +} + +/// @nodoc +class __$$RecipeTagModelImplCopyWithImpl<$Res> + extends _$RecipeTagModelCopyWithImpl<$Res, _$RecipeTagModelImpl> + implements _$$RecipeTagModelImplCopyWith<$Res> { + __$$RecipeTagModelImplCopyWithImpl( + _$RecipeTagModelImpl _value, $Res Function(_$RecipeTagModelImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? data = null, + Object? links = null, + Object? meta = null, + }) { + return _then(_$RecipeTagModelImpl( + data: null == data + ? _value._data + : data // ignore: cast_nullable_to_non_nullable + as List, + links: null == links + ? _value.links + : links // ignore: cast_nullable_to_non_nullable + as Links, + meta: null == meta + ? _value.meta + : meta // ignore: cast_nullable_to_non_nullable + as Meta, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$RecipeTagModelImpl implements _RecipeTagModel { + const _$RecipeTagModelImpl( + {@JsonKey(name: "data") required final List data, + @JsonKey(name: "links") required this.links, + @JsonKey(name: "meta") required this.meta}) + : _data = data; + + factory _$RecipeTagModelImpl.fromJson(Map json) => + _$$RecipeTagModelImplFromJson(json); + + final List _data; + @override + @JsonKey(name: "data") + List get data { + if (_data is EqualUnmodifiableListView) return _data; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_data); + } + + @override + @JsonKey(name: "links") + final Links links; + @override + @JsonKey(name: "meta") + final Meta meta; + + @override + String toString() { + return 'RecipeTagModel(data: $data, links: $links, meta: $meta)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$RecipeTagModelImpl && + const DeepCollectionEquality().equals(other._data, _data) && + (identical(other.links, links) || other.links == links) && + (identical(other.meta, meta) || other.meta == meta)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, const DeepCollectionEquality().hash(_data), links, meta); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$RecipeTagModelImplCopyWith<_$RecipeTagModelImpl> get copyWith => + __$$RecipeTagModelImplCopyWithImpl<_$RecipeTagModelImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$RecipeTagModelImplToJson( + this, + ); + } +} + +abstract class _RecipeTagModel implements RecipeTagModel { + const factory _RecipeTagModel( + {@JsonKey(name: "data") required final List data, + @JsonKey(name: "links") required final Links links, + @JsonKey(name: "meta") required final Meta meta}) = _$RecipeTagModelImpl; + + factory _RecipeTagModel.fromJson(Map json) = + _$RecipeTagModelImpl.fromJson; + + @override + @JsonKey(name: "data") + List get data; + @override + @JsonKey(name: "links") + Links get links; + @override + @JsonKey(name: "meta") + Meta get meta; + @override + @JsonKey(ignore: true) + _$$RecipeTagModelImplCopyWith<_$RecipeTagModelImpl> get copyWith => + throw _privateConstructorUsedError; +} + +RecipeTag _$RecipeTagFromJson(Map json) { + return _RecipeTag.fromJson(json); +} + +/// @nodoc +mixin _$RecipeTag { + @JsonKey(name: "id") + int get id => throw _privateConstructorUsedError; + @JsonKey(name: "name") + String get name => throw _privateConstructorUsedError; + @JsonKey(name: "created_at") + DateTime get createdAt => throw _privateConstructorUsedError; + @JsonKey(name: "updated_at") + DateTime get updatedAt => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $RecipeTagCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RecipeTagCopyWith<$Res> { + factory $RecipeTagCopyWith(RecipeTag value, $Res Function(RecipeTag) then) = + _$RecipeTagCopyWithImpl<$Res, RecipeTag>; + @useResult + $Res call( + {@JsonKey(name: "id") int id, + @JsonKey(name: "name") String name, + @JsonKey(name: "created_at") DateTime createdAt, + @JsonKey(name: "updated_at") DateTime updatedAt}); +} + +/// @nodoc +class _$RecipeTagCopyWithImpl<$Res, $Val extends RecipeTag> + implements $RecipeTagCopyWith<$Res> { + _$RecipeTagCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? name = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$RecipeTagImplCopyWith<$Res> + implements $RecipeTagCopyWith<$Res> { + factory _$$RecipeTagImplCopyWith( + _$RecipeTagImpl value, $Res Function(_$RecipeTagImpl) then) = + __$$RecipeTagImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@JsonKey(name: "id") int id, + @JsonKey(name: "name") String name, + @JsonKey(name: "created_at") DateTime createdAt, + @JsonKey(name: "updated_at") DateTime updatedAt}); +} + +/// @nodoc +class __$$RecipeTagImplCopyWithImpl<$Res> + extends _$RecipeTagCopyWithImpl<$Res, _$RecipeTagImpl> + implements _$$RecipeTagImplCopyWith<$Res> { + __$$RecipeTagImplCopyWithImpl( + _$RecipeTagImpl _value, $Res Function(_$RecipeTagImpl) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? name = null, + Object? createdAt = null, + Object? updatedAt = null, + }) { + return _then(_$RecipeTagImpl( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as int, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + createdAt: null == createdAt + ? _value.createdAt + : createdAt // ignore: cast_nullable_to_non_nullable + as DateTime, + updatedAt: null == updatedAt + ? _value.updatedAt + : updatedAt // ignore: cast_nullable_to_non_nullable + as DateTime, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$RecipeTagImpl implements _RecipeTag { + const _$RecipeTagImpl( + {@JsonKey(name: "id") required this.id, + @JsonKey(name: "name") required this.name, + @JsonKey(name: "created_at") required this.createdAt, + @JsonKey(name: "updated_at") required this.updatedAt}); + + factory _$RecipeTagImpl.fromJson(Map json) => + _$$RecipeTagImplFromJson(json); + + @override + @JsonKey(name: "id") + final int id; + @override + @JsonKey(name: "name") + final String name; + @override + @JsonKey(name: "created_at") + final DateTime createdAt; + @override + @JsonKey(name: "updated_at") + final DateTime updatedAt; + + @override + String toString() { + return 'RecipeTag(id: $id, name: $name, createdAt: $createdAt, updatedAt: $updatedAt)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$RecipeTagImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.name, name) || other.name == name) && + (identical(other.createdAt, createdAt) || + other.createdAt == createdAt) && + (identical(other.updatedAt, updatedAt) || + other.updatedAt == updatedAt)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, name, createdAt, updatedAt); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$RecipeTagImplCopyWith<_$RecipeTagImpl> get copyWith => + __$$RecipeTagImplCopyWithImpl<_$RecipeTagImpl>(this, _$identity); + + @override + Map toJson() { + return _$$RecipeTagImplToJson( + this, + ); + } +} + +abstract class _RecipeTag implements RecipeTag { + const factory _RecipeTag( + {@JsonKey(name: "id") required final int id, + @JsonKey(name: "name") required final String name, + @JsonKey(name: "created_at") required final DateTime createdAt, + @JsonKey(name: "updated_at") required final DateTime updatedAt}) = + _$RecipeTagImpl; + + factory _RecipeTag.fromJson(Map json) = + _$RecipeTagImpl.fromJson; + + @override + @JsonKey(name: "id") + int get id; + @override + @JsonKey(name: "name") + String get name; + @override + @JsonKey(name: "created_at") + DateTime get createdAt; + @override + @JsonKey(name: "updated_at") + DateTime get updatedAt; + @override + @JsonKey(ignore: true) + _$$RecipeTagImplCopyWith<_$RecipeTagImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/features/recipes/models/recipe_tag_model.g.dart b/lib/features/recipes/models/recipe_tag_model.g.dart new file mode 100644 index 00000000..6ab2a853 --- /dev/null +++ b/lib/features/recipes/models/recipe_tag_model.g.dart @@ -0,0 +1,40 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'recipe_tag_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$RecipeTagModelImpl _$$RecipeTagModelImplFromJson(Map json) => + _$RecipeTagModelImpl( + data: (json['data'] as List) + .map((e) => RecipeTag.fromJson(e as Map)) + .toList(), + links: Links.fromJson(json['links'] as Map), + meta: Meta.fromJson(json['meta'] as Map), + ); + +Map _$$RecipeTagModelImplToJson( + _$RecipeTagModelImpl instance) => + { + 'data': instance.data, + 'links': instance.links, + 'meta': instance.meta, + }; + +_$RecipeTagImpl _$$RecipeTagImplFromJson(Map json) => + _$RecipeTagImpl( + id: (json['id'] as num).toInt(), + name: json['name'] as String, + createdAt: DateTime.parse(json['created_at'] as String), + updatedAt: DateTime.parse(json['updated_at'] as String), + ); + +Map _$$RecipeTagImplToJson(_$RecipeTagImpl instance) => + { + 'id': instance.id, + 'name': instance.name, + 'created_at': instance.createdAt.toIso8601String(), + 'updated_at': instance.updatedAt.toIso8601String(), + }; diff --git a/lib/features/recipes/presentation/pages/about_recipes_screen.dart b/lib/features/recipes/presentation/pages/about_recipes_screen.dart index fdb23673..645af00b 100644 --- a/lib/features/recipes/presentation/pages/about_recipes_screen.dart +++ b/lib/features/recipes/presentation/pages/about_recipes_screen.dart @@ -394,7 +394,7 @@ class _AboutRecipesScreenState extends State { ); } - _buildComments(Comment comment) { + _buildComments(CommentModel comment) { return Column( children: [ for (int i = 0; i < comment.data.length; i++) ...[ @@ -414,11 +414,11 @@ class _AboutRecipesScreenState extends State { ); } - _comment(Datum datum, [double radius = 16]) { + _comment(Comment comment, [double radius = 16]) { return Container( width: MediaQuery.of(context).size.width, decoration: BoxDecoration( - color: replyId == datum.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white, + color: replyId == comment.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white, borderRadius: BorderRadius.circular(16), ), child: Padding( @@ -427,7 +427,7 @@ class _AboutRecipesScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ CircleAvatar( - foregroundImage: NetworkImage(datum.authorProfileIcon), + foregroundImage: NetworkImage(comment.authorProfileIcon), radius: radius, ), SizedBox(width: 8), @@ -436,7 +436,7 @@ class _AboutRecipesScreenState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Text( - datum.authorName, + comment.authorName, style: TextStyle( height: 1, color: Colors.grey.shade600, @@ -445,7 +445,7 @@ class _AboutRecipesScreenState extends State { ), SizedBox(width: 4), Text( - datum.body, + comment.body, style: TextStyle( height: 1, color: Colors.black, @@ -455,7 +455,7 @@ class _AboutRecipesScreenState extends State { Row( children: [ Text( - datum.createdAt.format('dd MMMM', 'ru'), + comment.createdAt.format('dd MMMM', 'ru'), style: TextStyle( color: Colors.grey.shade600, fontSize: 12, @@ -467,7 +467,7 @@ class _AboutRecipesScreenState extends State { GestureDetector( onTap: () { setState(() { - replyId = datum.id; + replyId = comment.id; }); }, child: Text( diff --git a/lib/features/recipes/reporitories/recipe_repository.dart b/lib/features/recipes/reporitories/recipe_repository.dart index e27013c7..cf9a355e 100644 --- a/lib/features/recipes/reporitories/recipe_repository.dart +++ b/lib/features/recipes/reporitories/recipe_repository.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:eatvio_app/features/recipes/models/recipe_model.dart'; +import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart'; import 'package:eatvio_app/features/recipes/services/recipe_service.dart'; import 'package:eatvio_app/features/diary/models/product.dart'; @@ -71,4 +72,12 @@ class RecipeRepository { rethrow; } } + + Future> getRecipesTags() async { + try { + return (await recipeService.getTags()).data; + } catch (e) { + rethrow; + } + } } diff --git a/lib/features/recipes/services/recipe_service.dart b/lib/features/recipes/services/recipe_service.dart index d92e6b9c..f0a5e200 100644 --- a/lib/features/recipes/services/recipe_service.dart +++ b/lib/features/recipes/services/recipe_service.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:dio/dio.dart'; import 'package:eatvio_app/features/recipes/models/recipe_model.dart'; +import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart'; import 'package:retrofit/retrofit.dart'; import 'package:eatvio_app/features/diary/models/product.dart'; @@ -33,4 +34,7 @@ abstract class RecipeService { @POST('/api/recipes/update/{id}') Future editRecipe(@Part() Map recipe, String id); + + @GET('/api/recipes/tags') + Future getTags(); } diff --git a/lib/features/recipes/services/recipe_service.g.dart b/lib/features/recipes/services/recipe_service.g.dart index 43cb10a8..c32c9e8a 100644 --- a/lib/features/recipes/services/recipe_service.g.dart +++ b/lib/features/recipes/services/recipe_service.g.dart @@ -220,6 +220,39 @@ class _RecipeService implements RecipeService { return _value; } + @override + Future getTags() async { + final _extra = {}; + final queryParameters = {}; + final _headers = {}; + const Map? _data = null; + final _options = _setStreamType(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/api/recipes/tags', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); + final _result = await _dio.fetch>(_options); + late RecipeTagModel _value; + try { + _value = RecipeTagModel.fromJson(_result.data!); + } on Object catch (e, s) { + errorLogger?.logError(e, s, _options); + rethrow; + } + return _value; + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes || diff --git a/lib/locator_service.dart b/lib/locator_service.dart index a73d21f1..30e45db8 100644 --- a/lib/locator_service.dart +++ b/lib/locator_service.dart @@ -42,7 +42,7 @@ Future init() async { sl.registerFactory(() => RegistrationCubit(registrationRepository: sl())); sl.registerFactory(() => ChatRoomCubit(chatRepository: sl(), initializationCubit: sl())); sl.registerFactory(() => FeedCubit(feedRepository: sl())); - sl.registerFactory(() => RecipesCubit(feedRepository: sl())); + sl.registerFactory(() => RecipesCubit(feedRepository: sl(), recipeRepository: sl())); sl.registerFactory(() => DiaryBloc(diaryRepository: sl())); sl.registerFactory(() => CalendarCubit(calendarRepository: sl())); sl.registerFactory(() => ProfileCubit(profileRepository: sl()));