user details created

This commit is contained in:
Username1548
2024-12-25 17:51:50 +07:00
parent 0c981b0068
commit 3521a58c2f
23 changed files with 1382 additions and 220 deletions

View File

@@ -0,0 +1,41 @@
import 'dart:developer';
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
import 'package:eatvio_app/features/user_details/presentation/cubit/user_details_state.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class UserDetailsCubit extends Cubit<UserDetailsState> {
final ProfileRepository profileRepository;
UserDetailsCubit({required this.profileRepository}) : super(UserDetailsState());
void getUserDetails(String slug) async {
try {
final profileDetails = await profileRepository.getProfileDetailsBySlug(slug);
emit(state.copyWith(profileDetails: profileDetails, isLoading: false));
getChartData(slug: slug);
} catch (e) {
log(e.toString());
emit(state.copyWith(error: e.toString(), isLoading: false));
}
}
void getChartData({
String period = '1',
required String slug,
}) async {
try {
final weightPoints = await profileRepository.getWeight(period: period);
final circumferencePoints = await profileRepository.getCircumferences(period: period);
emit(
state.copyWith(
weightPoints: weightPoints,
circumferencePoints: circumferencePoints,
),
);
} catch (e, stackTrace) {
log(e.toString(), stackTrace: stackTrace);
emit(state.copyWith(error: e.toString(), isLoading: false));
}
}
}

View File

@@ -0,0 +1,17 @@
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
import 'package:eatvio_app/features/profile/models/profile_model.dart';
import 'package:eatvio_app/features/profile/models/weight_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'user_details_state.freezed.dart';
@freezed
class UserDetailsState with _$UserDetailsState {
factory UserDetailsState({
@Default(false) bool isLoading,
String? error,
ProfileDetailsModel? profileDetails,
List<WeightModel>? weightPoints,
List<CircumferenceModel>? circumferencePoints,
}) = _UserDetailsState;
}

View File

