updated error handling, consultant rating layout and complaining logic

This commit is contained in:
Username1548
2025-02-28 19:18:01 +07:00
parent e5b293db79
commit 0cdd40102f
86 changed files with 3853 additions and 279 deletions

View File

@@ -0,0 +1,79 @@
import 'dart:developer';
import 'package:eatvio_app/core/enums/complained_content.dart';
import 'package:eatvio_app/features/complaining/presentation/complaining_bottom_sheet.dart';
import 'package:eatvio_app/features/complaining/presentation/cubit/complaining_state.dart';
import 'package:eatvio_app/features/complaining/repositories/complaining_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ComplainingCubit extends Cubit<ComplainingState> {
final ComplainingRepository repository;
ComplainingCubit({required this.repository}) : super(ComplainingState());
void setContentTypeAndIdentifier({required ComplainedContent contentType, int? id, String? slug}) {
emit(state.copyWith(contentType: contentType, contentId: id, contentSlug: slug));
}
void setCategory(ComplainType category) {
emit(state.copyWith(category: category));
}
void setTags(List<String> tags) {
emit(state.copyWith.complainInfo(tags: tags));
}
void toggleDescription() {
if (state.complainInfo.description != null) {
emit(state.copyWith.complainInfo(description: null));
} else {
emit(state.copyWith.complainInfo(description: ''));
}
}
void setDescription(String description) {
emit(state.copyWith.complainInfo(description: description));
}
Future<void> complain() async {
try {
final category = state.category;
final id = state.contentId;
final slug = state.contentSlug;
final contentType = state.contentType;
if (category != null && contentType != null) {
switch (contentType) {
case ComplainedContent.diet:
emit(state.copyWith(wasSentSuccessfully: true));
return;
case ComplainedContent.plan:
if (slug != null) {
await repository.sendPlanComplain(slug: slug, category: category.getValue(), body: state.complainInfo);
emit(state.copyWith(wasSentSuccessfully: true));
return;
}
case ComplainedContent.recipe:
if (slug != null) {
await repository.sendRecipeComplain(slug: slug, category: category.getValue(), body: state.complainInfo);
emit(state.copyWith(wasSentSuccessfully: true));
return;
}
case ComplainedContent.profile:
if (slug != null) {
await repository.sendProfileComplain(slug: slug, category: category.getValue(), body: state.complainInfo);
emit(state.copyWith(wasSentSuccessfully: true));
return;
}
case ComplainedContent.posts:
if (id != null) {
await repository.sendBlogPostsComplain(id: id, category: category.getValue(), body: state.complainInfo);
emit(state.copyWith(wasSentSuccessfully: true));
return;
}
}
}
} catch (e, st) {
log(e.toString(), stackTrace: st);
}
emit(state.copyWith(wasSentSuccessfully: false));
}
}

View File

@@ -0,0 +1,20 @@
import 'package:eatvio_app/core/enums/complained_content.dart';
import 'package:eatvio_app/features/complaining/models/complain_model.dart';
import 'package:eatvio_app/features/complaining/presentation/complaining_bottom_sheet.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'complaining_state.freezed.dart';
@freezed
class ComplainingState with _$ComplainingState {
factory ComplainingState({
@Default(false) bool isLoading,
@Default(null) bool? wasSentSuccessfully,
@Default(null) ComplainType? category,
@Default(null) ComplainedContent? contentType,
@Default(null) int? contentId,
@Default(null) String? contentSlug,
@Default(ComplainModel()) ComplainModel complainInfo,
}) = _ComplainingState;
}

View File

