forked from eatvio/eatvio_app
added plan pagination and updated plans creation screen
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/image_compressing/image_compress_utility.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
@@ -17,21 +13,8 @@ class CreateDietModel with _$CreateDietModel {
|
||||
String? details,
|
||||
String? state,
|
||||
int? duration,
|
||||
required List<bool> type,
|
||||
required Map<String, bool> type,
|
||||
XFile? image,
|
||||
List<List<List<DailySchedule>>>? dailySchedule,
|
||||
}) = _CreateDietModel;
|
||||
|
||||
Future<Map<String, dynamic>> toCreationJson() async => {
|
||||
'name': name,
|
||||
'duration': duration,
|
||||
'state': state,
|
||||
'type': type,
|
||||
'details': details,
|
||||
'image': image != null ? await MultipartFile.fromFile((await ImageCompressUtility.compressFile(File(image!.path))).path, filename: image!.name) : null,
|
||||
};
|
||||
|
||||
Map<String, dynamic> toDailyScheduleCreationJson() => {
|
||||
'daily_schedule': dailySchedule?.map((element) => element.map((element) => element.map((element) => element.toJson()).toList()).toList()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ mixin _$CreateDietModel {
|
||||
String? get details => throw _privateConstructorUsedError;
|
||||
String? get state => throw _privateConstructorUsedError;
|
||||
int? get duration => throw _privateConstructorUsedError;
|
||||
List<bool> get type => throw _privateConstructorUsedError;
|
||||
Map<String, bool> get type => throw _privateConstructorUsedError;
|
||||
XFile? get image => throw _privateConstructorUsedError;
|
||||
List<List<List<DailySchedule>>>? get dailySchedule =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -43,7 +43,7 @@ abstract class $CreateDietModelCopyWith<$Res> {
|
||||
String? details,
|
||||
String? state,
|
||||
int? duration,
|
||||
List<bool> type,
|
||||
Map<String, bool> type,
|
||||
XFile? image,
|
||||
List<List<List<DailySchedule>>>? dailySchedule});
|
||||
}
|
||||
@@ -91,7 +91,7 @@ class _$CreateDietModelCopyWithImpl<$Res, $Val extends CreateDietModel>
|
||||
type: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as List<bool>,
|
||||
as Map<String, bool>,
|
||||
image: freezed == image
|
||||
? _value.image
|
||||
: image // ignore: cast_nullable_to_non_nullable
|
||||
@@ -117,7 +117,7 @@ abstract class _$$CreateDietModelImplCopyWith<$Res>
|
||||
String? details,
|
||||
String? state,
|
||||
int? duration,
|
||||
List<bool> type,
|
||||
Map<String, bool> type,
|
||||
XFile? image,
|
||||
List<List<List<DailySchedule>>>? dailySchedule});
|
||||
}
|
||||
@@ -163,7 +163,7 @@ class __$$CreateDietModelImplCopyWithImpl<$Res>
|
||||
type: null == type
|
||||
? _value._type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as List<bool>,
|
||||
as Map<String, bool>,
|
||||
image: freezed == image
|
||||
? _value.image
|
||||
: image // ignore: cast_nullable_to_non_nullable
|
||||
@@ -184,7 +184,7 @@ class _$CreateDietModelImpl extends _CreateDietModel {
|
||||
this.details,
|
||||
this.state,
|
||||
this.duration,
|
||||
required final List<bool> type,
|
||||
required final Map<String, bool> type,
|
||||
this.image,
|
||||
final List<List<List<DailySchedule>>>? dailySchedule})
|
||||
: _type = type,
|
||||
@@ -199,12 +199,12 @@ class _$CreateDietModelImpl extends _CreateDietModel {
|
||||
final String? state;
|
||||
@override
|
||||
final int? duration;
|
||||
final List<bool> _type;
|
||||
final Map<String, bool> _type;
|
||||
@override
|
||||
List<bool> get type {
|
||||
if (_type is EqualUnmodifiableListView) return _type;
|
||||
Map<String, bool> get type {
|
||||
if (_type is EqualUnmodifiableMapView) return _type;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_type);
|
||||
return EqualUnmodifiableMapView(_type);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -267,7 +267,7 @@ abstract class _CreateDietModel extends CreateDietModel {
|
||||
final String? details,
|
||||
final String? state,
|
||||
final int? duration,
|
||||
required final List<bool> type,
|
||||
required final Map<String, bool> type,
|
||||
final XFile? image,
|
||||
final List<List<List<DailySchedule>>>? dailySchedule}) =
|
||||
_$CreateDietModelImpl;
|
||||
@@ -282,7 +282,7 @@ abstract class _CreateDietModel extends CreateDietModel {
|
||||
@override
|
||||
int? get duration;
|
||||
@override
|
||||
List<bool> get type;
|
||||
Map<String, bool> get type;
|
||||
@override
|
||||
XFile? get image;
|
||||
@override
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/const.dart';
|
||||
import 'package:eatvio_app/core/image_compressing/image_compress_utility.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_state.dart';
|
||||
import 'package:eatvio_app/features/create_diet/repositories/create_diet_repository.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
@@ -89,7 +93,9 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
emit(state.copyWith(dietStateIndex: index, dietData: state.dietData.copyWith(state: _dietStateValues[index])));
|
||||
}
|
||||
|
||||
void setDietType(List<bool> type) {
|
||||
void setDietType({required String key, required bool value}) {
|
||||
final type = Map<String, bool>.from(state.dietData.type);
|
||||
type[key] = value;
|
||||
emit(state.copyWith(dietData: state.dietData.copyWith(type: type)));
|
||||
}
|
||||
|
||||
@@ -248,19 +254,24 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
}
|
||||
|
||||
Future<void> publishDiet() async {
|
||||
// бек судя по всему с багом
|
||||
// try {
|
||||
// final model = await state.dietData.toCreationJson();
|
||||
// model.remove('image');
|
||||
// final dailySchedule = await state.dietData.toDailyScheduleCreationJson();
|
||||
// final dio = sl<Dio>();
|
||||
// final qwe = await dio.post('/api/diets/create', data: model);
|
||||
// // final diet = await createDietRepository.createDiet(model: model);
|
||||
// // final qwe2 = createDietRepository.createDietDailySchedule(id: diet.id, model: dailySchedule);
|
||||
// } catch (e, stackTrace) {
|
||||
// print(e);
|
||||
// print('---------------------------------');
|
||||
// print(stackTrace);
|
||||
// }
|
||||
try {
|
||||
// final types = jsonEncode(state.dietData.type);
|
||||
// if (state.dietData.image == null) {
|
||||
// return;
|
||||
// }
|
||||
// final image = await ImageCompressUtility.compressFile(File(state.dietData.image!.path));
|
||||
// final diet = await createDietRepository.createDiet(
|
||||
// name: state.dietData.name,
|
||||
// duration: state.dietData.duration,
|
||||
// state: state.dietData.state,
|
||||
// image: image,
|
||||
// type: types,
|
||||
// details: state.dietData.details,
|
||||
// );
|
||||
} catch (e, stackTrace) {
|
||||
print(e);
|
||||
print('---------------------------------');
|
||||
print(stackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:eatvio_app/core/const.dart';
|
||||
import 'package:eatvio_app/features/create_diet/models/create_diet_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
@@ -6,14 +7,20 @@ part 'create_diet_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class CreateDietState with _$CreateDietState {
|
||||
const factory CreateDietState({
|
||||
const factory CreateDietState({
|
||||
required bool isLoading,
|
||||
required String? errorMessage,
|
||||
required CreateDietModel dietData,
|
||||
List<List<DailySchedule>>? copiedDay,
|
||||
required CreateDietModel dietData,
|
||||
List<List<DailySchedule>>? copiedDay,
|
||||
int? durationIndex,
|
||||
int? dietStateIndex,
|
||||
}) = _CreateDietState;
|
||||
|
||||
factory CreateDietState.initial() => CreateDietState(isLoading: false, errorMessage: null, dietData: CreateDietModel(type: [false, false, false, false]));
|
||||
factory CreateDietState.initial() => CreateDietState(
|
||||
isLoading: false,
|
||||
errorMessage: null,
|
||||
dietData: CreateDietModel(
|
||||
type: Map.fromIterable(typeValues, value: (element) => false),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:eatvio_app/core/const.dart';
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_cubit.dart';
|
||||
@@ -18,15 +19,11 @@ class _DietTypeChoiceWidgetState extends State<DietTypeChoiceWidget> {
|
||||
final List<(String, String)> choiceContent = [];
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
// const List<String> typeValues = ['veg', 'light', 'carb', 'meat'];
|
||||
super.didChangeDependencies();
|
||||
final s = S.of(context);
|
||||
if (choiceContent.isEmpty) {
|
||||
choiceContent.add(
|
||||
(
|
||||
'assets/icons/meat2.svg',
|
||||
s.meat,
|
||||
),
|
||||
);
|
||||
|
||||
choiceContent.add(
|
||||
(
|
||||
'assets/icons/broccoli.svg',
|
||||
@@ -35,14 +32,20 @@ class _DietTypeChoiceWidgetState extends State<DietTypeChoiceWidget> {
|
||||
);
|
||||
choiceContent.add(
|
||||
(
|
||||
'assets/icons/bread.svg',
|
||||
s.carb_type,
|
||||
'assets/icons/cocktail.svg',
|
||||
s.light_type,
|
||||
),
|
||||
);
|
||||
choiceContent.add(
|
||||
(
|
||||
'assets/icons/cocktail.svg',
|
||||
s.light_type,
|
||||
'assets/icons/bread.svg',
|
||||
s.carb_type,
|
||||
),
|
||||
);
|
||||
choiceContent.add(
|
||||
(
|
||||
'assets/icons/meat2.svg',
|
||||
s.meat,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -58,18 +61,18 @@ class _DietTypeChoiceWidgetState extends State<DietTypeChoiceWidget> {
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
final dietTypes = [...state.dietData.type];
|
||||
dietTypes[index] = !dietTypes[index];
|
||||
context.read<CreateDietCubit>().setDietType(dietTypes);
|
||||
final key = typeValues[index];
|
||||
final value = !(state.dietData.type[key] ?? true);
|
||||
context.read<CreateDietCubit>().setDietType(key: key, value: value);
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: index == 3 ? 0 : 4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
color: state.dietData.type[index] ? appTheme.cardBackground : appTheme.whiteA700,
|
||||
color: state.dietData.type[typeValues[index]] == true ? appTheme.cardBackground : appTheme.whiteA700,
|
||||
border: Border.all(
|
||||
width: 1,
|
||||
color: state.dietData.type[index] ? appTheme.blueA400 : appTheme.lightGray00,
|
||||
color: state.dietData.type[typeValues[index]] == true ? appTheme.blueA400 : appTheme.lightGray00,
|
||||
),
|
||||
),
|
||||
height: 80,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/features/create_diet/services/create_diet_service.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
|
||||
@@ -6,10 +8,20 @@ class CreateDietRepository {
|
||||
CreateDietRepository({required this.createDietService});
|
||||
|
||||
Future<Diet> createDiet({
|
||||
required Map<String, dynamic> model,
|
||||
String? name,
|
||||
int? duration,
|
||||
String? state,
|
||||
String? type,
|
||||
String? details,
|
||||
File? image,
|
||||
}) {
|
||||
return createDietService.createDiet(
|
||||
model: model,
|
||||
name: name,
|
||||
duration: duration,
|
||||
state: state,
|
||||
type: type,
|
||||
details: details,
|
||||
image: image,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
@@ -11,7 +13,12 @@ abstract class CreateDietService {
|
||||
@POST('/api/diets/create')
|
||||
@MultiPart()
|
||||
Future<Diet> createDiet({
|
||||
@Body() required Map<String, dynamic> model,
|
||||
@Part(name: 'name') String? name,
|
||||
@Part(name: 'duration') int? duration,
|
||||
@Part(name: 'state') String? state,
|
||||
@Part(name: 'type') String? type,
|
||||
@Part(name: 'details') String? details,
|
||||
@Part(name: 'image') File? image,
|
||||
});
|
||||
|
||||
@POST('/api/diets/create/{id}/daily_schedule')
|
||||
|
||||
@@ -22,12 +22,60 @@ class _CreateDietService implements CreateDietService {
|
||||
final ParseErrorLogger? errorLogger;
|
||||
|
||||
@override
|
||||
Future<Diet> createDiet({required Map<String, dynamic> model}) async {
|
||||
Future<Diet> createDiet({
|
||||
String? name,
|
||||
int? duration,
|
||||
String? state,
|
||||
String? type,
|
||||
String? details,
|
||||
File? image,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = <String, dynamic>{};
|
||||
_data.addAll(model);
|
||||
final _data = FormData();
|
||||
if (name != null) {
|
||||
_data.fields.add(MapEntry(
|
||||
'name',
|
||||
name,
|
||||
));
|
||||
}
|
||||
if (duration != null) {
|
||||
_data.fields.add(MapEntry(
|
||||
'duration',
|
||||
duration.toString(),
|
||||
));
|
||||
}
|
||||
if (state != null) {
|
||||
_data.fields.add(MapEntry(
|
||||
'state',
|
||||
state,
|
||||
));
|
||||
}
|
||||
if (type != null) {
|
||||
_data.fields.add(MapEntry(
|
||||
'type',
|
||||
type,
|
||||
));
|
||||
}
|
||||
if (details != null) {
|
||||
_data.fields.add(MapEntry(
|
||||
'details',
|
||||
details,
|
||||
));
|
||||
}
|
||||
if (image != null) {
|
||||
if (image != null) {
|
||||
_data.files.add(MapEntry(
|
||||
'image',
|
||||
MultipartFile.fromFileSync(
|
||||
image.path,
|
||||
filename: image.path.split(Platform.pathSeparator).last,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
final _options = _setStreamType<Diet>(Options(
|
||||
method: 'POST',
|
||||
headers: _headers,
|
||||
|
||||
Reference in New Issue
Block a user