Files
eatvio_app/lib/features/create_plan/models/create_plan_model.dart

37 lines
1.3 KiB
Dart

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/plan_pagination_model.dart';
import 'package:flutter_image_compress/flutter_image_compress.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'create_plan_model.freezed.dart';
@freezed
class CreatePlanModel with _$CreatePlanModel {
const CreatePlanModel._();
const factory CreatePlanModel({
String? name,
String? details,
String? state,
int? duration,
required List<bool> type,
XFile? image,
required List<PacketOptions> options,
}) = _CreatePlanModel;
Future<Map<String, dynamic>> toCreationJson() async => {
'name': name,
'duration': duration,
'state': state,
'type': type,
'description_md': details,
'image': image != null ? await MultipartFile.fromFile((await ImageCompressUtility.compressFile(File(image!.path))).path, filename: image!.name) : null,
};
Map<String, dynamic> toOptionCreationJson() => {'packet1_options': options[0]};
Map<String, dynamic> toOptionsCreationJson() => {'packet1_options': options[0], 'packet2_options': options[1], 'packet3_options': options[2]};
}