feat(Лента): фильтрация рецептов по тегам, поиск по строке

This commit is contained in:
mso7nueh
2024-09-02 16:12:54 +03:00
parent 5a651cad9e
commit 334a6b0970
43 changed files with 2320 additions and 2160 deletions

View File

@@ -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(

View File

@@ -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<String, Object?> 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<Link> 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<String, Object?> 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<String, Object?> json) => _$LinkFromJson(json);
}

View File

@@ -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>(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<String, dynamic> 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<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$LinksCopyWith<Links> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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<Link> 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<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$MetaCopyWith<Meta> 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<Link> 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<Link>,
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<Link> 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<Link>,
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<Link> 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<String, dynamic> 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<Link> _links;
@override
@JsonKey(name: "links")
List<Link> 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<String, dynamic> 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<Link> 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<String, dynamic> 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<Link> 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<String, dynamic> 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<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$LinkCopyWith<Link> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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;
}

View File

@@ -0,0 +1,60 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'base_models.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$LinksImpl _$$LinksImplFromJson(Map<String, dynamic> json) => _$LinksImpl(
first: json['first'] as String,
last: json['last'] as String,
prev: json['prev'],
next: json['next'],
);
Map<String, dynamic> _$$LinksImplToJson(_$LinksImpl instance) =>
<String, dynamic>{
'first': instance.first,
'last': instance.last,
'prev': instance.prev,
'next': instance.next,
};
_$MetaImpl _$$MetaImplFromJson(Map<String, dynamic> 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<dynamic>)
.map((e) => Link.fromJson(e as Map<String, dynamic>))
.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<String, dynamic> _$$MetaImplToJson(_$MetaImpl instance) =>
<String, dynamic>{
'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<String, dynamic> json) => _$LinkImpl(
url: json['url'] as String?,
label: json['label'] as String,
active: json['active'] as bool,
);
Map<String, dynamic> _$$LinkImplToJson(_$LinkImpl instance) =>
<String, dynamic>{
'url': instance.url,
'label': instance.label,
'active': instance.active,
};

View File

