refactor(feed): refactor feed screen

This commit is contained in:
alex
2024-06-28 12:55:57 +03:00
parent 58a7ca933d
commit 060fb512a0
17 changed files with 1183 additions and 197 deletions

View File

@@ -0,0 +1,20 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'feed_blog_post_model.freezed.dart';
part 'feed_blog_post_model.g.dart';
@freezed
class FeedBlogPostModel with _$FeedBlogPostModel {
const factory FeedBlogPostModel({
required int id,
required String state,
required String image,
required String description,
@JsonKey(name: "youtube_url") required String youtubeUrl,
@JsonKey(name: "created_at") required DateTime createdAt,
@JsonKey(name: "updated_at") required DateTime updatedAt,
required String title,
}) = _FeedBlogPostModel;
factory FeedBlogPostModel.fromJson(Map<String, Object?> json) => _$FeedBlogPostModelFromJson(json);
}

View File

@@ -0,0 +1,310 @@
// 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 'feed_blog_post_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');
FeedBlogPostModel _$FeedBlogPostModelFromJson(Map<String, dynamic> json) {
return _FeedBlogPostModel.fromJson(json);
}
/// @nodoc
mixin _$FeedBlogPostModel {
int get id => throw _privateConstructorUsedError;
String get state => throw _privateConstructorUsedError;
String get image => throw _privateConstructorUsedError;
String get description => throw _privateConstructorUsedError;
@JsonKey(name: "youtube_url")
String get youtubeUrl => throw _privateConstructorUsedError;
@JsonKey(name: "created_at")
DateTime get createdAt => throw _privateConstructorUsedError;
@JsonKey(name: "updated_at")
DateTime get updatedAt => throw _privateConstructorUsedError;
String get title => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$FeedBlogPostModelCopyWith<FeedBlogPostModel> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $FeedBlogPostModelCopyWith<$Res> {
factory $FeedBlogPostModelCopyWith(
FeedBlogPostModel value, $Res Function(FeedBlogPostModel) then) =
_$FeedBlogPostModelCopyWithImpl<$Res, FeedBlogPostModel>;
@useResult
$Res call(
{int id,
String state,
String image,
String description,
@JsonKey(name: "youtube_url") String youtubeUrl,
@JsonKey(name: "created_at") DateTime createdAt,
@JsonKey(name: "updated_at") DateTime updatedAt,
String title});
}
/// @nodoc
class _$FeedBlogPostModelCopyWithImpl<$Res, $Val extends FeedBlogPostModel>
implements $FeedBlogPostModelCopyWith<$Res> {
_$FeedBlogPostModelCopyWithImpl(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? state = null,
Object? image = null,
Object? description = null,
Object? youtubeUrl = null,
Object? createdAt = null,
Object? updatedAt = null,
Object? title = null,
}) {
return _then(_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as int,
state: null == state
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as String,
image: null == image
? _value.image
: image // ignore: cast_nullable_to_non_nullable
as String,
description: null == description
? _value.description
: description // ignore: cast_nullable_to_non_nullable
as String,
youtubeUrl: null == youtubeUrl
? _value.youtubeUrl
: youtubeUrl // 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,
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}
/// @nodoc
abstract class _$$FeedBlogPostModelImplCopyWith<$Res>
implements $FeedBlogPostModelCopyWith<$Res> {
factory _$$FeedBlogPostModelImplCopyWith(_$FeedBlogPostModelImpl value,
$Res Function(_$FeedBlogPostModelImpl) then) =
__$$FeedBlogPostModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{int id,
String state,
String image,
String description,
@JsonKey(name: "youtube_url") String youtubeUrl,
@JsonKey(name: "created_at") DateTime createdAt,
@JsonKey(name: "updated_at") DateTime updatedAt,
String title});
}
/// @nodoc
class __$$FeedBlogPostModelImplCopyWithImpl<$Res>
extends _$FeedBlogPostModelCopyWithImpl<$Res, _$FeedBlogPostModelImpl>
implements _$$FeedBlogPostModelImplCopyWith<$Res> {
__$$FeedBlogPostModelImplCopyWithImpl(_$FeedBlogPostModelImpl _value,
$Res Function(_$FeedBlogPostModelImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? state = null,
Object? image = null,
Object? description = null,
Object? youtubeUrl = null,
Object? createdAt = null,
Object? updatedAt = null,
Object? title = null,
}) {
return _then(_$FeedBlogPostModelImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as int,
state: null == state
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as String,
image: null == image
? _value.image
: image // ignore: cast_nullable_to_non_nullable
as String,
description: null == description
? _value.description
: description // ignore: cast_nullable_to_non_nullable
as String,
youtubeUrl: null == youtubeUrl
? _value.youtubeUrl
: youtubeUrl // 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,
title: null == title
? _value.title
: title // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
@JsonSerializable()
class _$FeedBlogPostModelImpl implements _FeedBlogPostModel {
const _$FeedBlogPostModelImpl(
{required this.id,
required this.state,
required this.image,
required this.description,
@JsonKey(name: "youtube_url") required this.youtubeUrl,
@JsonKey(name: "created_at") required this.createdAt,
@JsonKey(name: "updated_at") required this.updatedAt,
required this.title});
factory _$FeedBlogPostModelImpl.fromJson(Map<String, dynamic> json) =>
_$$FeedBlogPostModelImplFromJson(json);
@override
final int id;
@override
final String state;
@override
final String image;
@override
final String description;
@override
@JsonKey(name: "youtube_url")
final String youtubeUrl;
@override
@JsonKey(name: "created_at")
final DateTime createdAt;
@override
@JsonKey(name: "updated_at")
final DateTime updatedAt;
@override
final String title;
@override
String toString() {
return 'FeedBlogPostModel(id: $id, state: $state, image: $image, description: $description, youtubeUrl: $youtubeUrl, createdAt: $createdAt, updatedAt: $updatedAt, title: $title)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FeedBlogPostModelImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.state, state) || other.state == state) &&
(identical(other.image, image) || other.image == image) &&
(identical(other.description, description) ||
other.description == description) &&
(identical(other.youtubeUrl, youtubeUrl) ||
other.youtubeUrl == youtubeUrl) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt) &&
(identical(other.title, title) || other.title == title));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, id, state, image, description,
youtubeUrl, createdAt, updatedAt, title);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$FeedBlogPostModelImplCopyWith<_$FeedBlogPostModelImpl> get copyWith =>
__$$FeedBlogPostModelImplCopyWithImpl<_$FeedBlogPostModelImpl>(
this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$FeedBlogPostModelImplToJson(
this,
);
}
}
abstract class _FeedBlogPostModel implements FeedBlogPostModel {
const factory _FeedBlogPostModel(
{required final int id,
required final String state,
required final String image,
required final String description,
@JsonKey(name: "youtube_url") required final String youtubeUrl,
@JsonKey(name: "created_at") required final DateTime createdAt,
@JsonKey(name: "updated_at") required final DateTime updatedAt,
required final String title}) = _$FeedBlogPostModelImpl;
factory _FeedBlogPostModel.fromJson(Map<String, dynamic> json) =
_$FeedBlogPostModelImpl.fromJson;
@override
int get id;
@override
String get state;
@override
String get image;
@override
String get description;
@override
@JsonKey(name: "youtube_url")
String get youtubeUrl;
@override
@JsonKey(name: "created_at")
DateTime get createdAt;
@override
@JsonKey(name: "updated_at")
DateTime get updatedAt;
@override
String get title;
@override
@JsonKey(ignore: true)
_$$FeedBlogPostModelImplCopyWith<_$FeedBlogPostModelImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,33 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'feed_blog_post_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$FeedBlogPostModelImpl _$$FeedBlogPostModelImplFromJson(
Map<String, dynamic> json) =>
_$FeedBlogPostModelImpl(
id: (json['id'] as num).toInt(),
state: json['state'] as String,
image: json['image'] as String,
description: json['description'] as String,
youtubeUrl: json['youtube_url'] as String,
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
title: json['title'] as String,
);
Map<String, dynamic> _$$FeedBlogPostModelImplToJson(
_$FeedBlogPostModelImpl instance) =>
<String, dynamic>{
'id': instance.id,
'state': instance.state,
'image': instance.image,
'description': instance.description,
'youtube_url': instance.youtubeUrl,
'created_at': instance.createdAt.toIso8601String(),
'updated_at': instance.updatedAt.toIso8601String(),
'title': instance.title,
};

View File

@@ -0,0 +1,19 @@
import 'package:eatvio_app/core/app_export.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_state.dart';
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
class FeedCubit extends Cubit<FeedState> {
final FeedRepository feedRepository;
FeedCubit({required this.feedRepository}) : super(const FeedState.loading());
loadFeedBlogPostList() async {
emit(const FeedStateLoading());
try {
final feedBlogPostList = await feedRepository.getFeedBlogPostList();
emit(FeedState.loaded(feedBlogPostList: feedBlogPostList));
} catch (e) {
emit(FeedState.error(errorMessage: e.toString()));
}
}
}

View File

@@ -0,0 +1,19 @@
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'feed_state.freezed.dart';
@freezed
abstract class FeedState with _$FeedState {
const factory FeedState() = _FeedState;
const factory FeedState.loading() = FeedStateLoading;
const factory FeedState.loaded({
required List<FeedBlogPostModel> feedBlogPostList,
}) = FeedStateLoaded;
const factory FeedState.error({
required String errorMessage,
}) = FeedStateError;
}

View File

@@ -0,0 +1,620 @@
// 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 'feed_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$FeedState {
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<FeedBlogPostModel> feedBlogPostList) loaded,
required TResult Function(String errorMessage) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult? Function(String errorMessage)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_FeedState value) $default, {
required TResult Function(FeedStateLoading value) loading,
required TResult Function(FeedStateLoaded value) loaded,
required TResult Function(FeedStateError value) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_FeedState value)? $default, {
TResult? Function(FeedStateLoading value)? loading,
TResult? Function(FeedStateLoaded value)? loaded,
TResult? Function(FeedStateError value)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_FeedState value)? $default, {
TResult Function(FeedStateLoading value)? loading,
TResult Function(FeedStateLoaded value)? loaded,
TResult Function(FeedStateError value)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $FeedStateCopyWith<$Res> {
factory $FeedStateCopyWith(FeedState value, $Res Function(FeedState) then) =
_$FeedStateCopyWithImpl<$Res, FeedState>;
}
/// @nodoc
class _$FeedStateCopyWithImpl<$Res, $Val extends FeedState>
implements $FeedStateCopyWith<$Res> {
_$FeedStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
}
/// @nodoc
abstract class _$$FeedStateImplCopyWith<$Res> {
factory _$$FeedStateImplCopyWith(
_$FeedStateImpl value, $Res Function(_$FeedStateImpl) then) =
__$$FeedStateImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$FeedStateImplCopyWithImpl<$Res>
extends _$FeedStateCopyWithImpl<$Res, _$FeedStateImpl>
implements _$$FeedStateImplCopyWith<$Res> {
__$$FeedStateImplCopyWithImpl(
_$FeedStateImpl _value, $Res Function(_$FeedStateImpl) _then)
: super(_value, _then);
}
/// @nodoc
class _$FeedStateImpl implements _FeedState {
const _$FeedStateImpl();
@override
String toString() {
return 'FeedState()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$FeedStateImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<FeedBlogPostModel> feedBlogPostList) loaded,
required TResult Function(String errorMessage) error,
}) {
return $default();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return $default?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if ($default != null) {
return $default();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_FeedState value) $default, {
required TResult Function(FeedStateLoading value) loading,
required TResult Function(FeedStateLoaded value) loaded,
required TResult Function(FeedStateError value) error,
}) {
return $default(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_FeedState value)? $default, {
TResult? Function(FeedStateLoading value)? loading,
TResult? Function(FeedStateLoaded value)? loaded,
TResult? Function(FeedStateError value)? error,
}) {
return $default?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_FeedState value)? $default, {
TResult Function(FeedStateLoading value)? loading,
TResult Function(FeedStateLoaded value)? loaded,
TResult Function(FeedStateError value)? error,
required TResult orElse(),
}) {
if ($default != null) {
return $default(this);
}
return orElse();
}
}
abstract class _FeedState implements FeedState {
const factory _FeedState() = _$FeedStateImpl;
}
/// @nodoc
abstract class _$$FeedStateLoadingImplCopyWith<$Res> {
factory _$$FeedStateLoadingImplCopyWith(_$FeedStateLoadingImpl value,
$Res Function(_$FeedStateLoadingImpl) then) =
__$$FeedStateLoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$FeedStateLoadingImplCopyWithImpl<$Res>
extends _$FeedStateCopyWithImpl<$Res, _$FeedStateLoadingImpl>
implements _$$FeedStateLoadingImplCopyWith<$Res> {
__$$FeedStateLoadingImplCopyWithImpl(_$FeedStateLoadingImpl _value,
$Res Function(_$FeedStateLoadingImpl) _then)
: super(_value, _then);
}
/// @nodoc
class _$FeedStateLoadingImpl implements FeedStateLoading {
const _$FeedStateLoadingImpl();
@override
String toString() {
return 'FeedState.loading()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$FeedStateLoadingImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<FeedBlogPostModel> feedBlogPostList) loaded,
required TResult Function(String errorMessage) error,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_FeedState value) $default, {
required TResult Function(FeedStateLoading value) loading,
required TResult Function(FeedStateLoaded value) loaded,
required TResult Function(FeedStateError value) error,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_FeedState value)? $default, {
TResult? Function(FeedStateLoading value)? loading,
TResult? Function(FeedStateLoaded value)? loaded,
TResult? Function(FeedStateError value)? error,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_FeedState value)? $default, {
TResult Function(FeedStateLoading value)? loading,
TResult Function(FeedStateLoaded value)? loaded,
TResult Function(FeedStateError value)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class FeedStateLoading implements FeedState {
const factory FeedStateLoading() = _$FeedStateLoadingImpl;
}
/// @nodoc
abstract class _$$FeedStateLoadedImplCopyWith<$Res> {
factory _$$FeedStateLoadedImplCopyWith(_$FeedStateLoadedImpl value,
$Res Function(_$FeedStateLoadedImpl) then) =
__$$FeedStateLoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({List<FeedBlogPostModel> feedBlogPostList});
}
/// @nodoc
class __$$FeedStateLoadedImplCopyWithImpl<$Res>
extends _$FeedStateCopyWithImpl<$Res, _$FeedStateLoadedImpl>
implements _$$FeedStateLoadedImplCopyWith<$Res> {
__$$FeedStateLoadedImplCopyWithImpl(
_$FeedStateLoadedImpl _value, $Res Function(_$FeedStateLoadedImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? feedBlogPostList = null,
}) {
return _then(_$FeedStateLoadedImpl(
feedBlogPostList: null == feedBlogPostList
? _value._feedBlogPostList
: feedBlogPostList // ignore: cast_nullable_to_non_nullable
as List<FeedBlogPostModel>,
));
}
}
/// @nodoc
class _$FeedStateLoadedImpl implements FeedStateLoaded {
const _$FeedStateLoadedImpl(
{required final List<FeedBlogPostModel> feedBlogPostList})
: _feedBlogPostList = feedBlogPostList;
final List<FeedBlogPostModel> _feedBlogPostList;
@override
List<FeedBlogPostModel> get feedBlogPostList {
if (_feedBlogPostList is EqualUnmodifiableListView)
return _feedBlogPostList;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_feedBlogPostList);
}
@override
String toString() {
return 'FeedState.loaded(feedBlogPostList: $feedBlogPostList)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FeedStateLoadedImpl &&
const DeepCollectionEquality()
.equals(other._feedBlogPostList, _feedBlogPostList));
}
@override
int get hashCode => Object.hash(
runtimeType, const DeepCollectionEquality().hash(_feedBlogPostList));
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$FeedStateLoadedImplCopyWith<_$FeedStateLoadedImpl> get copyWith =>
__$$FeedStateLoadedImplCopyWithImpl<_$FeedStateLoadedImpl>(
this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<FeedBlogPostModel> feedBlogPostList) loaded,
required TResult Function(String errorMessage) error,
}) {
return loaded(feedBlogPostList);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return loaded?.call(feedBlogPostList);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(feedBlogPostList);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_FeedState value) $default, {
required TResult Function(FeedStateLoading value) loading,
required TResult Function(FeedStateLoaded value) loaded,
required TResult Function(FeedStateError value) error,
}) {
return loaded(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_FeedState value)? $default, {
TResult? Function(FeedStateLoading value)? loading,
TResult? Function(FeedStateLoaded value)? loaded,
TResult? Function(FeedStateError value)? error,
}) {
return loaded?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_FeedState value)? $default, {
TResult Function(FeedStateLoading value)? loading,
TResult Function(FeedStateLoaded value)? loaded,
TResult Function(FeedStateError value)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(this);
}
return orElse();
}
}
abstract class FeedStateLoaded implements FeedState {
const factory FeedStateLoaded(
{required final List<FeedBlogPostModel> feedBlogPostList}) =
_$FeedStateLoadedImpl;
List<FeedBlogPostModel> get feedBlogPostList;
@JsonKey(ignore: true)
_$$FeedStateLoadedImplCopyWith<_$FeedStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$FeedStateErrorImplCopyWith<$Res> {
factory _$$FeedStateErrorImplCopyWith(_$FeedStateErrorImpl value,
$Res Function(_$FeedStateErrorImpl) then) =
__$$FeedStateErrorImplCopyWithImpl<$Res>;
@useResult
$Res call({String errorMessage});
}
/// @nodoc
class __$$FeedStateErrorImplCopyWithImpl<$Res>
extends _$FeedStateCopyWithImpl<$Res, _$FeedStateErrorImpl>
implements _$$FeedStateErrorImplCopyWith<$Res> {
__$$FeedStateErrorImplCopyWithImpl(
_$FeedStateErrorImpl _value, $Res Function(_$FeedStateErrorImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? errorMessage = null,
}) {
return _then(_$FeedStateErrorImpl(
errorMessage: null == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$FeedStateErrorImpl implements FeedStateError {
const _$FeedStateErrorImpl({required this.errorMessage});
@override
final String errorMessage;
@override
String toString() {
return 'FeedState.error(errorMessage: $errorMessage)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$FeedStateErrorImpl &&
(identical(other.errorMessage, errorMessage) ||
other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType, errorMessage);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$FeedStateErrorImplCopyWith<_$FeedStateErrorImpl> get copyWith =>
__$$FeedStateErrorImplCopyWithImpl<_$FeedStateErrorImpl>(
this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(List<FeedBlogPostModel> feedBlogPostList) loaded,
required TResult Function(String errorMessage) error,
}) {
return error(errorMessage);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return error?.call(errorMessage);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<FeedBlogPostModel> feedBlogPostList)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(errorMessage);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_FeedState value) $default, {
required TResult Function(FeedStateLoading value) loading,
required TResult Function(FeedStateLoaded value) loaded,
required TResult Function(FeedStateError value) error,
}) {
return error(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_FeedState value)? $default, {
TResult? Function(FeedStateLoading value)? loading,
TResult? Function(FeedStateLoaded value)? loaded,
TResult? Function(FeedStateError value)? error,
}) {
return error?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_FeedState value)? $default, {
TResult Function(FeedStateLoading value)? loading,
TResult Function(FeedStateLoaded value)? loaded,
TResult Function(FeedStateError value)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(this);
}
return orElse();
}
}
abstract class FeedStateError implements FeedState {
const factory FeedStateError({required final String errorMessage}) =
_$FeedStateErrorImpl;
String get errorMessage;
@JsonKey(ignore: true)
_$$FeedStateErrorImplCopyWith<_$FeedStateErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,315 @@
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_state.dart';
import 'package:flutter/cupertino.dart';
import 'package:go_router/go_router.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:eatvio_app/presentation/feed/feed_screen/widgets/feed_search_view.dart';
import 'package:eatvio_app/presentation/feed/feed_screen/widgets/feed_scroll_item.dart';
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/core/app_export.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class FeedScreen extends StatelessWidget {
Widget build(BuildContext context) {
return BlocBuilder<FeedCubit, FeedState>(
builder: (BuildContext context, FeedState state) {
if (state is FeedStateLoaded) {
return _buildFeedScreen(context, state);
} else {
return Scaffold(
body: Center(
child: CupertinoActivityIndicator(),
),
);
}
},
);
}
_buildFeedScreen(BuildContext context, FeedStateLoaded state) {
mediaQueryData = MediaQuery.of(context);
return RefreshIndicator(
onRefresh: () => context.read<FeedCubit>().loadFeedBlogPostList(),
child: Scaffold(
appBar: AppBar(
toolbarHeight: 0,
),
backgroundColor: Colors.grey[200],
resizeToAvoidBottomInset: true,
body: SingleChildScrollView(
child: Container(
width: double.maxFinite,
decoration: BoxDecoration(color: Colors.grey[200]),
child: Padding(
padding: EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(height: 20),
_buildSearch(context),
SizedBox(height: 20),
_buildMenu(context, state),
SizedBox(height: 20),
_buildBlogPostList(context, state),
],
),
),
),
),
),
);
}
_buildSearch(BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(12)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3),
),
],
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
children: [
CustomSearchView(
hintText: "Поиск записей",
),
SizedBox(height: 10),
Row(
children: [
Flexible(
flex: 5,
child: CustomOutlinedButton(
text: "Найти запись",
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
),
),
SizedBox(width: 8), // Add some spacing between the buttons
Flexible(
flex: 1,
child: CustomOutlinedButton(
text: "+",
onPressed: () => GoRouter.of(context).goNamed('blogPostCreateScreen'),
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
),
),
],
),
],
),
),
);
}
_buildBlogPostList(BuildContext context, FeedStateLoaded state) {
List<Widget> postWidgets = [];
for (var post in state.feedBlogPostList) {
postWidgets.add(_buildFeedEntry(post, context));
}
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: postWidgets,
);
}
_buildFeedEntry(FeedBlogPostModel post, BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(12)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3),
),
],
),
child: Column(
children: [
ListTile(
leading: CachedNetworkImage(
imageUrl: dotenv.env['STORAGE_URL']! + ('' ?? ''),
/// todo profile photo path
imageBuilder: (context, imageProvider) => CircleAvatar(
backgroundImage: imageProvider,
radius: 24,
),
placeholder: (context, url) => CircleAvatar(
child: Icon(Icons.person),
backgroundColor: Colors.white,
radius: 24,
),
errorWidget: (context, url, error) => CircleAvatar(
child: Icon(Icons.person),
backgroundColor: Colors.white,
radius: 24,
),
),
title: Text(
'Authorae',
/// todo author name
style: CustomTextStyles.titleMediumSemiBold,
),
subtitle: Text(
DateFormat('dd.MM.yyyy').format(post.updatedAt),
style: theme.textTheme.bodyMedium,
),
onTap: () => GoRouter.of(context).goNamed(
'blogPostScreen',
extra: post.id.toString(),
),
trailing: PopupMenuButton<String>(
onSelected: (value) => print("tap"),
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: 'edit',
child: Text('Редактировать'),
),
PopupMenuItem<String>(
value: 'delete',
child: Text('Удалить'),
),
],
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Spacer(),
Align(
alignment: Alignment.center,
child: Text(
post.title,
style: CustomTextStyles.titleMediumBlack,
),
),
Spacer(),
],
),
SizedBox(height: 8.0),
Text(
post.description,
style: CustomTextStyles.bodyMediumBluegray800,
),
SizedBox(height: 16.0),
CachedNetworkImage(
imageUrl: dotenv.env['STORAGE_URL']! + (post.image ?? ''),
imageBuilder: (context, imageProvider) => Stack(
children: [
ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
child: Image(
image: imageProvider,
),
),
],
),
placeholder: (context, url) => CircularProgressIndicator(),
),
SizedBox(height: 16.0),
Row(
children: [
Padding(
padding: EdgeInsets.only(left: 4),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(right: 4),
child: Icon(Icons.comment_outlined),
),
Text(
"Комментировать",
),
],
),
),
Spacer(),
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 4),
child: Icon(Icons.favorite_outline),
),
Text(
"Нравится",
),
],
),
Spacer(),
Padding(
padding: EdgeInsets.only(right: 4),
child: Icon(Icons.share_outlined),
),
],
),
],
),
),
],
),
);
}
Function onTapBack(BuildContext context) {
return () {
onTapArrowLeft(context);
};
}
onTapArrowLeft(BuildContext context) {
GoRouter.of(context).pop();
}
_buildMenu(BuildContext context, FeedStateLoaded state) {
return Container(
padding: EdgeInsets.all(12),
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(12)),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: Offset(0, 3),
),
],
),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
ScrollItem(title: 'Все'),
ScrollItem(title: 'Рецепты'),
ScrollItem(title: 'Диеты'),
ScrollItem(title: 'Планы'),
ScrollItem(title: 'Записи'),
],
),
),
);
}
}

