diet creation page

This commit is contained in:
Username1548
2024-11-20 15:28:48 +07:00
parent 92c1bb1a91
commit c292f3a767
19 changed files with 1036 additions and 38 deletions

View File

@@ -0,0 +1,35 @@
import 'dart:io';
import 'package:eatvio_app/core/image_compressing/image_compress_utility.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'create_diet_model.freezed.dart';
@freezed
class CreateDietModel with _$CreateDietModel{
const CreateDietModel._();
const factory CreateDietModel({
String? name,
String? details,
String? state,
int? duration,
List<String>? type,
File? 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 ImageCompressUtility.compressFile(image!) : null,
};
Map<String, dynamic> toDailyScheduleCreationJson() => {
'daily_schedule': dailySchedule,
};
}

View File

@@ -0,0 +1,299 @@
// 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 'create_diet_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');
/// @nodoc
mixin _$CreateDietModel {
String? get name => throw _privateConstructorUsedError;
String? get details => throw _privateConstructorUsedError;
String? get state => throw _privateConstructorUsedError;
int? get duration => throw _privateConstructorUsedError;
List<String>? get type => throw _privateConstructorUsedError;
File? get image => throw _privateConstructorUsedError;
List<List<List<DailySchedule>>>? get dailySchedule =>
throw _privateConstructorUsedError;
/// Create a copy of CreateDietModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CreateDietModelCopyWith<CreateDietModel> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CreateDietModelCopyWith<$Res> {
factory $CreateDietModelCopyWith(
CreateDietModel value, $Res Function(CreateDietModel) then) =
_$CreateDietModelCopyWithImpl<$Res, CreateDietModel>;
@useResult
$Res call(
{String? name,
String? details,
String? state,
int? duration,
List<String>? type,
File? image,
List<List<List<DailySchedule>>>? dailySchedule});
}
/// @nodoc
class _$CreateDietModelCopyWithImpl<$Res, $Val extends CreateDietModel>
implements $CreateDietModelCopyWith<$Res> {
_$CreateDietModelCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CreateDietModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = freezed,
Object? details = freezed,
Object? state = freezed,
Object? duration = freezed,
Object? type = freezed,
Object? image = freezed,
Object? dailySchedule = freezed,
}) {
return _then(_value.copyWith(
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
details: freezed == details
? _value.details
: details // ignore: cast_nullable_to_non_nullable
as String?,
state: freezed == state
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as String?,
duration: freezed == duration
? _value.duration
: duration // ignore: cast_nullable_to_non_nullable
as int?,
type: freezed == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as List<String>?,
image: freezed == image
? _value.image
: image // ignore: cast_nullable_to_non_nullable
as File?,
dailySchedule: freezed == dailySchedule
? _value.dailySchedule
: dailySchedule // ignore: cast_nullable_to_non_nullable
as List<List<List<DailySchedule>>>?,
) as $Val);
}
}
/// @nodoc
abstract class _$$CreateDietModelImplCopyWith<$Res>
implements $CreateDietModelCopyWith<$Res> {
factory _$$CreateDietModelImplCopyWith(_$CreateDietModelImpl value,
$Res Function(_$CreateDietModelImpl) then) =
__$$CreateDietModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{String? name,
String? details,
String? state,
int? duration,
List<String>? type,
File? image,
List<List<List<DailySchedule>>>? dailySchedule});
}
/// @nodoc
class __$$CreateDietModelImplCopyWithImpl<$Res>
extends _$CreateDietModelCopyWithImpl<$Res, _$CreateDietModelImpl>
implements _$$CreateDietModelImplCopyWith<$Res> {
__$$CreateDietModelImplCopyWithImpl(
_$CreateDietModelImpl _value, $Res Function(_$CreateDietModelImpl) _then)
: super(_value, _then);
/// Create a copy of CreateDietModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = freezed,
Object? details = freezed,
Object? state = freezed,
Object? duration = freezed,
Object? type = freezed,
Object? image = freezed,
Object? dailySchedule = freezed,
}) {
return _then(_$CreateDietModelImpl(
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
details: freezed == details
? _value.details
: details // ignore: cast_nullable_to_non_nullable
as String?,
state: freezed == state
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as String?,
duration: freezed == duration
? _value.duration
: duration // ignore: cast_nullable_to_non_nullable
as int?,
type: freezed == type
? _value._type
: type // ignore: cast_nullable_to_non_nullable
as List<String>?,
image: freezed == image
? _value.image
: image // ignore: cast_nullable_to_non_nullable
as File?,
dailySchedule: freezed == dailySchedule
? _value._dailySchedule
: dailySchedule // ignore: cast_nullable_to_non_nullable
as List<List<List<DailySchedule>>>?,
));
}
}
/// @nodoc
class _$CreateDietModelImpl extends _CreateDietModel {
const _$CreateDietModelImpl(
{this.name,
this.details,
this.state,
this.duration,
final List<String>? type,
this.image,
final List<List<List<DailySchedule>>>? dailySchedule})
: _type = type,
_dailySchedule = dailySchedule,
super._();
@override
final String? name;
@override
final String? details;
@override
final String? state;
@override
final int? duration;
final List<String>? _type;
@override
List<String>? get type {
final value = _type;
if (value == null) return null;
if (_type is EqualUnmodifiableListView) return _type;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override
final File? image;
final List<List<List<DailySchedule>>>? _dailySchedule;
@override
List<List<List<DailySchedule>>>? get dailySchedule {
final value = _dailySchedule;
if (value == null) return null;
if (_dailySchedule is EqualUnmodifiableListView) return _dailySchedule;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override
String toString() {
return 'CreateDietModel(name: $name, details: $details, state: $state, duration: $duration, type: $type, image: $image, dailySchedule: $dailySchedule)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CreateDietModelImpl &&
(identical(other.name, name) || other.name == name) &&
(identical(other.details, details) || other.details == details) &&
(identical(other.state, state) || other.state == state) &&
(identical(other.duration, duration) ||
other.duration == duration) &&
const DeepCollectionEquality().equals(other._type, _type) &&
(identical(other.image, image) || other.image == image) &&
const DeepCollectionEquality()
.equals(other._dailySchedule, _dailySchedule));
}
@override
int get hashCode => Object.hash(
runtimeType,
name,
details,
state,
duration,
const DeepCollectionEquality().hash(_type),
image,
const DeepCollectionEquality().hash(_dailySchedule));
/// Create a copy of CreateDietModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CreateDietModelImplCopyWith<_$CreateDietModelImpl> get copyWith =>
__$$CreateDietModelImplCopyWithImpl<_$CreateDietModelImpl>(
this, _$identity);
}
abstract class _CreateDietModel extends CreateDietModel {
const factory _CreateDietModel(
{final String? name,
final String? details,
final String? state,
final int? duration,
final List<String>? type,
final File? image,
final List<List<List<DailySchedule>>>? dailySchedule}) =
_$CreateDietModelImpl;
const _CreateDietModel._() : super._();
@override
String? get name;
@override
String? get details;
@override
String? get state;
@override
int? get duration;
@override
List<String>? get type;
@override
File? get image;
@override
List<List<List<DailySchedule>>>? get dailySchedule;
/// Create a copy of CreateDietModel
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CreateDietModelImplCopyWith<_$CreateDietModelImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,12 @@
import 'package:flutter/widgets.dart';
class CreateDietScreen extends StatelessWidget {
static const name = 'createDietScreen';
static const path = '/create-diet-screen';
const CreateDietScreen({super.key});
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}

View File

@@ -0,0 +1,37 @@
import 'dart:io';
import 'package:eatvio_app/features/create_diet/presentation/cubit/create_diet_state.dart';
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CreateDietCubit extends Cubit<CreateDietState> {
CreateDietCubit() : super(CreateDietState.initial());
void setDetails(String text) {
emit(state.copyWith(dietData: state.dietData.copyWith(details: text)));
}
void setName(String name) {
emit(state.copyWith(dietData: state.dietData.copyWith(name: name)));
}
void setDuration(int duration) {
emit(state.copyWith(dietData: state.dietData.copyWith(duration: duration)));
}
void setImage(File image) {
emit(state.copyWith(dietData: state.dietData.copyWith(image: image)));
}
void setDailySchedule(List<List<List<DailySchedule>>> dailySchedule) {
emit(state.copyWith(dietData: state.dietData.copyWith(dailySchedule: dailySchedule)));
}
void setDietState(String dietState) {
emit(state.copyWith(dietData: state.dietData.copyWith(state: dietState)));
}
void setDietType(List<String> type) {
emit(state.copyWith(dietData: state.dietData.copyWith(type: type)));
}
}

View File

@@ -0,0 +1,15 @@
import 'package:eatvio_app/features/create_diet/models/create_diet_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'create_diet_state.freezed.dart';
@freezed
class CreateDietState with _$CreateDietState {
const factory CreateDietState({
required bool isLoading,
required String? errorMessage,
required CreateDietModel dietData,
}) = _CreateDietState;
factory CreateDietState.initial() => CreateDietState(isLoading: false, errorMessage: null, dietData: CreateDietModel());
}

View File

@@ -0,0 +1,201 @@
// 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 'create_diet_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 _$CreateDietState {
bool get isLoading => throw _privateConstructorUsedError;
String? get errorMessage => throw _privateConstructorUsedError;
CreateDietModel get dietData => throw _privateConstructorUsedError;
/// Create a copy of CreateDietState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$CreateDietStateCopyWith<CreateDietState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CreateDietStateCopyWith<$Res> {
factory $CreateDietStateCopyWith(
CreateDietState value, $Res Function(CreateDietState) then) =
_$CreateDietStateCopyWithImpl<$Res, CreateDietState>;
@useResult
$Res call({bool isLoading, String? errorMessage, CreateDietModel dietData});
$CreateDietModelCopyWith<$Res> get dietData;
}
/// @nodoc
class _$CreateDietStateCopyWithImpl<$Res, $Val extends CreateDietState>
implements $CreateDietStateCopyWith<$Res> {
_$CreateDietStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of CreateDietState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? errorMessage = freezed,
Object? dietData = null,
}) {
return _then(_value.copyWith(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
errorMessage: freezed == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String?,
dietData: null == dietData
? _value.dietData
: dietData // ignore: cast_nullable_to_non_nullable
as CreateDietModel,
) as $Val);
}
/// Create a copy of CreateDietState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$CreateDietModelCopyWith<$Res> get dietData {
return $CreateDietModelCopyWith<$Res>(_value.dietData, (value) {
return _then(_value.copyWith(dietData: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$CreateDietStateImplCopyWith<$Res>
implements $CreateDietStateCopyWith<$Res> {
factory _$$CreateDietStateImplCopyWith(_$CreateDietStateImpl value,
$Res Function(_$CreateDietStateImpl) then) =
__$$CreateDietStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool isLoading, String? errorMessage, CreateDietModel dietData});
@override
$CreateDietModelCopyWith<$Res> get dietData;
}
/// @nodoc
class __$$CreateDietStateImplCopyWithImpl<$Res>
extends _$CreateDietStateCopyWithImpl<$Res, _$CreateDietStateImpl>
implements _$$CreateDietStateImplCopyWith<$Res> {
__$$CreateDietStateImplCopyWithImpl(
_$CreateDietStateImpl _value, $Res Function(_$CreateDietStateImpl) _then)
: super(_value, _then);
/// Create a copy of CreateDietState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? errorMessage = freezed,
Object? dietData = null,
}) {
return _then(_$CreateDietStateImpl(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
errorMessage: freezed == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String?,
dietData: null == dietData
? _value.dietData
: dietData // ignore: cast_nullable_to_non_nullable
as CreateDietModel,
));
}
}
/// @nodoc
class _$CreateDietStateImpl implements _CreateDietState {
const _$CreateDietStateImpl(
{required this.isLoading,
required this.errorMessage,
required this.dietData});
@override
final bool isLoading;
@override
final String? errorMessage;
@override
final CreateDietModel dietData;
@override
String toString() {
return 'CreateDietState(isLoading: $isLoading, errorMessage: $errorMessage, dietData: $dietData)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CreateDietStateImpl &&
(identical(other.isLoading, isLoading) ||
other.isLoading == isLoading) &&
(identical(other.errorMessage, errorMessage) ||
other.errorMessage == errorMessage) &&
(identical(other.dietData, dietData) ||
other.dietData == dietData));
}
@override
int get hashCode =>
Object.hash(runtimeType, isLoading, errorMessage, dietData);
/// Create a copy of CreateDietState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$CreateDietStateImplCopyWith<_$CreateDietStateImpl> get copyWith =>
__$$CreateDietStateImplCopyWithImpl<_$CreateDietStateImpl>(
this, _$identity);
}
abstract class _CreateDietState implements CreateDietState {
const factory _CreateDietState(
{required final bool isLoading,
required final String? errorMessage,
required final CreateDietModel dietData}) = _$CreateDietStateImpl;
@override
bool get isLoading;
@override
String? get errorMessage;
@override
CreateDietModel get dietData;
/// Create a copy of CreateDietState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$CreateDietStateImplCopyWith<_$CreateDietStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,12 @@
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
part 'create_diet_service.g.dart';
@RestApi()
abstract class CreateDietService {
factory CreateDietService(Dio dio, {String baseUrl}) = _CreateDietService;
}

View File

@@ -0,0 +1,53 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'create_diet_service.dart';
// **************************************************************************
// RetrofitGenerator
// **************************************************************************
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers,unused_element,unnecessary_string_interpolations
class _CreateDietService implements CreateDietService {
_CreateDietService(
this._dio, {
this.baseUrl,
this.errorLogger,
});
final Dio _dio;
String? baseUrl;
final ParseErrorLogger? errorLogger;
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();
}
}