@@ -0,0 +1,298 @@
// 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 'complaining_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 _$ComplainingState {
bool get isLoading => throw _privateConstructorUsedError;
bool? get wasSentSuccessfully => throw _privateConstructorUsedError;
ComplainType? get category => throw _privateConstructorUsedError;
ComplainedContent? get contentType => throw _privateConstructorUsedError;
int? get contentId => throw _privateConstructorUsedError;
String? get contentSlug => throw _privateConstructorUsedError;
ComplainModel get complainInfo => throw _privateConstructorUsedError;
/// Create a copy of ComplainingState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$ComplainingStateCopyWith<ComplainingState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ComplainingStateCopyWith<$Res> {
factory $ComplainingStateCopyWith(
ComplainingState value, $Res Function(ComplainingState) then) =
_$ComplainingStateCopyWithImpl<$Res, ComplainingState>;
@useResult
$Res call(
{bool isLoading,
bool? wasSentSuccessfully,
ComplainType? category,
ComplainedContent? contentType,
int? contentId,
String? contentSlug,
ComplainModel complainInfo});
$ComplainModelCopyWith<$Res> get complainInfo;
}
/// @nodoc
class _$ComplainingStateCopyWithImpl<$Res, $Val extends ComplainingState>
implements $ComplainingStateCopyWith<$Res> {
_$ComplainingStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of ComplainingState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? wasSentSuccessfully = freezed,
Object? category = freezed,
Object? contentType = freezed,
Object? contentId = freezed,
Object? contentSlug = freezed,
Object? complainInfo = null,
}) {
return _then(_value.copyWith(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
wasSentSuccessfully: freezed == wasSentSuccessfully
? _value.wasSentSuccessfully
: wasSentSuccessfully // ignore: cast_nullable_to_non_nullable
as bool?,
category: freezed == category
? _value.category
: category // ignore: cast_nullable_to_non_nullable
as ComplainType?,
contentType: freezed == contentType
? _value.contentType
: contentType // ignore: cast_nullable_to_non_nullable
as ComplainedContent?,
contentId: freezed == contentId
? _value.contentId
: contentId // ignore: cast_nullable_to_non_nullable
as int?,
contentSlug: freezed == contentSlug
? _value.contentSlug
: contentSlug // ignore: cast_nullable_to_non_nullable
as String?,
complainInfo: null == complainInfo
? _value.complainInfo
: complainInfo // ignore: cast_nullable_to_non_nullable
as ComplainModel,
) as $Val);
}
/// Create a copy of ComplainingState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ComplainModelCopyWith<$Res> get complainInfo {
return $ComplainModelCopyWith<$Res>(_value.complainInfo, (value) {
return _then(_value.copyWith(complainInfo: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$ComplainingStateImplCopyWith<$Res>
implements $ComplainingStateCopyWith<$Res> {
factory _$$ComplainingStateImplCopyWith(_$ComplainingStateImpl value,
$Res Function(_$ComplainingStateImpl) then) =
__$$ComplainingStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{bool isLoading,
bool? wasSentSuccessfully,
ComplainType? category,
ComplainedContent? contentType,
int? contentId,
String? contentSlug,
ComplainModel complainInfo});
@override
$ComplainModelCopyWith<$Res> get complainInfo;
}
/// @nodoc
class __$$ComplainingStateImplCopyWithImpl<$Res>
extends _$ComplainingStateCopyWithImpl<$Res, _$ComplainingStateImpl>
implements _$$ComplainingStateImplCopyWith<$Res> {
__$$ComplainingStateImplCopyWithImpl(_$ComplainingStateImpl _value,
$Res Function(_$ComplainingStateImpl) _then)
: super(_value, _then);
/// Create a copy of ComplainingState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? wasSentSuccessfully = freezed,
Object? category = freezed,
Object? contentType = freezed,
Object? contentId = freezed,
Object? contentSlug = freezed,
Object? complainInfo = null,
}) {
return _then(_$ComplainingStateImpl(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
wasSentSuccessfully: freezed == wasSentSuccessfully
? _value.wasSentSuccessfully
: wasSentSuccessfully // ignore: cast_nullable_to_non_nullable
as bool?,
category: freezed == category
? _value.category
: category // ignore: cast_nullable_to_non_nullable
as ComplainType?,
contentType: freezed == contentType
? _value.contentType
: contentType // ignore: cast_nullable_to_non_nullable
as ComplainedContent?,
contentId: freezed == contentId
? _value.contentId
: contentId // ignore: cast_nullable_to_non_nullable
as int?,
contentSlug: freezed == contentSlug
? _value.contentSlug
: contentSlug // ignore: cast_nullable_to_non_nullable
as String?,
complainInfo: null == complainInfo
? _value.complainInfo
: complainInfo // ignore: cast_nullable_to_non_nullable
as ComplainModel,
));
}
}
/// @nodoc
class _$ComplainingStateImpl implements _ComplainingState {
_$ComplainingStateImpl(
{this.isLoading = false,
this.wasSentSuccessfully = null,
this.category = null,
this.contentType = null,
this.contentId = null,
this.contentSlug = null,
this.complainInfo = const ComplainModel()});
@override
@JsonKey()
final bool isLoading;
@override
@JsonKey()
final bool? wasSentSuccessfully;
@override
@JsonKey()
final ComplainType? category;
@override
@JsonKey()
final ComplainedContent? contentType;
@override
@JsonKey()
final int? contentId;
@override
@JsonKey()
final String? contentSlug;
@override
@JsonKey()
final ComplainModel complainInfo;
@override
String toString() {
return 'ComplainingState(isLoading: $isLoading, wasSentSuccessfully: $wasSentSuccessfully, category: $category, contentType: $contentType, contentId: $contentId, contentSlug: $contentSlug, complainInfo: $complainInfo)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ComplainingStateImpl &&
(identical(other.isLoading, isLoading) ||
other.isLoading == isLoading) &&
(identical(other.wasSentSuccessfully, wasSentSuccessfully) ||
other.wasSentSuccessfully == wasSentSuccessfully) &&
(identical(other.category, category) ||
other.category == category) &&
(identical(other.contentType, contentType) ||
other.contentType == contentType) &&
(identical(other.contentId, contentId) ||
other.contentId == contentId) &&
(identical(other.contentSlug, contentSlug) ||
other.contentSlug == contentSlug) &&
(identical(other.complainInfo, complainInfo) ||
other.complainInfo == complainInfo));
}
@override
int get hashCode => Object.hash(runtimeType, isLoading, wasSentSuccessfully,
category, contentType, contentId, contentSlug, complainInfo);
/// Create a copy of ComplainingState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$ComplainingStateImplCopyWith<_$ComplainingStateImpl> get copyWith =>
__$$ComplainingStateImplCopyWithImpl<_$ComplainingStateImpl>(
this, _$identity);
}
abstract class _ComplainingState implements ComplainingState {
factory _ComplainingState(
{final bool isLoading,
final bool? wasSentSuccessfully,
final ComplainType? category,
final ComplainedContent? contentType,
final int? contentId,
final String? contentSlug,
final ComplainModel complainInfo}) = _$ComplainingStateImpl;
@override
bool get isLoading;
@override
bool? get wasSentSuccessfully;
@override
ComplainType? get category;
@override
ComplainedContent? get contentType;
@override
int? get contentId;
@override
String? get contentSlug;
@override
ComplainModel get complainInfo;
/// Create a copy of ComplainingState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$ComplainingStateImplCopyWith<_$ComplainingStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}