From 1ac956b4481ed3bb84526e0c9f5264dbc4e7e3e0 Mon Sep 17 00:00:00 2001 From: mso7nueh Date: Wed, 20 Nov 2024 11:15:20 +0300 Subject: [PATCH] fix: fix analyzer --- .../gradle/wrapper/gradle-wrapper.properties | 1 - .../models/product_moderation_model.dart | 21 ++ .../product_moderation_model.freezed.dart | 270 ++++++++++++++++++ .../models/product_moderation_model.g.dart | 27 ++ .../diary/presentation/bloc/diary_cubit.dart | 16 ++ .../presentation/pages/diary_screen.dart | 5 +- ...ssary_moderation_request_modal_widget.dart | 86 +++++- .../diary/repositories/diary_repository.dart | 19 ++ .../diary/services/diary_service.dart | 5 + .../diary/services/diary_service.g.dart | 27 ++ 10 files changed, 472 insertions(+), 5 deletions(-) create mode 100644 lib/features/diary/models/product_moderation_model.dart create mode 100644 lib/features/diary/models/product_moderation_model.freezed.dart create mode 100644 lib/features/diary/models/product_moderation_model.g.dart diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 5841cc1f..2496707b 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,3 @@ -#Fri Jun 23 08:50:38 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/lib/features/diary/models/product_moderation_model.dart b/lib/features/diary/models/product_moderation_model.dart new file mode 100644 index 00000000..c28ffe64 --- /dev/null +++ b/lib/features/diary/models/product_moderation_model.dart @@ -0,0 +1,21 @@ +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'product_moderation_model.freezed.dart'; +part 'product_moderation_model.g.dart'; + +@freezed +class ProductModerationModel with _$ProductModerationModel { + const factory ProductModerationModel({ + required String name, + @JsonKey(name: 'energy_on_100gr') + required int energy, + @JsonKey(name: 'proteins_on_100gr') + required int proteins, + @JsonKey(name: 'fats_on_100gr') + required int fats, + @JsonKey(name: 'carbohydrates_on_100gr') + required int carbohydrates, + }) = _ProductModerationModel; + + factory ProductModerationModel.fromJson(Map json) => _$ProductModerationModelFromJson(json); +} diff --git a/lib/features/diary/models/product_moderation_model.freezed.dart b/lib/features/diary/models/product_moderation_model.freezed.dart new file mode 100644 index 00000000..9566e207 --- /dev/null +++ b/lib/features/diary/models/product_moderation_model.freezed.dart @@ -0,0 +1,270 @@ +// 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 'product_moderation_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +ProductModerationModel _$ProductModerationModelFromJson( + Map json) { + return _ProductModerationModel.fromJson(json); +} + +/// @nodoc +mixin _$ProductModerationModel { + String get name => throw _privateConstructorUsedError; + @JsonKey(name: 'energy_on_100gr') + int get energy => throw _privateConstructorUsedError; + @JsonKey(name: 'proteins_on_100gr') + int get proteins => throw _privateConstructorUsedError; + @JsonKey(name: 'fats_on_100gr') + int get fats => throw _privateConstructorUsedError; + @JsonKey(name: 'carbohydrates_on_100gr') + int get carbohydrates => throw _privateConstructorUsedError; + + /// Serializes this ProductModerationModel to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of ProductModerationModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $ProductModerationModelCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ProductModerationModelCopyWith<$Res> { + factory $ProductModerationModelCopyWith(ProductModerationModel value, + $Res Function(ProductModerationModel) then) = + _$ProductModerationModelCopyWithImpl<$Res, ProductModerationModel>; + @useResult + $Res call( + {String name, + @JsonKey(name: 'energy_on_100gr') int energy, + @JsonKey(name: 'proteins_on_100gr') int proteins, + @JsonKey(name: 'fats_on_100gr') int fats, + @JsonKey(name: 'carbohydrates_on_100gr') int carbohydrates}); +} + +/// @nodoc +class _$ProductModerationModelCopyWithImpl<$Res, + $Val extends ProductModerationModel> + implements $ProductModerationModelCopyWith<$Res> { + _$ProductModerationModelCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of ProductModerationModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? energy = null, + Object? proteins = null, + Object? fats = null, + Object? carbohydrates = null, + }) { + return _then(_value.copyWith( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + energy: null == energy + ? _value.energy + : energy // ignore: cast_nullable_to_non_nullable + as int, + proteins: null == proteins + ? _value.proteins + : proteins // ignore: cast_nullable_to_non_nullable + as int, + fats: null == fats + ? _value.fats + : fats // ignore: cast_nullable_to_non_nullable + as int, + carbohydrates: null == carbohydrates + ? _value.carbohydrates + : carbohydrates // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$ProductModerationModelImplCopyWith<$Res> + implements $ProductModerationModelCopyWith<$Res> { + factory _$$ProductModerationModelImplCopyWith( + _$ProductModerationModelImpl value, + $Res Function(_$ProductModerationModelImpl) then) = + __$$ProductModerationModelImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String name, + @JsonKey(name: 'energy_on_100gr') int energy, + @JsonKey(name: 'proteins_on_100gr') int proteins, + @JsonKey(name: 'fats_on_100gr') int fats, + @JsonKey(name: 'carbohydrates_on_100gr') int carbohydrates}); +} + +/// @nodoc +class __$$ProductModerationModelImplCopyWithImpl<$Res> + extends _$ProductModerationModelCopyWithImpl<$Res, + _$ProductModerationModelImpl> + implements _$$ProductModerationModelImplCopyWith<$Res> { + __$$ProductModerationModelImplCopyWithImpl( + _$ProductModerationModelImpl _value, + $Res Function(_$ProductModerationModelImpl) _then) + : super(_value, _then); + + /// Create a copy of ProductModerationModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? name = null, + Object? energy = null, + Object? proteins = null, + Object? fats = null, + Object? carbohydrates = null, + }) { + return _then(_$ProductModerationModelImpl( + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + energy: null == energy + ? _value.energy + : energy // ignore: cast_nullable_to_non_nullable + as int, + proteins: null == proteins + ? _value.proteins + : proteins // ignore: cast_nullable_to_non_nullable + as int, + fats: null == fats + ? _value.fats + : fats // ignore: cast_nullable_to_non_nullable + as int, + carbohydrates: null == carbohydrates + ? _value.carbohydrates + : carbohydrates // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$ProductModerationModelImpl implements _ProductModerationModel { + const _$ProductModerationModelImpl( + {required this.name, + @JsonKey(name: 'energy_on_100gr') required this.energy, + @JsonKey(name: 'proteins_on_100gr') required this.proteins, + @JsonKey(name: 'fats_on_100gr') required this.fats, + @JsonKey(name: 'carbohydrates_on_100gr') required this.carbohydrates}); + + factory _$ProductModerationModelImpl.fromJson(Map json) => + _$$ProductModerationModelImplFromJson(json); + + @override + final String name; + @override + @JsonKey(name: 'energy_on_100gr') + final int energy; + @override + @JsonKey(name: 'proteins_on_100gr') + final int proteins; + @override + @JsonKey(name: 'fats_on_100gr') + final int fats; + @override + @JsonKey(name: 'carbohydrates_on_100gr') + final int carbohydrates; + + @override + String toString() { + return 'ProductModerationModel(name: $name, energy: $energy, proteins: $proteins, fats: $fats, carbohydrates: $carbohydrates)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$ProductModerationModelImpl && + (identical(other.name, name) || other.name == name) && + (identical(other.energy, energy) || other.energy == energy) && + (identical(other.proteins, proteins) || + other.proteins == proteins) && + (identical(other.fats, fats) || other.fats == fats) && + (identical(other.carbohydrates, carbohydrates) || + other.carbohydrates == carbohydrates)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, name, energy, proteins, fats, carbohydrates); + + /// Create a copy of ProductModerationModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$ProductModerationModelImplCopyWith<_$ProductModerationModelImpl> + get copyWith => __$$ProductModerationModelImplCopyWithImpl< + _$ProductModerationModelImpl>(this, _$identity); + + @override + Map toJson() { + return _$$ProductModerationModelImplToJson( + this, + ); + } +} + +abstract class _ProductModerationModel implements ProductModerationModel { + const factory _ProductModerationModel( + {required final String name, + @JsonKey(name: 'energy_on_100gr') required final int energy, + @JsonKey(name: 'proteins_on_100gr') required final int proteins, + @JsonKey(name: 'fats_on_100gr') required final int fats, + @JsonKey(name: 'carbohydrates_on_100gr') + required final int carbohydrates}) = _$ProductModerationModelImpl; + + factory _ProductModerationModel.fromJson(Map json) = + _$ProductModerationModelImpl.fromJson; + + @override + String get name; + @override + @JsonKey(name: 'energy_on_100gr') + int get energy; + @override + @JsonKey(name: 'proteins_on_100gr') + int get proteins; + @override + @JsonKey(name: 'fats_on_100gr') + int get fats; + @override + @JsonKey(name: 'carbohydrates_on_100gr') + int get carbohydrates; + + /// Create a copy of ProductModerationModel + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$ProductModerationModelImplCopyWith<_$ProductModerationModelImpl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/lib/features/diary/models/product_moderation_model.g.dart b/lib/features/diary/models/product_moderation_model.g.dart new file mode 100644 index 00000000..2199a5f6 --- /dev/null +++ b/lib/features/diary/models/product_moderation_model.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'product_moderation_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$ProductModerationModelImpl _$$ProductModerationModelImplFromJson( + Map json) => + _$ProductModerationModelImpl( + name: json['name'] as String, + energy: (json['energy_on_100gr'] as num).toInt(), + proteins: (json['proteins_on_100gr'] as num).toInt(), + fats: (json['fats_on_100gr'] as num).toInt(), + carbohydrates: (json['carbohydrates_on_100gr'] as num).toInt(), + ); + +Map _$$ProductModerationModelImplToJson( + _$ProductModerationModelImpl instance) => + { + 'name': instance.name, + 'energy_on_100gr': instance.energy, + 'proteins_on_100gr': instance.proteins, + 'fats_on_100gr': instance.fats, + 'carbohydrates_on_100gr': instance.carbohydrates, + }; diff --git a/lib/features/diary/presentation/bloc/diary_cubit.dart b/lib/features/diary/presentation/bloc/diary_cubit.dart index 0c243ac4..976d16e6 100644 --- a/lib/features/diary/presentation/bloc/diary_cubit.dart +++ b/lib/features/diary/presentation/bloc/diary_cubit.dart @@ -140,4 +140,20 @@ class DiaryCubit extends Cubit { currentSelectedSatietyRating = value; emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: currentSelectedSatietyRating)); } + + sendProductToModeration({ + required String name, + required int energy, + required int proteins, + required int fats, + required int carbohydrates, + }) async { + return await diaryRepository.sendProductToModeration( + name: name, + energy: energy, + proteins: proteins, + fats: fats, + carbohydrates: carbohydrates, + ); + } } diff --git a/lib/features/diary/presentation/pages/diary_screen.dart b/lib/features/diary/presentation/pages/diary_screen.dart index 94d1eff5..6c19ceb6 100644 --- a/lib/features/diary/presentation/pages/diary_screen.dart +++ b/lib/features/diary/presentation/pages/diary_screen.dart @@ -1023,7 +1023,10 @@ class _DiaryScreenState extends State { padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom, ), - child: GlossaryModerationRequestModalWidget(productName: productNameController.text), + child: GlossaryModerationRequestModalWidget( + productName: productNameController.text, + diaryCubit: diaryCubit, + ), ), ); } diff --git a/lib/features/diary/presentation/widgets/glossary_moderation_request_modal_widget.dart b/lib/features/diary/presentation/widgets/glossary_moderation_request_modal_widget.dart index 956a9113..57896321 100644 --- a/lib/features/diary/presentation/widgets/glossary_moderation_request_modal_widget.dart +++ b/lib/features/diary/presentation/widgets/glossary_moderation_request_modal_widget.dart @@ -1,29 +1,38 @@ +import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart'; import 'package:eatvio_app/theme/theme_helper.dart'; import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:flutter/material.dart'; +import 'package:lottie/lottie.dart'; class GlossaryModerationRequestModalWidget extends StatefulWidget { + final DiaryCubit diaryCubit; final String productName; const GlossaryModerationRequestModalWidget({ super.key, - required this.productName, + required this.productName, required this.diaryCubit, }); @override State createState() => _GlossaryModerationRequestModalWidgetState(); } -enum GlossaryState { alert, addNewProduct, finish } +enum GlossaryState { alert, addNewProduct, success } class _GlossaryModerationRequestModalWidgetState extends State { GlossaryState glossaryState = GlossaryState.alert; final productNameController = TextEditingController(); + final energyController = TextEditingController(); + final proteinsController = TextEditingController(); + final fatsController = TextEditingController(); + final carbohydratesController = TextEditingController(); @override Widget build(BuildContext context) { if (glossaryState == GlossaryState.alert) { return _alert(); + } else if (glossaryState == GlossaryState.success) { + return _success(); } else { return _addNewGlossaryProduct(); } @@ -126,6 +135,58 @@ class _GlossaryModerationRequestModalWidgetState extends State sendProductToModeration({ + required String name, + required int energy, + required int proteins, + required int fats, + required int carbohydrates, + }) async { + return await diaryService.sendProductToModeration( + data: ProductModerationModel( + name: name, + energy: energy, + proteins: proteins, + fats: fats, + carbohydrates: carbohydrates, + ).toJson(), + ); + } } diff --git a/lib/features/diary/services/diary_service.dart b/lib/features/diary/services/diary_service.dart index d4edd406..4ff8b2e1 100644 --- a/lib/features/diary/services/diary_service.dart +++ b/lib/features/diary/services/diary_service.dart @@ -70,4 +70,9 @@ abstract class DiaryService { @Path('diary_id') required int diaryId, // @Body() required FinishDiaryDayModel finishDiaryDayModel, }); + + @POST('/api/diary/product_nutritional_values/sendToModeration') + Future sendProductToModeration({ + @Body() required Map data, + }); } diff --git a/lib/features/diary/services/diary_service.g.dart b/lib/features/diary/services/diary_service.g.dart index 816c7fb5..b9327c5f 100644 --- a/lib/features/diary/services/diary_service.g.dart +++ b/lib/features/diary/services/diary_service.g.dart @@ -320,6 +320,33 @@ class _DiaryService implements DiaryService { await _dio.fetch(_options); } + @override + Future sendProductToModeration( + {required Map data}) async { + final _extra = {}; + final queryParameters = {}; + final _headers = {}; + final _data = {}; + _data.addAll(data); + final _options = _setStreamType(Options( + method: 'POST', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/api/diary/product_nutritional_values/sendToModeration', + queryParameters: queryParameters, + data: _data, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); + await _dio.fetch(_options); + } + RequestOptions _setStreamType(RequestOptions requestOptions) { if (T != dynamic && !(requestOptions.responseType == ResponseType.bytes ||