View File

@@ -0,0 +1,16 @@
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:eatvio_app/features/feed/services/feed_service.dart';
class FeedRepository {
final FeedService feedService;
FeedRepository({required this.feedService});
Future<List<FeedBlogPostModel>> getFeedBlogPostList() async {
try {
return await feedService.getBlocPostList();
} catch (e) {
rethrow;
}
}
}

View File

@@ -0,0 +1,13 @@
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
import 'package:retrofit/retrofit.dart';
part 'feed_service.g.dart';
@RestApi()
abstract class FeedService {
factory FeedService(Dio dio, {String baseUrl}) = _FeedService;
@GET('/feed/index')
Future<List<FeedBlogPostModel>> getBlocPostList();
}

View File

@@ -0,0 +1,80 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'feed_service.dart';
// **************************************************************************
// RetrofitGenerator
// **************************************************************************
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers
class _FeedService implements FeedService {
_FeedService(
this._dio, {
this.baseUrl,
});
final Dio _dio;
String? baseUrl;
@override
Future<List<FeedBlogPostModel>> getBlocPostList() async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _result = await _dio
.fetch<List<dynamic>>(_setStreamType<List<FeedBlogPostModel>>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/feed/index',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
))));
var value = _result.data!
.map((dynamic i) =>
FeedBlogPostModel.fromJson(i as Map<String, dynamic>))
.toList();
return value;
}
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
if (T != dynamic &&
!(requestOptions.responseType == ResponseType.bytes ||
requestOptions.responseType == ResponseType.stream)) {
if (T == String) {
requestOptions.responseType = ResponseType.plain;
} else {
requestOptions.responseType = ResponseType.json;
}
}
return requestOptions;
}
String _combineBaseUrls(
String dioBaseUrl,
String? baseUrl,
) {
if (baseUrl == null || baseUrl.trim().isEmpty) {
return dioBaseUrl;
}
final url = Uri.parse(baseUrl);
if (url.isAbsolute) {
return url.toString();
}
return Uri.parse(dioBaseUrl).resolveUri(url).toString();
}
}