fix: fix analyzer

This commit is contained in:
mso7nueh
2024-11-20 11:15:20 +03:00
parent f230833c4e
commit 1ac956b448
10 changed files with 472 additions and 5 deletions

View File

@@ -1,4 +1,3 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

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

View File

@@ -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>(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<String, dynamic> 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<String, dynamic> 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<ProductModerationModel> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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;
}

View File

@@ -0,0 +1,27 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'product_moderation_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$ProductModerationModelImpl _$$ProductModerationModelImplFromJson(
Map<String, dynamic> 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<String, dynamic> _$$ProductModerationModelImplToJson(
_$ProductModerationModelImpl instance) =>
<String, dynamic>{
'name': instance.name,
'energy_on_100gr': instance.energy,
'proteins_on_100gr': instance.proteins,
'fats_on_100gr': instance.fats,
'carbohydrates_on_100gr': instance.carbohydrates,
};

View File

@@ -140,4 +140,20 @@ class DiaryCubit extends Cubit<DiaryState> {
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,
);
}
}

View File

@@ -1023,7 +1023,10 @@ class _DiaryScreenState extends State<DiaryScreen> {
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: GlossaryModerationRequestModalWidget(productName: productNameController.text),
child: GlossaryModerationRequestModalWidget(
productName: productNameController.text,
diaryCubit: diaryCubit,
),
),
);
}

View File

@@ -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<GlossaryModerationRequestModalWidget> createState() => _GlossaryModerationRequestModalWidgetState();
}
enum GlossaryState { alert, addNewProduct, finish }
enum GlossaryState { alert, addNewProduct, success }
class _GlossaryModerationRequestModalWidgetState extends State<GlossaryModerationRequestModalWidget> {
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<GlossaryModeratio
);
}
_success() {
return Padding(
padding: EdgeInsets.all(16),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Продукт успешно отправлен\nна модерацию',
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFF323F4B),
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 16),
Lottie.asset(
'assets/lottie_animations/success.json',
width: 160,
height: 160,
),
const SizedBox(height: 16),
InkWell(
onTap: () {
Navigator.of(context).pop();
},
borderRadius: BorderRadius.circular(20),
child: Ink(
decoration: BoxDecoration(
color: appTheme.blueA400,
borderRadius: BorderRadius.circular(20),
),
child: Container(
padding: EdgeInsets.all(16),
alignment: Alignment.center,
child: Text(
'Закрыть',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500,
),
),
),
),
),
const SizedBox(height: 16),
],
),
);
}
_addNewGlossaryProduct() {
return Padding(
padding: const EdgeInsets.all(16),
@@ -163,12 +224,16 @@ class _GlossaryModerationRequestModalWidgetState extends State<GlossaryModeratio
Expanded(
child: CustomTextFormField(
hintText: 'Калории',
controller: energyController,
keyboardType: TextInputType.number,
),
),
const SizedBox(width: 8),
Expanded(
child: CustomTextFormField(
hintText: 'Белки',
controller: proteinsController,
keyboardType: TextInputType.number,
),
),
],
@@ -180,19 +245,34 @@ class _GlossaryModerationRequestModalWidgetState extends State<GlossaryModeratio
Expanded(
child: CustomTextFormField(
hintText: 'Жиры',
controller: fatsController,
keyboardType: TextInputType.number,
),
),
const SizedBox(width: 8),
Expanded(
child: CustomTextFormField(
hintText: 'Углеводы',
controller: carbohydratesController,
keyboardType: TextInputType.number,
),
),
],
),
const SizedBox(height: 12),
InkWell(
onTap: () {},
onTap: () {
widget.diaryCubit.sendProductToModeration(
name: productNameController.text,
energy: int.parse(energyController.text),
proteins: int.parse(proteinsController.text),
fats: int.parse(fatsController.text),
carbohydrates: int.parse(carbohydratesController.text),
);
setState(() {
glossaryState = GlossaryState.success;
});
},
borderRadius: BorderRadius.circular(20),
child: Ink(
padding: EdgeInsets.symmetric(horizontal: 8),

View File

@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
import 'package:eatvio_app/features/diary/models/nutrition_model.dart';
import 'package:eatvio_app/features/diary/models/product_moderation_model.dart';
import 'package:eatvio_app/features/diary/services/diary_service.dart';
class DiaryRepository {
@@ -120,4 +121,22 @@ class DiaryRepository {
// ),
);
}
Future<void> 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(),
);
}
}

View File

@@ -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<void> sendProductToModeration({
@Body() required Map<String, dynamic> data,
});
}

View File

@@ -320,6 +320,33 @@ class _DiaryService implements DiaryService {
await _dio.fetch<void>(_options);
}
@override
Future<void> sendProductToModeration(
{required Map<String, dynamic> data}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(data);
final _options = _setStreamType<void>(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<void>(_options);
}
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
if (T != dynamic &&
!(requestOptions.responseType == ResponseType.bytes ||