@@ -320,31 +320,31 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
);
}
_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<BlogPostScreen> {
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<BlogPostScreen> {
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<BlogPostScreen> {
),
SizedBox(width: 4),
Text(
datum.body,
comment.body,
style: TextStyle(
height: 1,
color: Colors.black,
@@ -381,7 +381,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
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<BlogPostScreen> {
GestureDetector(
onTap: () {
setState(() {
replyId = datum.id;
replyId = comment.id;
});
},
child: Text(

View File

@@ -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<int> 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<AboutDietScreen> {
@override
void initState() {
super.initState();
commentsCubit.getDietsComments(widget.datum.id);
commentsCubit.getDietsComments(widget.diet.id);
}
@override
@@ -157,7 +157,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
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<AboutDietScreen> {
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<AboutDietScreen> {
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<AboutDietScreen> {
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<AboutDietScreen> {
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<AboutDietScreen> {
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<AboutDietScreen> {
),
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<AboutDietScreen> {
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<AboutDietScreen> {
),
),
),
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<AboutDietScreen> {
);
}
_dayOfPlan(List<List<Diets.DailySchedule>> day, int dayNumber) {
_dayOfPlan(List<List<DailySchedule>> day, int dayNumber) {
_choiceChipWidget(int index) {
return ChoiceChip(
selectedColor: appTheme.blueA400,
@@ -410,7 +410,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
);
}
_daily(Diets.DailySchedule daily) {
_daily(DailySchedule daily) {
return Row(
children: [
Text(
@@ -436,7 +436,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
);
}
_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<AboutDietScreen> {
);
}
_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<AboutDietScreen> {
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<AboutDietScreen> {
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<AboutDietScreen> {
),
SizedBox(width: 4),
Text(
datum.body,
diet.body,
style: TextStyle(
height: 1,
color: Colors.black,
@@ -497,7 +497,7 @@ class _AboutDietScreenState extends State<AboutDietScreen> {
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<AboutDietScreen> {
GestureDetector(
onTap: () {
setState(() {
replyId = datum.id;
replyId = diet.id;
});
},
child: Text(

View File

@@ -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<Datum> data,
class CommentModel with _$CommentModel {
const factory CommentModel({
@JsonKey(name: "data") required List<Comment> data,
@JsonKey(name: "links") required Links links,
@JsonKey(name: "meta") required Meta meta,
}) = _Comment;
}) = _CommentModel;
factory Comment.fromJson(Map<String, Object?> json) => _$CommentFromJson(json);
factory CommentModel.fromJson(Map<String, Object?> 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<Datum> childrenComments,
@JsonKey(name: "children_comments") required List<Comment> childrenComments,
@JsonKey(name: "created_at") required DateTime createdAt,
}) = _Datum;
}) = _Comment;
factory Datum.fromJson(Map<String, Object?> 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<String, Object?> 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<Link> 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<String, Object?> 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<String, Object?> json) => _$LinkFromJson(json);
factory Comment.fromJson(Map<String, Object?> json) => _$CommentFromJson(json);
}

File diff suppressed because it is too large Load Diff

View File

@@ -6,34 +6,35 @@ part of 'comment_model.dart';
// JsonSerializableGenerator
// **************************************************************************
_$CommentImpl _$$CommentImplFromJson(Map<String, dynamic> json) =>
_$CommentImpl(
_$CommentModelImpl _$$CommentModelImplFromJson(Map<String, dynamic> json) =>
_$CommentModelImpl(
data: (json['data'] as List<dynamic>)
.map((e) => Datum.fromJson(e as Map<String, dynamic>))
.map((e) => Comment.fromJson(e as Map<String, dynamic>))
.toList(),
links: Links.fromJson(json['links'] as Map<String, dynamic>),
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
);
Map<String, dynamic> _$$CommentImplToJson(_$CommentImpl instance) =>
Map<String, dynamic> _$$CommentModelImplToJson(_$CommentModelImpl instance) =>
<String, dynamic>{
'data': instance.data,
'links': instance.links,
'meta': instance.meta,
};
_$DatumImpl _$$DatumImplFromJson(Map<String, dynamic> json) => _$DatumImpl(
_$CommentImpl _$$CommentImplFromJson(Map<String, dynamic> 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<dynamic>)
.map((e) => Datum.fromJson(e as Map<String, dynamic>))
.map((e) => Comment.fromJson(e as Map<String, dynamic>))
.toList(),
createdAt: DateTime.parse(json['created_at'] as String),
);
Map<String, dynamic> _$$DatumImplToJson(_$DatumImpl instance) =>
Map<String, dynamic> _$$CommentImplToJson(_$CommentImpl instance) =>
<String, dynamic>{
'id': instance.id,
'author_name': instance.authorName,
@@ -42,56 +43,3 @@ Map<String, dynamic> _$$DatumImplToJson(_$DatumImpl instance) =>
'children_comments': instance.childrenComments,
'created_at': instance.createdAt.toIso8601String(),
};
_$LinksImpl _$$LinksImplFromJson(Map<String, dynamic> json) => _$LinksImpl(
first: json['first'] as String,
last: json['last'] as String,
prev: json['prev'],
next: json['next'],
);
Map<String, dynamic> _$$LinksImplToJson(_$LinksImpl instance) =>
<String, dynamic>{
'first': instance.first,
'last': instance.last,
'prev': instance.prev,
'next': instance.next,
};
_$MetaImpl _$$MetaImplFromJson(Map<String, dynamic> 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<dynamic>)
.map((e) => Link.fromJson(e as Map<String, dynamic>))
.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<String, dynamic> _$$MetaImplToJson(_$MetaImpl instance) =>
<String, dynamic>{
'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<String, dynamic> json) => _$LinkImpl(
url: json['url'] as String?,
label: json['label'] as String,
active: json['active'] as bool,
);
Map<String, dynamic> _$$LinkImplToJson(_$LinkImpl instance) =>
<String, dynamic>{
'url': instance.url,
'label': instance.label,
'active': instance.active,
};

View File

@@ -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<Datum> data,
@JsonKey(name: "data") required List<Diet> 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<List<List<DailySchedule>>> 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<String, dynamic> json) => _$DatumFromJson(json);
factory Diet.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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<Link> 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<String, dynamic> 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<String, dynamic> json) => _$LinkFromJson(json);
factory DietType.fromJson(Map<String, dynamic> json) => _$DietTypeFromJson(json);
}
class EnumValues<T> {

File diff suppressed because it is too large Load Diff

View File

@@ -10,7 +10,7 @@ _$DietsPaginationImpl _$$DietsPaginationImplFromJson(
Map<String, dynamic> json) =>
_$DietsPaginationImpl(
data: (json['data'] as List<dynamic>)
.map((e) => Datum.fromJson(e as Map<String, dynamic>))
.map((e) => Diet.fromJson(e as Map<String, dynamic>))
.toList(),
links: Links.fromJson(json['links'] as Map<String, dynamic>),
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
@@ -24,13 +24,13 @@ Map<String, dynamic> _$$DietsPaginationImplToJson(
'meta': instance.meta,
};
_$DatumImpl _$$DatumImplFromJson(Map<String, dynamic> json) => _$DatumImpl(
_$DietImpl _$$DietImplFromJson(Map<String, dynamic> 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<String, dynamic>),
type: DietType.fromJson(json['type'] as Map<String, dynamic>),
details: json['details'] as String,
dailySchedule: (json['daily_schedule'] as List<dynamic>)
.map((e) => (e as List<dynamic>)
@@ -45,7 +45,7 @@ _$DatumImpl _$$DatumImplFromJson(Map<String, dynamic> json) => _$DatumImpl(
totalComments: (json['total_comments'] as num).toInt(),
);
Map<String, dynamic> _$$DatumImplToJson(_$DatumImpl instance) =>
Map<String, dynamic> _$$DietImplToJson(_$DietImpl instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
@@ -98,70 +98,18 @@ const _$PortionEnumMap = {
Portion.PCS: 'pcs',
};
_$TypeImpl _$$TypeImplFromJson(Map<String, dynamic> json) => _$TypeImpl(
_$DietTypeImpl _$$DietTypeImplFromJson(Map<String, dynamic> json) =>
_$DietTypeImpl(
alko: json['alko'] as bool?,
veg: json['veg'] as bool?,
corb: json['corb'] as bool?,
meat: json['meat'] as bool?,
);
Map<String, dynamic> _$$TypeImplToJson(_$TypeImpl instance) =>
Map<String, dynamic> _$$DietTypeImplToJson(_$DietTypeImpl instance) =>
<String, dynamic>{
'alko': instance.alko,
'veg': instance.veg,
'corb': instance.corb,
'meat': instance.meat,
};
_$LinksImpl _$$LinksImplFromJson(Map<String, dynamic> json) => _$LinksImpl(
first: json['first'] as String,
last: json['last'] as String,
prev: json['prev'],
next: json['next'],
);
Map<String, dynamic> _$$LinksImplToJson(_$LinksImpl instance) =>
<String, dynamic>{
'first': instance.first,
'last': instance.last,
'prev': instance.prev,
'next': instance.next,
};
_$MetaImpl _$$MetaImplFromJson(Map<String, dynamic> 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<dynamic>)
.map((e) => Link.fromJson(e as Map<String, dynamic>))
.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<String, dynamic> _$$MetaImplToJson(_$MetaImpl instance) =>
<String, dynamic>{
'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<String, dynamic> json) => _$LinkImpl(
url: json['url'] as String?,
label: json['label'] as String,
active: json['active'] as bool,
);
Map<String, dynamic> _$$LinkImplToJson(_$LinkImpl instance) =>
<String, dynamic>{
'url': instance.url,
'label': instance.label,
'active': instance.active,
};

View File

@@ -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';

View File

@@ -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({

View File

@@ -20,7 +20,7 @@ mixin _$CommentsState {
TResult when<TResult extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
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 extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(Comment comment)? loaded,
TResult Function(CommentModel comment)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {

View File

@@ -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<RecipesState> {
final FeedRepository feedRepository;
final RecipeRepository recipeRepository;
Set<int> _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,
));
}
}

View File

@@ -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<Recipes> recipesList,
required List<RecipeTag> recipesTags,
required Set<int> selectedTags,
required int selectedTagsCounter,
}) = RecipesStateLoaded;
const factory RecipesState.error({

View File

@@ -20,7 +20,12 @@ mixin _$RecipesState {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<Recipes> recipesList) loaded,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter)
loaded,
required TResult Function(String errorMessage) error,
}) =>
throw _privateConstructorUsedError;
@@ -28,7 +33,9 @@ mixin _$RecipesState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList)? loaded,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter)?
loaded,
TResult? Function(String errorMessage)? error,
}) =>
throw _privateConstructorUsedError;
@@ -36,7 +43,9 @@ mixin _$RecipesState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList)? loaded,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) =>
@@ -126,7 +135,12 @@ class _$RecipesStateImpl implements _RecipesState {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<Recipes> recipesList) loaded,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter)
loaded,
required TResult Function(String errorMessage) error,
}) {
return $default();
@@ -137,7 +151,9 @@ class _$RecipesStateImpl implements _RecipesState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList)? loaded,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return $default?.call();
@@ -148,7 +164,9 @@ class _$RecipesStateImpl implements _RecipesState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList)? loaded,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
@@ -241,7 +259,12 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<Recipes> recipesList) loaded,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter)
loaded,
required TResult Function(String errorMessage) error,
}) {
return loading();
@@ -252,7 +275,9 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList)? loaded,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return loading?.call();
@@ -263,7 +288,9 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList)? loaded,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> 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<Recipes> recipesList});
$Res call(
{List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> 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<Recipes>,
recipesTags: null == recipesTags
? _value._recipesTags
: recipesTags // ignore: cast_nullable_to_non_nullable
as List<RecipeTag>,
selectedTags: null == selectedTags
? _value._selectedTags
: selectedTags // ignore: cast_nullable_to_non_nullable
as Set<int>,
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<Recipes> recipesList})
: _recipesList = recipesList;
const _$RecipesStateLoadedImpl(
{required final List<Recipes> recipesList,
required final List<RecipeTag> recipesTags,
required final Set<int> selectedTags,
required this.selectedTagsCounter})
: _recipesList = recipesList,
_recipesTags = recipesTags,
_selectedTags = selectedTags;
final List<Recipes> _recipesList;
@override
@@ -360,9 +412,28 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
return EqualUnmodifiableListView(_recipesList);
}
final List<RecipeTag> _recipesTags;
@override
List<RecipeTag> get recipesTags {
if (_recipesTags is EqualUnmodifiableListView) return _recipesTags;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_recipesTags);
}
final Set<int> _selectedTags;
@override
Set<int> 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 extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<Recipes> recipesList) loaded,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> 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 extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList)? loaded,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> 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 extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList)? loaded,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> 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<Recipes> recipesList}) =
_$RecipesStateLoadedImpl;
const factory RecipesStateLoaded(
{required final List<Recipes> recipesList,
required final List<RecipeTag> recipesTags,
required final Set<int> selectedTags,
required final int selectedTagsCounter}) = _$RecipesStateLoadedImpl;
List<Recipes> get recipesList;
List<RecipeTag> get recipesTags;
Set<int> 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 extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<Recipes> recipesList) loaded,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter)
loaded,
required TResult Function(String errorMessage) error,
}) {
return error(errorMessage);
@@ -549,7 +652,9 @@ class _$RecipesStateErrorImpl implements RecipesStateError {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList)? loaded,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return error?.call(errorMessage);
@@ -560,7 +665,9 @@ class _$RecipesStateErrorImpl implements RecipesStateError {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList)? loaded,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {

View File

@@ -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<FeedScreen> {
final searchController = TextEditingController();
final List<String> 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<RecipesCubit, RecipesState>(
builder: (BuildContext context, RecipesState state) {
if (state is RecipesStateLoaded) {
return TagsModalWidget(
tagsList: state.recipesTags,
selectedTags: state.selectedTags,
);
} else {
return Container();
}
},
);
},
);
context.read<RecipesCubit>().loadRecipesList();
},
)
: null,
appBar: AppBar(
backgroundColor: Colors.white,
toolbarHeight: 0,
@@ -85,7 +118,7 @@ class _FeedScreenState extends State<FeedScreen> {
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<FeedScreen> {
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<RecipesCubit>().loadRecipesList(query: query);
}
},
);
} else {
EasyDebounce.debounce(
'searchFeed',
Duration(milliseconds: 500),
() {
switch (_selectedChipIndex) {
case 1:
context.read<RecipesCubit>().loadRecipesList(query: query);
}
},
);
}
},
decoration: InputDecoration(
hintText: 'Поиск',
hintStyle: TextStyle(
@@ -304,6 +363,8 @@ class _FeedScreenState extends State<FeedScreen> {
onSelected: (bool selected) {
setState(() {
_selectedChipIndex = index;
searchController.clear();
FocusScope.of(context).requestFocus(new FocusNode());
});
},
);

View File

@@ -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<DietsWidget> createState() => _DietsWidgetState();
@@ -18,7 +18,7 @@ class _DietsWidgetState extends State<DietsWidget> {
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<DietsWidget> {
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<DietsWidget> {
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<DietsWidget> {
),
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<DietsWidget> {
),
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<DietsWidget> {
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<DietsWidget> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
widget.datum.details,
widget.diet.details,
style: TextStyle(
color: Colors.black87,
),

View File

@@ -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<RecipeTag> tagsList;
final Set<int> selectedTags;
const TagsModalWidget({
super.key,
required this.tagsList,
required this.selectedTags,
});
@override
State<TagsModalWidget> createState() => _TagsModalWidgetState();
}
class _TagsModalWidgetState extends State<TagsModalWidget> {
@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<RecipesCubit>().updateTags(tag),
);
}
}

View File

@@ -17,9 +17,16 @@ class FeedRepository {
}
}
Future<List<Recipes>> getRecipes() async {
Future<List<Recipes>> getRecipes({
String? query,
List<int>? 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<Comment> getBlogPostComments(int id) async {
Future<CommentModel> getBlogPostComments(int id) async {
try {
return (await feedService.getBlogPostComments(id: id));
} catch (e) {
@@ -57,7 +64,7 @@ class FeedRepository {
}
}
Future<Comment> getDietsComments(int id) async {
Future<CommentModel> getDietsComments(int id) async {
try {
return (await feedService.getDietsComments(id: id));
} catch (e) {
@@ -81,7 +88,7 @@ class FeedRepository {
}
}
Future<Comment> getRecipesComments(String id) async {
Future<CommentModel> getRecipesComments(String id) async {
try {
return (await feedService.getRecipesComments(id: id));
} catch (e) {

View File

@@ -17,13 +17,16 @@ abstract class FeedService {
});
@GET('/api/recipes/index')
Future<RecipesPagination> getRecipes();
Future<RecipesPagination> getRecipes({
@Query('filters[tags][tags.id][\$in][]') required List<int>? tags,
@Query('filters[title][\$contains]') required String? query,
});
@GET('/api/diets/index')
Future<DietsPagination> getDiets();
@GET('/api/blogPosts/{id}/comments/show')
Future<Comment> getBlogPostComments({
Future<CommentModel> getBlogPostComments({
@Path() required int id,
});
@@ -35,7 +38,7 @@ abstract class FeedService {
});
@GET('/api/diets/{id}/comments/show')
Future<Comment> getDietsComments({
Future<CommentModel> getDietsComments({
@Path() required int id,
});
@@ -47,7 +50,7 @@ abstract class FeedService {
});
@GET('/api/recipes/{id}/comments/show')
Future<Comment> getRecipesComments({
Future<CommentModel> getRecipesComments({
@Path() required String id,
});

View File

@@ -55,9 +55,16 @@ class _FeedService implements FeedService {
}
@override
Future<RecipesPagination> getRecipes() async {
Future<RecipesPagination> getRecipes({
List<int>? tags,
String? query,
}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final queryParameters = <String, dynamic>{
r'filters[tags][tags.id][$in][]': tags,
r'filters[title][$contains]': query,
};
queryParameters.removeWhere((k, v) => v == null);
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<RecipesPagination>(Options(
@@ -121,12 +128,12 @@ class _FeedService implements FeedService {
}
@override
Future<Comment> getBlogPostComments({required int id}) async {
Future<CommentModel> getBlogPostComments({required int id}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<Comment>(Options(
final _options = _setStreamType<CommentModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
@@ -143,9 +150,9 @@ class _FeedService implements FeedService {
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_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<Comment> getDietsComments({required int id}) async {
Future<CommentModel> getDietsComments({required int id}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<Comment>(Options(
final _options = _setStreamType<CommentModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
@@ -216,9 +223,9 @@ class _FeedService implements FeedService {
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_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<Comment> getRecipesComments({required String id}) async {
Future<CommentModel> getRecipesComments({required String id}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<Comment>(Options(
final _options = _setStreamType<CommentModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
@@ -289,9 +296,9 @@ class _FeedService implements FeedService {
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_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;

View File

@@ -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<ChartPoint> chartPoints,
@JsonKey(name: "chartPoints") required List<ChartPointModel> chartPoints,
@JsonKey(name: "userDetails") required UserDetails userDetails,
@JsonKey(name: "circumferences") required List<Circumference> circumferences,
@JsonKey(name: "finishedPlans") required List<dynamic> 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<String, dynamic> json) => _$ChartPointFromJson(json);
factory ChartPointModel.fromJson(Map<String, dynamic> json) => _$ChartPointModelFromJson(json);
}

View File

@@ -23,7 +23,7 @@ mixin _$ProfileModel {
@JsonKey(name: "user")
User get user => throw _privateConstructorUsedError;
@JsonKey(name: "chartPoints")
List<ChartPoint> get chartPoints => throw _privateConstructorUsedError;
List<ChartPointModel> 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<ChartPoint> chartPoints,
@JsonKey(name: "chartPoints") List<ChartPointModel> chartPoints,
@JsonKey(name: "userDetails") UserDetails userDetails,
@JsonKey(name: "circumferences") List<Circumference> circumferences,
@JsonKey(name: "finishedPlans") List<dynamic> 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<ChartPoint>,
as List<ChartPointModel>,
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<ChartPoint> chartPoints,
@JsonKey(name: "chartPoints") List<ChartPointModel> chartPoints,
@JsonKey(name: "userDetails") UserDetails userDetails,
@JsonKey(name: "circumferences") List<Circumference> circumferences,
@JsonKey(name: "finishedPlans") List<dynamic> finishedPlans,
@@ -210,7 +210,7 @@ class __$$ProfileModelImplCopyWithImpl<$Res>
chartPoints: null == chartPoints
? _value._chartPoints
: chartPoints // ignore: cast_nullable_to_non_nullable
as List<ChartPoint>,
as List<ChartPointModel>,
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<ChartPoint> chartPoints,
@JsonKey(name: "chartPoints")
required final List<ChartPointModel> chartPoints,
@JsonKey(name: "userDetails") required this.userDetails,
@JsonKey(name: "circumferences")
required final List<Circumference> circumferences,
@@ -280,10 +281,10 @@ class _$ProfileModelImpl implements _ProfileModel {
@override
@JsonKey(name: "user")
final User user;
final List<ChartPoint> _chartPoints;
final List<ChartPointModel> _chartPoints;
@override
@JsonKey(name: "chartPoints")
List<ChartPoint> get chartPoints {
List<ChartPointModel> 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<ChartPoint> chartPoints,
@JsonKey(name: "chartPoints")
required final List<ChartPointModel> chartPoints,
@JsonKey(name: "userDetails") required final UserDetails userDetails,
@JsonKey(name: "circumferences")
required final List<Circumference> circumferences,
@@ -440,7 +442,7 @@ abstract class _ProfileModel implements ProfileModel {
User get user;
@override
@JsonKey(name: "chartPoints")
List<ChartPoint> get chartPoints;
List<ChartPointModel> get chartPoints;
@override
@JsonKey(name: "userDetails")
UserDetails get userDetails;
@@ -2110,12 +2112,12 @@ abstract class _UserDetails implements UserDetails {
throw _privateConstructorUsedError;
}
ChartPoint _$ChartPointFromJson(Map<String, dynamic> json) {
return _ChartPoint.fromJson(json);
ChartPointModel _$ChartPointModelFromJson(Map<String, dynamic> 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<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ChartPointCopyWith<ChartPoint> get copyWith =>
$ChartPointModelCopyWith<ChartPointModel> 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<String, dynamic> json) =>
_$$ChartPointImplFromJson(json);
factory _$ChartPointModelImpl.fromJson(Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> json) =
_$ChartPointImpl.fromJson;
factory _ChartPointModel.fromJson(Map<String, dynamic> 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;
}

View File

@@ -10,7 +10,7 @@ _$ProfileModelImpl _$$ProfileModelImplFromJson(Map<String, dynamic> json) =>
_$ProfileModelImpl(
user: User.fromJson(json['user'] as Map<String, dynamic>),
chartPoints: (json['chartPoints'] as List<dynamic>)
.map((e) => ChartPoint.fromJson(e as Map<String, dynamic>))
.map((e) => ChartPointModel.fromJson(e as Map<String, dynamic>))
.toList(),
userDetails:
UserDetails.fromJson(json['userDetails'] as Map<String, dynamic>),
@@ -164,8 +164,9 @@ Map<String, dynamic> _$$UserDetailsImplToJson(_$UserDetailsImpl instance) =>
'activity_coefficient': instance.activityCoefficient,
};
_$ChartPointImpl _$$ChartPointImplFromJson(Map<String, dynamic> json) =>
_$ChartPointImpl(
_$ChartPointModelImpl _$$ChartPointModelImplFromJson(
Map<String, dynamic> 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<String, dynamic> json) =>
updatedAt: DateTime.parse(json['updated_at'] as String),
);
Map<String, dynamic> _$$ChartPointImplToJson(_$ChartPointImpl instance) =>
Map<String, dynamic> _$$ChartPointModelImplToJson(
_$ChartPointModelImpl instance) =>
<String, dynamic>{
'id': instance.id,
'user_id': instance.userId,

View File

@@ -21,7 +21,7 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen> {
List<Circumference> chartData = [];
List<ChartPoint> chartPoints = [];
List<ChartPointModel> chartPoints = [];
final List<String> chipsLabelList = ['Вес', 'Замеры', 'ИМТ'];
final List<String> chipsIntervalLabelList = ['1М', '3М', '6М', '1Г', 'ВСЁ ВРЕМЯ'];
int _selectedChipIndex = 0;
@@ -49,95 +49,98 @@ class _ProfileScreenState extends State<ProfileScreen> {
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<ProfileScreen> {
);
}
_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),

View File

@@ -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<CartesianSeries<Circumference, DateTime>> _getSplineSeries() {
final Color seriesColor1 = Colors.red;
final Color seriesColor2 = Colors.blue;
final Color seriesColor2 = appTheme.blueA400;
final Color seriesColor3 = Colors.green;
return <CartesianSeries<Circumference, DateTime>>[
SplineSeries<Circumference, DateTime>(
SplineAreaSeries<Circumference, DateTime>(
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<Circumference, DateTime>(
SplineAreaSeries<Circumference, DateTime>(
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<Circumference, DateTime>(
SplineAreaSeries<Circumference, DateTime>(
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,

View File

@@ -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<ProfileModel.ChartPoint> chartPoints;
final List<ChartPointModel> 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<CartesianSeries<ProfileModel.ChartPoint, DateTime>> _getSplineSeries() {
return <CartesianSeries<ProfileModel.ChartPoint, DateTime>>[
SplineSeries<ProfileModel.ChartPoint, DateTime>(
List<CartesianSeries<ChartPointModel, DateTime>> _getSplineSeries() {
return <CartesianSeries<ChartPointModel, DateTime>>[
SplineAreaSeries<ChartPointModel, DateTime>(
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)),
),
];
}

View File

@@ -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<ProfileModel.ChartPoint> chartPoints;
final List<ChartPointModel> 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<CartesianSeries<ProfileModel.ChartPoint, DateTime>> _getSplineSeries() {
return <CartesianSeries<ProfileModel.ChartPoint, DateTime>>[
SplineAreaSeries<ProfileModel.ChartPoint, DateTime>(
List<CartesianSeries<ChartPointModel, DateTime>> _getSplineSeries() {
return <CartesianSeries<ChartPointModel, DateTime>>[
SplineAreaSeries<ChartPointModel, DateTime>(
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,
),
];
}

View File

@@ -41,7 +41,7 @@ class ProfileRepository {
}
}
Future<ChartPoint> addWeight({
Future<ChartPointModel> addWeight({
required int weight,
}) async {
try {

View File

@@ -25,7 +25,7 @@ abstract class ProfileService {
});
@POST('/api/profile/addWeight')
Future<Map<String, ChartPoint>> addWeight({
Future<Map<String, ChartPointModel>> addWeight({
@Part() required int weight,
});

View File

@@ -138,7 +138,7 @@ class _ProfileService implements ProfileService {
}
@override
Future<Map<String, ChartPoint>> addWeight({required int weight}) async {
Future<Map<String, ChartPointModel>> addWeight({required int weight}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
@@ -147,7 +147,7 @@ class _ProfileService implements ProfileService {
'weight',
weight.toString(),
));
final _options = _setStreamType<Map<String, ChartPoint>>(Options(
final _options = _setStreamType<Map<String, ChartPointModel>>(Options(
method: 'POST',
headers: _headers,
extra: _extra,
@@ -164,10 +164,10 @@ class _ProfileService implements ProfileService {
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late Map<String, ChartPoint> _value;
late Map<String, ChartPointModel> _value;
try {
_value = _result.data!.map((k, dynamic v) =>
MapEntry(k, ChartPoint.fromJson(v as Map<String, dynamic>)));
MapEntry(k, ChartPointModel.fromJson(v as Map<String, dynamic>)));
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;

View File

@@ -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<RecipeTag> data,
@JsonKey(name: "links") required Links links,
@JsonKey(name: "meta") required Meta meta,
}) = _RecipeTagModel;
factory RecipeTagModel.fromJson(Map<String, dynamic> 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<String, dynamic> json) => _$RecipeTagFromJson(json);
}

View File

@@ -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>(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<String, dynamic> json) {
return _RecipeTagModel.fromJson(json);
}
/// @nodoc
mixin _$RecipeTagModel {
@JsonKey(name: "data")
List<RecipeTag> get data => throw _privateConstructorUsedError;
@JsonKey(name: "links")
Links get links => throw _privateConstructorUsedError;
@JsonKey(name: "meta")
Meta get meta => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$RecipeTagModelCopyWith<RecipeTagModel> 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<RecipeTag> 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<RecipeTag>,
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<RecipeTag> 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<RecipeTag>,
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<RecipeTag> data,
@JsonKey(name: "links") required this.links,
@JsonKey(name: "meta") required this.meta})
: _data = data;
factory _$RecipeTagModelImpl.fromJson(Map<String, dynamic> json) =>
_$$RecipeTagModelImplFromJson(json);
final List<RecipeTag> _data;
@override
@JsonKey(name: "data")
List<RecipeTag> 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<String, dynamic> toJson() {
return _$$RecipeTagModelImplToJson(
this,
);
}
}
abstract class _RecipeTagModel implements RecipeTagModel {
const factory _RecipeTagModel(
{@JsonKey(name: "data") required final List<RecipeTag> data,
@JsonKey(name: "links") required final Links links,
@JsonKey(name: "meta") required final Meta meta}) = _$RecipeTagModelImpl;
factory _RecipeTagModel.fromJson(Map<String, dynamic> json) =
_$RecipeTagModelImpl.fromJson;
@override
@JsonKey(name: "data")
List<RecipeTag> 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<String, dynamic> 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<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$RecipeTagCopyWith<RecipeTag> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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;
}

View File

@@ -0,0 +1,40 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'recipe_tag_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$RecipeTagModelImpl _$$RecipeTagModelImplFromJson(Map<String, dynamic> json) =>
_$RecipeTagModelImpl(
data: (json['data'] as List<dynamic>)
.map((e) => RecipeTag.fromJson(e as Map<String, dynamic>))
.toList(),
links: Links.fromJson(json['links'] as Map<String, dynamic>),
meta: Meta.fromJson(json['meta'] as Map<String, dynamic>),
);
Map<String, dynamic> _$$RecipeTagModelImplToJson(
_$RecipeTagModelImpl instance) =>
<String, dynamic>{
'data': instance.data,
'links': instance.links,
'meta': instance.meta,
};
_$RecipeTagImpl _$$RecipeTagImplFromJson(Map<String, dynamic> 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<String, dynamic> _$$RecipeTagImplToJson(_$RecipeTagImpl instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
'created_at': instance.createdAt.toIso8601String(),
'updated_at': instance.updatedAt.toIso8601String(),
};

View File

@@ -394,7 +394,7 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
);
}
_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<AboutRecipesScreen> {
);
}
_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<AboutRecipesScreen> {
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<AboutRecipesScreen> {
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<AboutRecipesScreen> {
),
SizedBox(width: 4),
Text(
datum.body,
comment.body,
style: TextStyle(
height: 1,
color: Colors.black,
@@ -455,7 +455,7 @@ class _AboutRecipesScreenState extends State<AboutRecipesScreen> {
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<AboutRecipesScreen> {
GestureDetector(
onTap: () {
setState(() {
replyId = datum.id;
replyId = comment.id;
});
},
child: Text(

View File

@@ -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<List<RecipeTag>> getRecipesTags() async {
try {
return (await recipeService.getTags()).data;
} catch (e) {
rethrow;
}
}
}

View File

@@ -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<RecipeModel> editRecipe(@Part() Map<String, Object?> recipe, String id);
@GET('/api/recipes/tags')
Future<RecipeTagModel> getTags();
}

View File

@@ -220,6 +220,39 @@ class _RecipeService implements RecipeService {
return _value;
}
@override
Future<RecipeTagModel> getTags() async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<RecipeTagModel>(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<Map<String, dynamic>>(_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<T>(RequestOptions requestOptions) {
if (T != dynamic &&
!(requestOptions.responseType == ResponseType.bytes ||

View File

@@ -42,7 +42,7 @@ Future<void> init() async {
sl.registerFactory<RegistrationCubit>(() => RegistrationCubit(registrationRepository: sl()));
sl.registerFactory<ChatRoomCubit>(() => ChatRoomCubit(chatRepository: sl(), initializationCubit: sl()));
sl.registerFactory<FeedCubit>(() => FeedCubit(feedRepository: sl()));
sl.registerFactory<RecipesCubit>(() => RecipesCubit(feedRepository: sl()));
sl.registerFactory<RecipesCubit>(() => RecipesCubit(feedRepository: sl(), recipeRepository: sl()));
sl.registerFactory<DiaryBloc>(() => DiaryBloc(diaryRepository: sl()));
sl.registerFactory<CalendarCubit>(() => CalendarCubit(calendarRepository: sl()));
sl.registerFactory<ProfileCubit>(() => ProfileCubit(profileRepository: sl()));