@@ -0,0 +1,278 @@
// 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 'user_details_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 _$UserDetailsState {
bool get isLoading => throw _privateConstructorUsedError;
String? get error => throw _privateConstructorUsedError;
ProfileDetailsModel? get profileDetails => throw _privateConstructorUsedError;
List<WeightModel>? get weightPoints => throw _privateConstructorUsedError;
List<CircumferenceModel>? get circumferencePoints =>
throw _privateConstructorUsedError;
/// Create a copy of UserDetailsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$UserDetailsStateCopyWith<UserDetailsState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $UserDetailsStateCopyWith<$Res> {
factory $UserDetailsStateCopyWith(
UserDetailsState value, $Res Function(UserDetailsState) then) =
_$UserDetailsStateCopyWithImpl<$Res, UserDetailsState>;
@useResult
$Res call(
{bool isLoading,
String? error,
ProfileDetailsModel? profileDetails,
List<WeightModel>? weightPoints,
List<CircumferenceModel>? circumferencePoints});
$ProfileDetailsModelCopyWith<$Res>? get profileDetails;
}
/// @nodoc
class _$UserDetailsStateCopyWithImpl<$Res, $Val extends UserDetailsState>
implements $UserDetailsStateCopyWith<$Res> {
_$UserDetailsStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of UserDetailsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? error = freezed,
Object? profileDetails = freezed,
Object? weightPoints = freezed,
Object? circumferencePoints = freezed,
}) {
return _then(_value.copyWith(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
error: freezed == error
? _value.error
: error // ignore: cast_nullable_to_non_nullable
as String?,
profileDetails: freezed == profileDetails
? _value.profileDetails
: profileDetails // ignore: cast_nullable_to_non_nullable
as ProfileDetailsModel?,
weightPoints: freezed == weightPoints
? _value.weightPoints
: weightPoints // ignore: cast_nullable_to_non_nullable
as List<WeightModel>?,
circumferencePoints: freezed == circumferencePoints
? _value.circumferencePoints
: circumferencePoints // ignore: cast_nullable_to_non_nullable
as List<CircumferenceModel>?,
) as $Val);
}
/// Create a copy of UserDetailsState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$ProfileDetailsModelCopyWith<$Res>? get profileDetails {
if (_value.profileDetails == null) {
return null;
}
return $ProfileDetailsModelCopyWith<$Res>(_value.profileDetails!, (value) {
return _then(_value.copyWith(profileDetails: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$UserDetailsStateImplCopyWith<$Res>
implements $UserDetailsStateCopyWith<$Res> {
factory _$$UserDetailsStateImplCopyWith(_$UserDetailsStateImpl value,
$Res Function(_$UserDetailsStateImpl) then) =
__$$UserDetailsStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{bool isLoading,
String? error,
ProfileDetailsModel? profileDetails,
List<WeightModel>? weightPoints,
List<CircumferenceModel>? circumferencePoints});
@override
$ProfileDetailsModelCopyWith<$Res>? get profileDetails;
}
/// @nodoc
class __$$UserDetailsStateImplCopyWithImpl<$Res>
extends _$UserDetailsStateCopyWithImpl<$Res, _$UserDetailsStateImpl>
implements _$$UserDetailsStateImplCopyWith<$Res> {
__$$UserDetailsStateImplCopyWithImpl(_$UserDetailsStateImpl _value,
$Res Function(_$UserDetailsStateImpl) _then)
: super(_value, _then);
/// Create a copy of UserDetailsState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? isLoading = null,
Object? error = freezed,
Object? profileDetails = freezed,
Object? weightPoints = freezed,
Object? circumferencePoints = freezed,
}) {
return _then(_$UserDetailsStateImpl(
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
error: freezed == error
? _value.error
: error // ignore: cast_nullable_to_non_nullable
as String?,
profileDetails: freezed == profileDetails
? _value.profileDetails
: profileDetails // ignore: cast_nullable_to_non_nullable
as ProfileDetailsModel?,
weightPoints: freezed == weightPoints
? _value._weightPoints
: weightPoints // ignore: cast_nullable_to_non_nullable
as List<WeightModel>?,
circumferencePoints: freezed == circumferencePoints
? _value._circumferencePoints
: circumferencePoints // ignore: cast_nullable_to_non_nullable
as List<CircumferenceModel>?,
));
}
}
/// @nodoc
class _$UserDetailsStateImpl implements _UserDetailsState {
_$UserDetailsStateImpl(
{this.isLoading = false,
this.error,
this.profileDetails,
final List<WeightModel>? weightPoints,
final List<CircumferenceModel>? circumferencePoints})
: _weightPoints = weightPoints,
_circumferencePoints = circumferencePoints;
@override
@JsonKey()
final bool isLoading;
@override
final String? error;
@override
final ProfileDetailsModel? profileDetails;
final List<WeightModel>? _weightPoints;
@override
List<WeightModel>? get weightPoints {
final value = _weightPoints;
if (value == null) return null;
if (_weightPoints is EqualUnmodifiableListView) return _weightPoints;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
final List<CircumferenceModel>? _circumferencePoints;
@override
List<CircumferenceModel>? get circumferencePoints {
final value = _circumferencePoints;
if (value == null) return null;
if (_circumferencePoints is EqualUnmodifiableListView)
return _circumferencePoints;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override
String toString() {
return 'UserDetailsState(isLoading: $isLoading, error: $error, profileDetails: $profileDetails, weightPoints: $weightPoints, circumferencePoints: $circumferencePoints)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UserDetailsStateImpl &&
(identical(other.isLoading, isLoading) ||
other.isLoading == isLoading) &&
(identical(other.error, error) || other.error == error) &&
(identical(other.profileDetails, profileDetails) ||
other.profileDetails == profileDetails) &&
const DeepCollectionEquality()
.equals(other._weightPoints, _weightPoints) &&
const DeepCollectionEquality()
.equals(other._circumferencePoints, _circumferencePoints));
}
@override
int get hashCode => Object.hash(
runtimeType,
isLoading,
error,
profileDetails,
const DeepCollectionEquality().hash(_weightPoints),
const DeepCollectionEquality().hash(_circumferencePoints));
/// Create a copy of UserDetailsState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$UserDetailsStateImplCopyWith<_$UserDetailsStateImpl> get copyWith =>
__$$UserDetailsStateImplCopyWithImpl<_$UserDetailsStateImpl>(
this, _$identity);
}
abstract class _UserDetailsState implements UserDetailsState {
factory _UserDetailsState(
{final bool isLoading,
final String? error,
final ProfileDetailsModel? profileDetails,
final List<WeightModel>? weightPoints,
final List<CircumferenceModel>? circumferencePoints}) =
_$UserDetailsStateImpl;
@override
bool get isLoading;
@override
String? get error;
@override
ProfileDetailsModel? get profileDetails;
@override
List<WeightModel>? get weightPoints;
@override
List<CircumferenceModel>? get circumferencePoints;
/// Create a copy of UserDetailsState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$UserDetailsStateImplCopyWith<_$UserDetailsStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}