forked from eatvio/eatvio_app
updated error handling, consultant rating layout and complaining logic
This commit is contained in:
15
lib/features/complaining/models/complain_model.dart
Normal file
15
lib/features/complaining/models/complain_model.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'complain_model.freezed.dart';
|
||||
part 'complain_model.g.dart';
|
||||
|
||||
@freezed
|
||||
class ComplainModel with _$ComplainModel {
|
||||
|
||||
const factory ComplainModel({
|
||||
@Default(null) String? description,
|
||||
@Default([]) List<String> tags,
|
||||
}) = _ComplainModel;
|
||||
|
||||
factory ComplainModel.fromJson(Map<String, dynamic> json) => _$ComplainModelFromJson(json);
|
||||
}
|
||||
193
lib/features/complaining/models/complain_model.freezed.dart
Normal file
193
lib/features/complaining/models/complain_model.freezed.dart
Normal file
@@ -0,0 +1,193 @@
|
||||
// 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 'complain_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');
|
||||
|
||||
ComplainModel _$ComplainModelFromJson(Map<String, dynamic> json) {
|
||||
return _ComplainModel.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ComplainModel {
|
||||
String? get description => throw _privateConstructorUsedError;
|
||||
List<String> get tags => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this ComplainModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of ComplainModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$ComplainModelCopyWith<ComplainModel> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ComplainModelCopyWith<$Res> {
|
||||
factory $ComplainModelCopyWith(
|
||||
ComplainModel value, $Res Function(ComplainModel) then) =
|
||||
_$ComplainModelCopyWithImpl<$Res, ComplainModel>;
|
||||
@useResult
|
||||
$Res call({String? description, List<String> tags});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ComplainModelCopyWithImpl<$Res, $Val extends ComplainModel>
|
||||
implements $ComplainModelCopyWith<$Res> {
|
||||
_$ComplainModelCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of ComplainModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? description = freezed,
|
||||
Object? tags = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
description: freezed == description
|
||||
? _value.description
|
||||
: description // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
tags: null == tags
|
||||
? _value.tags
|
||||
: tags // ignore: cast_nullable_to_non_nullable
|
||||
as List<String>,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ComplainModelImplCopyWith<$Res>
|
||||
implements $ComplainModelCopyWith<$Res> {
|
||||
factory _$$ComplainModelImplCopyWith(
|
||||
_$ComplainModelImpl value, $Res Function(_$ComplainModelImpl) then) =
|
||||
__$$ComplainModelImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({String? description, List<String> tags});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ComplainModelImplCopyWithImpl<$Res>
|
||||
extends _$ComplainModelCopyWithImpl<$Res, _$ComplainModelImpl>
|
||||
implements _$$ComplainModelImplCopyWith<$Res> {
|
||||
__$$ComplainModelImplCopyWithImpl(
|
||||
_$ComplainModelImpl _value, $Res Function(_$ComplainModelImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of ComplainModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? description = freezed,
|
||||
Object? tags = null,
|
||||
}) {
|
||||
return _then(_$ComplainModelImpl(
|
||||
description: freezed == description
|
||||
? _value.description
|
||||
: description // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
tags: null == tags
|
||||
? _value._tags
|
||||
: tags // ignore: cast_nullable_to_non_nullable
|
||||
as List<String>,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$ComplainModelImpl implements _ComplainModel {
|
||||
const _$ComplainModelImpl(
|
||||
{this.description = null, final List<String> tags = const []})
|
||||
: _tags = tags;
|
||||
|
||||
factory _$ComplainModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$ComplainModelImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
final String? description;
|
||||
final List<String> _tags;
|
||||
@override
|
||||
@JsonKey()
|
||||
List<String> get tags {
|
||||
if (_tags is EqualUnmodifiableListView) return _tags;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_tags);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ComplainModel(description: $description, tags: $tags)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ComplainModelImpl &&
|
||||
(identical(other.description, description) ||
|
||||
other.description == description) &&
|
||||
const DeepCollectionEquality().equals(other._tags, _tags));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType, description, const DeepCollectionEquality().hash(_tags));
|
||||
|
||||
/// Create a copy of ComplainModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ComplainModelImplCopyWith<_$ComplainModelImpl> get copyWith =>
|
||||
__$$ComplainModelImplCopyWithImpl<_$ComplainModelImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$ComplainModelImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ComplainModel implements ComplainModel {
|
||||
const factory _ComplainModel(
|
||||
{final String? description,
|
||||
final List<String> tags}) = _$ComplainModelImpl;
|
||||
|
||||
factory _ComplainModel.fromJson(Map<String, dynamic> json) =
|
||||
_$ComplainModelImpl.fromJson;
|
||||
|
||||
@override
|
||||
String? get description;
|
||||
@override
|
||||
List<String> get tags;
|
||||
|
||||
/// Create a copy of ComplainModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$ComplainModelImplCopyWith<_$ComplainModelImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
21
lib/features/complaining/models/complain_model.g.dart
Normal file
21
lib/features/complaining/models/complain_model.g.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'complain_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$ComplainModelImpl _$$ComplainModelImplFromJson(Map<String, dynamic> json) =>
|
||||
_$ComplainModelImpl(
|
||||
description: json['description'] as String? ?? null,
|
||||
tags:
|
||||
(json['tags'] as List<dynamic>?)?.map((e) => e as String).toList() ??
|
||||
const [],
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ComplainModelImplToJson(_$ComplainModelImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'description': instance.description,
|
||||
'tags': instance.tags,
|
||||
};
|
||||
@@ -0,0 +1,590 @@
|
||||
import 'package:eatvio_app/core/app_router.dart';
|
||||
import 'package:eatvio_app/core/enums/complained_content.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/complaining/presentation/cubit/complaining_cubit.dart';
|
||||
import 'package:eatvio_app/features/complaining/presentation/cubit/complaining_state.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class ComplainingBottomSheet extends StatefulWidget {
|
||||
const ComplainingBottomSheet({super.key, required this.complainedContentType, this.slug, this.id});
|
||||
final ComplainedContent complainedContentType;
|
||||
final String? slug;
|
||||
final int? id;
|
||||
@override
|
||||
State<ComplainingBottomSheet> createState() => _ComplainingBottomSheetState();
|
||||
}
|
||||
|
||||
class _ComplainingBottomSheetState extends State<ComplainingBottomSheet> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => sl<ComplainingCubit>()..setContentTypeAndIdentifier(contentType: widget.complainedContentType, slug: widget.slug, id: widget.id),
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: 8, bottom: 24, left: 16, right: 16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
|
||||
),
|
||||
child: BlocBuilder<ComplainingCubit, ComplainingState>(
|
||||
builder: (context, state) {
|
||||
final category = state.category;
|
||||
if (state.wasSentSuccessfully == true) {
|
||||
return _ComplaintSentWidget();
|
||||
} else if (state.wasSentSuccessfully == false) {
|
||||
return _ComplaintFailedWidget();
|
||||
}
|
||||
if (category != null) {
|
||||
return switch (category) {
|
||||
ComplainType.spam => _SpamWidget(),
|
||||
ComplainType.lawViolation => _LawViolationWidget(),
|
||||
ComplainType.deception => _DeceptionWidget(),
|
||||
ComplainType.violenceDndHostility => _ViolenceAndHostility(),
|
||||
ComplainType.explicitImage => _ExplicitImageWidget(),
|
||||
};
|
||||
}
|
||||
return _CategoryWidget();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategoryWidget extends StatelessWidget {
|
||||
const _CategoryWidget();
|
||||
final categories = ComplainType.values;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.complaint,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
s.complaint_question,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
...List.generate(
|
||||
categories.length,
|
||||
(index) => Column(
|
||||
children: [
|
||||
_CategoryButton(
|
||||
category: categories[index],
|
||||
onTap: () {
|
||||
context.read<ComplainingCubit>().setCategory(categories[index]);
|
||||
},
|
||||
),
|
||||
if (index != categories.length - 1) SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SpamWidget extends StatelessWidget {
|
||||
const _SpamWidget();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.spam,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
s.spam_description,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
_ComplainButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ExplicitImageWidget extends StatelessWidget {
|
||||
const _ExplicitImageWidget();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.explicitImages,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
s.explicitImagesDescription,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
_ComplainButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _LawViolationWidget extends StatefulWidget {
|
||||
const _LawViolationWidget();
|
||||
|
||||
@override
|
||||
State<_LawViolationWidget> createState() => _LawViolationWidgetState();
|
||||
}
|
||||
|
||||
class _LawViolationWidgetState extends State<_LawViolationWidget> {
|
||||
final List<(bool, String)> tags = [];
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final s = S.of(context);
|
||||
if (tags.isEmpty) {
|
||||
tags.addAll([
|
||||
(false, s.alcohol),
|
||||
(false, s.drugs),
|
||||
(false, s.nicotine),
|
||||
(false, s.weapon),
|
||||
(false, s.fake_documents),
|
||||
(false, s.prostitution),
|
||||
(false, s.other),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.lawViolation,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
s.what_do_you_want_to_complaint_about,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
...tags.mapIndexed((index, element) {
|
||||
return Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
activeColor: appTheme.blueA400,
|
||||
side: BorderSide(width: 2, color: tags[index].$1 ? appTheme.blueA400 : appTheme.blueGray),
|
||||
value: element.$1,
|
||||
onChanged: (isChecked) {
|
||||
setState(() {
|
||||
if (isChecked == null) return;
|
||||
if (index == tags.length - 1 && !isChecked) {
|
||||
context.read<ComplainingCubit>().toggleDescription();
|
||||
}
|
||||
tags[index] = (isChecked, element.$2);
|
||||
final activeTags = tags.where((elem) => elem.$1).map((e) => e.$2).toList();
|
||||
context.read<ComplainingCubit>().setTags(activeTags);
|
||||
});
|
||||
},
|
||||
),
|
||||
Text(
|
||||
element.$2,
|
||||
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
if (tags.last.$1) ...[
|
||||
SizedBox(height: 12),
|
||||
CustomTextFormField(
|
||||
hintText: s.type_here_your_complaint,
|
||||
onChanged: (value) {
|
||||
context.read<ComplainingCubit>().setDescription(value);
|
||||
},
|
||||
),
|
||||
],
|
||||
SizedBox(height: 20),
|
||||
_ComplainButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ViolenceAndHostility extends StatefulWidget {
|
||||
const _ViolenceAndHostility();
|
||||
|
||||
@override
|
||||
State<_ViolenceAndHostility> createState() => _ViolenceAndHostilityState();
|
||||
}
|
||||
|
||||
class _ViolenceAndHostilityState extends State<_ViolenceAndHostility> {
|
||||
final List<(bool, String)> tags = [];
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final s = S.of(context);
|
||||
if (tags.isEmpty) {
|
||||
tags.addAll([
|
||||
(false, s.violence_against_people_or_animal),
|
||||
(false, s.hatred),
|
||||
(false, s.suicide),
|
||||
(false, s.hatred_description),
|
||||
(false, s.extremism),
|
||||
(false, s.calls_for_bullying),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.lawViolation,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
s.what_do_you_want_to_complaint_about,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
...tags.mapIndexed((index, element) {
|
||||
return Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
activeColor: appTheme.blueA400,
|
||||
side: BorderSide(width: 2, color: tags[index].$1 ? appTheme.blueA400 : appTheme.blueGray),
|
||||
value: element.$1,
|
||||
onChanged: (isChecked) {
|
||||
setState(() {
|
||||
if (isChecked == null) return;
|
||||
tags[index] = (isChecked, element.$2);
|
||||
final activeTags = tags.where((elem) => elem.$1).map((e) => e.$2).toList();
|
||||
context.read<ComplainingCubit>().setTags(activeTags);
|
||||
});
|
||||
},
|
||||
),
|
||||
Text(
|
||||
element.$2,
|
||||
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
SizedBox(height: 20),
|
||||
_ComplainButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _DeceptionWidget extends StatefulWidget {
|
||||
const _DeceptionWidget();
|
||||
|
||||
@override
|
||||
State<_DeceptionWidget> createState() => _DeceptionWidgetState();
|
||||
}
|
||||
|
||||
class _DeceptionWidgetState extends State<_DeceptionWidget> {
|
||||
final List<(bool, String)> tags = [];
|
||||
final List<String> descriptions = [];
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final s = S.of(context);
|
||||
if (tags.isEmpty && descriptions.isEmpty) {
|
||||
tags.addAll([
|
||||
(false, s.misrepresentation),
|
||||
(false, s.fraud),
|
||||
]);
|
||||
|
||||
descriptions.addAll([
|
||||
s.misrepresentation_description,
|
||||
s.fraud_description,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.lawViolation,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
s.what_do_you_want_to_complaint_about,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
...tags.mapIndexed((index, element) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Checkbox(
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
activeColor: appTheme.blueA400,
|
||||
side: BorderSide(width: 2, color: tags[index].$1 ? appTheme.blueA400 : appTheme.blueGray),
|
||||
value: element.$1,
|
||||
onChanged: (isChecked) {
|
||||
setState(() {
|
||||
if (isChecked == null) return;
|
||||
tags[index] = (isChecked, element.$2);
|
||||
final activeTags = tags.where((elem) => elem.$1).map((e) => e.$2).toList();
|
||||
context.read<ComplainingCubit>().setTags(activeTags);
|
||||
});
|
||||
},
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
element.$2,
|
||||
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
descriptions[index],
|
||||
style: TextStyles.textSSemibold.copyWith(color: appTheme.lightGray600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
SizedBox(height: 20),
|
||||
_ComplainButton(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ComplaintSentWidget extends StatelessWidget {
|
||||
const _ComplaintSentWidget();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.complaint_sent,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
s.complaint_sent_description,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
CustomOutlinedButton(
|
||||
text: s.ok,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
),
|
||||
onPressed: () {
|
||||
AppRouter.navigatorKey.currentContext?.pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ComplaintFailedWidget extends StatelessWidget {
|
||||
const _ComplaintFailedWidget();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
BottomSheetHandlerBar(),
|
||||
SizedBox(height: 20),
|
||||
Text(
|
||||
s.could_not_send_complain,
|
||||
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: MediaQuery.sizeOf(context).width * 0.7,
|
||||
child: Text(
|
||||
s.please_try_again_later,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyles.textMMedium.copyWith(color: appTheme.black),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
CustomOutlinedButton(
|
||||
text: s.ok,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
),
|
||||
onPressed: () {
|
||||
AppRouter.navigatorKey.currentContext?.pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ComplainButton extends StatelessWidget {
|
||||
const _ComplainButton();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return BlocBuilder<ComplainingCubit, ComplainingState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading) {
|
||||
return Loader();
|
||||
}
|
||||
return CustomOutlinedButton(
|
||||
text: s.send_complain,
|
||||
height: 52,
|
||||
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
|
||||
buttonStyle: ButtonStyle(
|
||||
side: WidgetStatePropertyAll(BorderSide.none),
|
||||
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
|
||||
),
|
||||
onPressed: () async {
|
||||
await context.read<ComplainingCubit>().complain();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CategoryButton extends StatelessWidget {
|
||||
const _CategoryButton({required this.category, required this.onTap});
|
||||
final ComplainType category;
|
||||
final void Function() onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Ink(
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
category.getTranslatedText(),
|
||||
style: TextStyles.textLSemibold.copyWith(color: appTheme.black),
|
||||
),
|
||||
Spacer(),
|
||||
SvgPicture.asset('assets/icons/right_arrow.svg'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum ComplainType {
|
||||
spam,
|
||||
lawViolation,
|
||||
deception,
|
||||
violenceDndHostility,
|
||||
explicitImage;
|
||||
|
||||
String getTranslatedText() => switch (this) {
|
||||
ComplainType.spam => S.current.spam,
|
||||
ComplainType.lawViolation => S.current.lawViolation,
|
||||
ComplainType.deception => S.current.deception,
|
||||
ComplainType.violenceDndHostility => S.current.violenceAndHostility,
|
||||
ComplainType.explicitImage => S.current.explicitImage,
|
||||
};
|
||||
|
||||
String getValue() => switch (this) {
|
||||
ComplainType.spam => 'spam',
|
||||
ComplainType.lawViolation => 'legalViolation',
|
||||
ComplainType.deception => 'fraud',
|
||||
ComplainType.violenceDndHostility => 'violenceAndHatred',
|
||||
ComplainType.explicitImage => 'explicitImage',
|
||||
};
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ComplainingScreen extends StatelessWidget {
|
||||
const ComplainingScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import 'package:eatvio_app/features/complaining/models/complain_model.dart';
|
||||
import 'package:eatvio_app/features/complaining/services/complaining_service.dart';
|
||||
|
||||
class ComplainingRepository {
|
||||
final ComplainingService service;
|
||||
ComplainingRepository({required this.service});
|
||||
|
||||
Future<void> sendPlanComplain({
|
||||
required String slug,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendPlanComplain(slug: slug, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sendRecipeComplain({
|
||||
required String slug,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendRecipeComplain(slug: slug, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sendBlogPostsComplain({
|
||||
required int id,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendBlogPostsComplain(id: id, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> sendProfileComplain({
|
||||
required String slug,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
try {
|
||||
service.sendProfileComplain(slug: slug, category: category, body: body);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
lib/features/complaining/services/complaining_service.dart
Normal file
39
lib/features/complaining/services/complaining_service.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/complaining/models/complain_model.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
part 'complaining_service.g.dart';
|
||||
|
||||
@RestApi()
|
||||
abstract class ComplainingService {
|
||||
factory ComplainingService(Dio dio, {String baseUrl}) = _ComplainingService;
|
||||
|
||||
@POST('/api/plans/{slug}/complain/{category}')
|
||||
Future<void> sendPlanComplain({
|
||||
@Path() required String slug,
|
||||
@Path() required String category,
|
||||
@Body() required ComplainModel body,
|
||||
});
|
||||
|
||||
@POST('/api/recipes/{slug}/complain/{category}')
|
||||
Future<void> sendRecipeComplain({
|
||||
@Path() required String slug,
|
||||
@Path() required String category,
|
||||
@Body() required ComplainModel body,
|
||||
});
|
||||
|
||||
@POST('/api/blogPosts/{id}/complain/{category}')
|
||||
Future<void> sendBlogPostsComplain({
|
||||
@Path() required int id,
|
||||
@Path() required String category,
|
||||
@Body() required ComplainModel body,
|
||||
});
|
||||
|
||||
@POST('/api/profile/{slug}/complain/{category}')
|
||||
Future<void> sendProfileComplain({
|
||||
@Path() required String slug,
|
||||
@Path() required String category,
|
||||
@Body() required ComplainModel body,
|
||||
});
|
||||
}
|
||||
|
||||
138
lib/features/complaining/services/complaining_service.g.dart
Normal file
138
lib/features/complaining/services/complaining_service.g.dart
Normal file
@@ -0,0 +1,138 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'complaining_service.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RetrofitGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers,unused_element,unnecessary_string_interpolations
|
||||
|
||||
class _ComplainingService implements ComplainingService {
|
||||
_ComplainingService(this._dio, {this.baseUrl, this.errorLogger});
|
||||
|
||||
final Dio _dio;
|
||||
|
||||
String? baseUrl;
|
||||
|
||||
final ParseErrorLogger? errorLogger;
|
||||
|
||||
@override
|
||||
Future<void> sendPlanComplain({
|
||||
required String slug,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = body;
|
||||
final _options = _setStreamType<void>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/plans/${slug}/complain/${category}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> sendRecipeComplain({
|
||||
required String slug,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = body;
|
||||
final _options = _setStreamType<void>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/recipes/${slug}/complain/${category}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> sendBlogPostsComplain({
|
||||
required int id,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = body;
|
||||
final _options = _setStreamType<void>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/blogPosts/${id}/complain/${category}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> sendProfileComplain({
|
||||
required String slug,
|
||||
required String category,
|
||||
required ComplainModel body,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = body;
|
||||
final _options = _setStreamType<void>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/profile/${slug}/complain/${category}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user