feat(profile): add profile model

This commit is contained in:
mso7nueh
2024-08-26 16:41:19 +03:00
parent 0a2eae6824
commit ec19861eb2
9 changed files with 479 additions and 88 deletions

View File

@@ -1,24 +1,38 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'profile_model.freezed.dart';
part 'profile_model.g.dart';
@freezed
class Profile with _$Profile {
const factory Profile({
class ProfileModel with _$ProfileModel {
const factory ProfileModel({
@JsonKey(name: "user") required User user,
@JsonKey(name: "chartPoints") required List<dynamic> chartPoints,
@JsonKey(name: "userDetails") required UserDetails userDetails,
@JsonKey(name: "circumferences") required List<dynamic> circumferences,
@JsonKey(name: "circumferences") required List<Circumference> circumferences,
@JsonKey(name: "finishedPlans") required List<dynamic> finishedPlans,
@JsonKey(name: "rejectedPlans") required List<dynamic> rejectedPlans,
@JsonKey(name: "startedPlan") required List<dynamic> startedPlan,
@JsonKey(name: "paidPlan") required List<dynamic> paidPlan,
@JsonKey(name: "requestedPlan") required List<dynamic> requestedPlan,
@JsonKey(name: "initedPlan") required List<dynamic> initedPlan,
}) = _Profile;
}) = _ProfileModel;
factory Profile.fromJson(Map<String, Object?> json) => _$ProfileFromJson(json);
factory ProfileModel.fromJson(Map<String, dynamic> json) => _$ProfileModelFromJson(json);
}
@freezed
class Circumference with _$Circumference {
const factory Circumference({
@JsonKey(name: "id") required int id,
@JsonKey(name: "user_id") required int userId,
@JsonKey(name: "chest_circumference") required int chestCircumference,
@JsonKey(name: "waist_circumference") required int waistCircumference,
@JsonKey(name: "hip_circumference") required int hipCircumference,
@JsonKey(name: "created_at") required DateTime createdAt,
@JsonKey(name: "updated_at") required DateTime updatedAt,
}) = _Circumference;
factory Circumference.fromJson(Map<String, dynamic> json) => _$CircumferenceFromJson(json);
}
@freezed
@@ -41,7 +55,7 @@ class User with _$User {
@JsonKey(name: "detailz") required UserDetails detailz,
}) = _User;
factory User.fromJson(Map<String, Object?> json) => _$UserFromJson(json);
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}
@freezed
@@ -78,5 +92,5 @@ class UserDetails with _$UserDetails {
@JsonKey(name: "activity_coefficient") required double activityCoefficient,
}) = _UserDetails;
factory UserDetails.fromJson(Map<String, Object?> json) => _$UserDetailsFromJson(json);
factory UserDetails.fromJson(Map<String, dynamic> json) => _$UserDetailsFromJson(json);
}

View File

@@ -14,12 +14,12 @@ 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');
Profile _$ProfileFromJson(Map<String, dynamic> json) {
return _Profile.fromJson(json);
ProfileModel _$ProfileModelFromJson(Map<String, dynamic> json) {
return _ProfileModel.fromJson(json);
}
/// @nodoc
mixin _$Profile {
mixin _$ProfileModel {
@JsonKey(name: "user")
User get user => throw _privateConstructorUsedError;
@JsonKey(name: "chartPoints")
@@ -27,7 +27,7 @@ mixin _$Profile {
@JsonKey(name: "userDetails")
UserDetails get userDetails => throw _privateConstructorUsedError;
@JsonKey(name: "circumferences")
List<dynamic> get circumferences => throw _privateConstructorUsedError;
List<Circumference> get circumferences => throw _privateConstructorUsedError;
@JsonKey(name: "finishedPlans")
List<dynamic> get finishedPlans => throw _privateConstructorUsedError;
@JsonKey(name: "rejectedPlans")
@@ -43,19 +43,21 @@ mixin _$Profile {
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ProfileCopyWith<Profile> get copyWith => throw _privateConstructorUsedError;
$ProfileModelCopyWith<ProfileModel> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ProfileCopyWith<$Res> {
factory $ProfileCopyWith(Profile value, $Res Function(Profile) then) =
_$ProfileCopyWithImpl<$Res, Profile>;
abstract class $ProfileModelCopyWith<$Res> {
factory $ProfileModelCopyWith(
ProfileModel value, $Res Function(ProfileModel) then) =
_$ProfileModelCopyWithImpl<$Res, ProfileModel>;
@useResult
$Res call(
{@JsonKey(name: "user") User user,
@JsonKey(name: "chartPoints") List<dynamic> chartPoints,
@JsonKey(name: "userDetails") UserDetails userDetails,
@JsonKey(name: "circumferences") List<dynamic> circumferences,
@JsonKey(name: "circumferences") List<Circumference> circumferences,
@JsonKey(name: "finishedPlans") List<dynamic> finishedPlans,
@JsonKey(name: "rejectedPlans") List<dynamic> rejectedPlans,
@JsonKey(name: "startedPlan") List<dynamic> startedPlan,
@@ -68,9 +70,9 @@ abstract class $ProfileCopyWith<$Res> {
}
/// @nodoc
class _$ProfileCopyWithImpl<$Res, $Val extends Profile>
implements $ProfileCopyWith<$Res> {
_$ProfileCopyWithImpl(this._value, this._then);
class _$ProfileModelCopyWithImpl<$Res, $Val extends ProfileModel>
implements $ProfileModelCopyWith<$Res> {
_$ProfileModelCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
@@ -107,7 +109,7 @@ class _$ProfileCopyWithImpl<$Res, $Val extends Profile>
circumferences: null == circumferences
? _value.circumferences
: circumferences // ignore: cast_nullable_to_non_nullable
as List<dynamic>,
as List<Circumference>,
finishedPlans: null == finishedPlans
? _value.finishedPlans
: finishedPlans // ignore: cast_nullable_to_non_nullable
@@ -153,17 +155,18 @@ class _$ProfileCopyWithImpl<$Res, $Val extends Profile>
}
/// @nodoc
abstract class _$$ProfileImplCopyWith<$Res> implements $ProfileCopyWith<$Res> {
factory _$$ProfileImplCopyWith(
_$ProfileImpl value, $Res Function(_$ProfileImpl) then) =
__$$ProfileImplCopyWithImpl<$Res>;
abstract class _$$ProfileModelImplCopyWith<$Res>
implements $ProfileModelCopyWith<$Res> {
factory _$$ProfileModelImplCopyWith(
_$ProfileModelImpl value, $Res Function(_$ProfileModelImpl) then) =
__$$ProfileModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@JsonKey(name: "user") User user,
@JsonKey(name: "chartPoints") List<dynamic> chartPoints,
@JsonKey(name: "userDetails") UserDetails userDetails,
@JsonKey(name: "circumferences") List<dynamic> circumferences,
@JsonKey(name: "circumferences") List<Circumference> circumferences,
@JsonKey(name: "finishedPlans") List<dynamic> finishedPlans,
@JsonKey(name: "rejectedPlans") List<dynamic> rejectedPlans,
@JsonKey(name: "startedPlan") List<dynamic> startedPlan,
@@ -178,11 +181,11 @@ abstract class _$$ProfileImplCopyWith<$Res> implements $ProfileCopyWith<$Res> {
}
/// @nodoc
class __$$ProfileImplCopyWithImpl<$Res>
extends _$ProfileCopyWithImpl<$Res, _$ProfileImpl>
implements _$$ProfileImplCopyWith<$Res> {
__$$ProfileImplCopyWithImpl(
_$ProfileImpl _value, $Res Function(_$ProfileImpl) _then)
class __$$ProfileModelImplCopyWithImpl<$Res>
extends _$ProfileModelCopyWithImpl<$Res, _$ProfileModelImpl>
implements _$$ProfileModelImplCopyWith<$Res> {
__$$ProfileModelImplCopyWithImpl(
_$ProfileModelImpl _value, $Res Function(_$ProfileModelImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@@ -199,7 +202,7 @@ class __$$ProfileImplCopyWithImpl<$Res>
Object? requestedPlan = null,
Object? initedPlan = null,
}) {
return _then(_$ProfileImpl(
return _then(_$ProfileModelImpl(
user: null == user
? _value.user
: user // ignore: cast_nullable_to_non_nullable
@@ -215,7 +218,7 @@ class __$$ProfileImplCopyWithImpl<$Res>
circumferences: null == circumferences
? _value._circumferences
: circumferences // ignore: cast_nullable_to_non_nullable
as List<dynamic>,
as List<Circumference>,
finishedPlans: null == finishedPlans
? _value._finishedPlans
: finishedPlans // ignore: cast_nullable_to_non_nullable
@@ -246,13 +249,13 @@ class __$$ProfileImplCopyWithImpl<$Res>
/// @nodoc
@JsonSerializable()
class _$ProfileImpl implements _Profile {
const _$ProfileImpl(
class _$ProfileModelImpl implements _ProfileModel {
const _$ProfileModelImpl(
{@JsonKey(name: "user") required this.user,
@JsonKey(name: "chartPoints") required final List<dynamic> chartPoints,
@JsonKey(name: "userDetails") required this.userDetails,
@JsonKey(name: "circumferences")
required final List<dynamic> circumferences,
required final List<Circumference> circumferences,
@JsonKey(name: "finishedPlans")
required final List<dynamic> finishedPlans,
@JsonKey(name: "rejectedPlans")
@@ -271,8 +274,8 @@ class _$ProfileImpl implements _Profile {
_requestedPlan = requestedPlan,
_initedPlan = initedPlan;
factory _$ProfileImpl.fromJson(Map<String, dynamic> json) =>
_$$ProfileImplFromJson(json);
factory _$ProfileModelImpl.fromJson(Map<String, dynamic> json) =>
_$$ProfileModelImplFromJson(json);
@override
@JsonKey(name: "user")
@@ -289,10 +292,10 @@ class _$ProfileImpl implements _Profile {
@override
@JsonKey(name: "userDetails")
final UserDetails userDetails;
final List<dynamic> _circumferences;
final List<Circumference> _circumferences;
@override
@JsonKey(name: "circumferences")
List<dynamic> get circumferences {
List<Circumference> get circumferences {
if (_circumferences is EqualUnmodifiableListView) return _circumferences;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_circumferences);
@@ -354,14 +357,14 @@ class _$ProfileImpl implements _Profile {
@override
String toString() {
return 'Profile(user: $user, chartPoints: $chartPoints, userDetails: $userDetails, circumferences: $circumferences, finishedPlans: $finishedPlans, rejectedPlans: $rejectedPlans, startedPlan: $startedPlan, paidPlan: $paidPlan, requestedPlan: $requestedPlan, initedPlan: $initedPlan)';
return 'ProfileModel(user: $user, chartPoints: $chartPoints, userDetails: $userDetails, circumferences: $circumferences, finishedPlans: $finishedPlans, rejectedPlans: $rejectedPlans, startedPlan: $startedPlan, paidPlan: $paidPlan, requestedPlan: $requestedPlan, initedPlan: $initedPlan)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ProfileImpl &&
other is _$ProfileModelImpl &&
(identical(other.user, user) || other.user == user) &&
const DeepCollectionEquality()
.equals(other._chartPoints, _chartPoints) &&
@@ -400,24 +403,24 @@ class _$ProfileImpl implements _Profile {
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$ProfileImplCopyWith<_$ProfileImpl> get copyWith =>
__$$ProfileImplCopyWithImpl<_$ProfileImpl>(this, _$identity);
_$$ProfileModelImplCopyWith<_$ProfileModelImpl> get copyWith =>
__$$ProfileModelImplCopyWithImpl<_$ProfileModelImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$ProfileImplToJson(
return _$$ProfileModelImplToJson(
this,
);
}
}
abstract class _Profile implements Profile {
const factory _Profile(
abstract class _ProfileModel implements ProfileModel {
const factory _ProfileModel(
{@JsonKey(name: "user") required final User user,
@JsonKey(name: "chartPoints") required final List<dynamic> chartPoints,
@JsonKey(name: "userDetails") required final UserDetails userDetails,
@JsonKey(name: "circumferences")
required final List<dynamic> circumferences,
required final List<Circumference> circumferences,
@JsonKey(name: "finishedPlans")
required final List<dynamic> finishedPlans,
@JsonKey(name: "rejectedPlans")
@@ -427,9 +430,10 @@ abstract class _Profile implements Profile {
@JsonKey(name: "requestedPlan")
required final List<dynamic> requestedPlan,
@JsonKey(name: "initedPlan")
required final List<dynamic> initedPlan}) = _$ProfileImpl;
required final List<dynamic> initedPlan}) = _$ProfileModelImpl;
factory _Profile.fromJson(Map<String, dynamic> json) = _$ProfileImpl.fromJson;
factory _ProfileModel.fromJson(Map<String, dynamic> json) =
_$ProfileModelImpl.fromJson;
@override
@JsonKey(name: "user")
@@ -442,7 +446,7 @@ abstract class _Profile implements Profile {
UserDetails get userDetails;
@override
@JsonKey(name: "circumferences")
List<dynamic> get circumferences;
List<Circumference> get circumferences;
@override
@JsonKey(name: "finishedPlans")
List<dynamic> get finishedPlans;
@@ -463,7 +467,297 @@ abstract class _Profile implements Profile {
List<dynamic> get initedPlan;
@override
@JsonKey(ignore: true)
_$$ProfileImplCopyWith<_$ProfileImpl> get copyWith =>
_$$ProfileModelImplCopyWith<_$ProfileModelImpl> get copyWith =>
throw _privateConstructorUsedError;
}
Circumference _$CircumferenceFromJson(Map<String, dynamic> json) {
return _Circumference.fromJson(json);
}
/// @nodoc
mixin _$Circumference {
@JsonKey(name: "id")
int get id => throw _privateConstructorUsedError;
@JsonKey(name: "user_id")
int get userId => throw _privateConstructorUsedError;
@JsonKey(name: "chest_circumference")
int get chestCircumference => throw _privateConstructorUsedError;
@JsonKey(name: "waist_circumference")
int get waistCircumference => throw _privateConstructorUsedError;
@JsonKey(name: "hip_circumference")
int get hipCircumference => throw _privateConstructorUsedError;
@JsonKey(name: "created_at")
DateTime get createdAt => throw _privateConstructorUsedError;
@JsonKey(name: "updated_at")
DateTime get updatedAt => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$CircumferenceCopyWith<Circumference> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $CircumferenceCopyWith<$Res> {
factory $CircumferenceCopyWith(
Circumference value, $Res Function(Circumference) then) =
_$CircumferenceCopyWithImpl<$Res, Circumference>;
@useResult
$Res call(
{@JsonKey(name: "id") int id,
@JsonKey(name: "user_id") int userId,
@JsonKey(name: "chest_circumference") int chestCircumference,
@JsonKey(name: "waist_circumference") int waistCircumference,
@JsonKey(name: "hip_circumference") int hipCircumference,
@JsonKey(name: "created_at") DateTime createdAt,
@JsonKey(name: "updated_at") DateTime updatedAt});
}
/// @nodoc
class _$CircumferenceCopyWithImpl<$Res, $Val extends Circumference>
implements $CircumferenceCopyWith<$Res> {
_$CircumferenceCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? userId = null,
Object? chestCircumference = null,
Object? waistCircumference = null,
Object? hipCircumference = null,
Object? createdAt = null,
Object? updatedAt = null,
}) {
return _then(_value.copyWith(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as int,
userId: null == userId
? _value.userId
: userId // ignore: cast_nullable_to_non_nullable
as int,
chestCircumference: null == chestCircumference
? _value.chestCircumference
: chestCircumference // ignore: cast_nullable_to_non_nullable
as int,
waistCircumference: null == waistCircumference
? _value.waistCircumference
: waistCircumference // ignore: cast_nullable_to_non_nullable
as int,
hipCircumference: null == hipCircumference
? _value.hipCircumference
: hipCircumference // ignore: cast_nullable_to_non_nullable
as int,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
updatedAt: null == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime,
) as $Val);
}
}
/// @nodoc
abstract class _$$CircumferenceImplCopyWith<$Res>
implements $CircumferenceCopyWith<$Res> {
factory _$$CircumferenceImplCopyWith(
_$CircumferenceImpl value, $Res Function(_$CircumferenceImpl) then) =
__$$CircumferenceImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{@JsonKey(name: "id") int id,
@JsonKey(name: "user_id") int userId,
@JsonKey(name: "chest_circumference") int chestCircumference,
@JsonKey(name: "waist_circumference") int waistCircumference,
@JsonKey(name: "hip_circumference") int hipCircumference,
@JsonKey(name: "created_at") DateTime createdAt,
@JsonKey(name: "updated_at") DateTime updatedAt});
}
/// @nodoc
class __$$CircumferenceImplCopyWithImpl<$Res>
extends _$CircumferenceCopyWithImpl<$Res, _$CircumferenceImpl>
implements _$$CircumferenceImplCopyWith<$Res> {
__$$CircumferenceImplCopyWithImpl(
_$CircumferenceImpl _value, $Res Function(_$CircumferenceImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = null,
Object? userId = null,
Object? chestCircumference = null,
Object? waistCircumference = null,
Object? hipCircumference = null,
Object? createdAt = null,
Object? updatedAt = null,
}) {
return _then(_$CircumferenceImpl(
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as int,
userId: null == userId
? _value.userId
: userId // ignore: cast_nullable_to_non_nullable
as int,
chestCircumference: null == chestCircumference
? _value.chestCircumference
: chestCircumference // ignore: cast_nullable_to_non_nullable
as int,
waistCircumference: null == waistCircumference
? _value.waistCircumference
: waistCircumference // ignore: cast_nullable_to_non_nullable
as int,
hipCircumference: null == hipCircumference
? _value.hipCircumference
: hipCircumference // ignore: cast_nullable_to_non_nullable
as int,
createdAt: null == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
as DateTime,
updatedAt: null == updatedAt
? _value.updatedAt
: updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime,
));
}
}
/// @nodoc
@JsonSerializable()
class _$CircumferenceImpl implements _Circumference {
const _$CircumferenceImpl(
{@JsonKey(name: "id") required this.id,
@JsonKey(name: "user_id") required this.userId,
@JsonKey(name: "chest_circumference") required this.chestCircumference,
@JsonKey(name: "waist_circumference") required this.waistCircumference,
@JsonKey(name: "hip_circumference") required this.hipCircumference,
@JsonKey(name: "created_at") required this.createdAt,
@JsonKey(name: "updated_at") required this.updatedAt});
factory _$CircumferenceImpl.fromJson(Map<String, dynamic> json) =>
_$$CircumferenceImplFromJson(json);
@override
@JsonKey(name: "id")
final int id;
@override
@JsonKey(name: "user_id")
final int userId;
@override
@JsonKey(name: "chest_circumference")
final int chestCircumference;
@override
@JsonKey(name: "waist_circumference")
final int waistCircumference;
@override
@JsonKey(name: "hip_circumference")
final int hipCircumference;
@override
@JsonKey(name: "created_at")
final DateTime createdAt;
@override
@JsonKey(name: "updated_at")
final DateTime updatedAt;
@override
String toString() {
return 'Circumference(id: $id, userId: $userId, chestCircumference: $chestCircumference, waistCircumference: $waistCircumference, hipCircumference: $hipCircumference, createdAt: $createdAt, updatedAt: $updatedAt)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CircumferenceImpl &&
(identical(other.id, id) || other.id == id) &&
(identical(other.userId, userId) || other.userId == userId) &&
(identical(other.chestCircumference, chestCircumference) ||
other.chestCircumference == chestCircumference) &&
(identical(other.waistCircumference, waistCircumference) ||
other.waistCircumference == waistCircumference) &&
(identical(other.hipCircumference, hipCircumference) ||
other.hipCircumference == hipCircumference) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
other.updatedAt == updatedAt));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, id, userId, chestCircumference,
waistCircumference, hipCircumference, createdAt, updatedAt);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$CircumferenceImplCopyWith<_$CircumferenceImpl> get copyWith =>
__$$CircumferenceImplCopyWithImpl<_$CircumferenceImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$CircumferenceImplToJson(
this,
);
}
}
abstract class _Circumference implements Circumference {
const factory _Circumference(
{@JsonKey(name: "id") required final int id,
@JsonKey(name: "user_id") required final int userId,
@JsonKey(name: "chest_circumference")
required final int chestCircumference,
@JsonKey(name: "waist_circumference")
required final int waistCircumference,
@JsonKey(name: "hip_circumference") required final int hipCircumference,
@JsonKey(name: "created_at") required final DateTime createdAt,
@JsonKey(name: "updated_at")
required final DateTime updatedAt}) = _$CircumferenceImpl;
factory _Circumference.fromJson(Map<String, dynamic> json) =
_$CircumferenceImpl.fromJson;
@override
@JsonKey(name: "id")
int get id;
@override
@JsonKey(name: "user_id")
int get userId;
@override
@JsonKey(name: "chest_circumference")
int get chestCircumference;
@override
@JsonKey(name: "waist_circumference")
int get waistCircumference;
@override
@JsonKey(name: "hip_circumference")
int get hipCircumference;
@override
@JsonKey(name: "created_at")
DateTime get createdAt;
@override
@JsonKey(name: "updated_at")
DateTime get updatedAt;
@override
@JsonKey(ignore: true)
_$$CircumferenceImplCopyWith<_$CircumferenceImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -6,13 +6,15 @@ part of 'profile_model.dart';
// JsonSerializableGenerator
// **************************************************************************
_$ProfileImpl _$$ProfileImplFromJson(Map<String, dynamic> json) =>
_$ProfileImpl(
_$ProfileModelImpl _$$ProfileModelImplFromJson(Map<String, dynamic> json) =>
_$ProfileModelImpl(
user: User.fromJson(json['user'] as Map<String, dynamic>),
chartPoints: json['chartPoints'] as List<dynamic>,
userDetails:
UserDetails.fromJson(json['userDetails'] as Map<String, dynamic>),
circumferences: json['circumferences'] as List<dynamic>,
circumferences: (json['circumferences'] as List<dynamic>)
.map((e) => Circumference.fromJson(e as Map<String, dynamic>))
.toList(),
finishedPlans: json['finishedPlans'] as List<dynamic>,
rejectedPlans: json['rejectedPlans'] as List<dynamic>,
startedPlan: json['startedPlan'] as List<dynamic>,
@@ -21,7 +23,7 @@ _$ProfileImpl _$$ProfileImplFromJson(Map<String, dynamic> json) =>
initedPlan: json['initedPlan'] as List<dynamic>,
);
Map<String, dynamic> _$$ProfileImplToJson(_$ProfileImpl instance) =>
Map<String, dynamic> _$$ProfileModelImplToJson(_$ProfileModelImpl instance) =>
<String, dynamic>{
'user': instance.user,
'chartPoints': instance.chartPoints,
@@ -35,6 +37,28 @@ Map<String, dynamic> _$$ProfileImplToJson(_$ProfileImpl instance) =>
'initedPlan': instance.initedPlan,
};
_$CircumferenceImpl _$$CircumferenceImplFromJson(Map<String, dynamic> json) =>
_$CircumferenceImpl(
id: (json['id'] as num).toInt(),
userId: (json['user_id'] as num).toInt(),
chestCircumference: (json['chest_circumference'] as num).toInt(),
waistCircumference: (json['waist_circumference'] as num).toInt(),
hipCircumference: (json['hip_circumference'] as num).toInt(),
createdAt: DateTime.parse(json['created_at'] as String),
updatedAt: DateTime.parse(json['updated_at'] as String),
);
Map<String, dynamic> _$$CircumferenceImplToJson(_$CircumferenceImpl instance) =>
<String, dynamic>{
'id': instance.id,
'user_id': instance.userId,
'chest_circumference': instance.chestCircumference,
'waist_circumference': instance.waistCircumference,
'hip_circumference': instance.hipCircumference,
'created_at': instance.createdAt.toIso8601String(),
'updated_at': instance.updatedAt.toIso8601String(),
};
_$UserImpl _$$UserImplFromJson(Map<String, dynamic> json) => _$UserImpl(
id: (json['id'] as num).toInt(),
name: json['name'] as String,

View File

@@ -5,11 +5,26 @@ import 'package:eatvio_app/features/profile/repositories/profile_repository.dart
class ProfileCubit extends Cubit<ProfileState> {
final ProfileRepository profileRepository;
ProfileCubit({required this.profileRepository}) : super(const ProfileState.loading());
ProfileCubit({
required this.profileRepository,
}) : super(const ProfileState.loading());
getProfileBySlug(String slug) async {
try {
emit(ProfileState.loaded(profile: await profileRepository.getProfileBySlug(slug)));
emit(ProfileState.loaded(
profile: await profileRepository.getProfileBySlug(slug),
));
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
print(e);
}
}
getMyProfile() async {
try {
emit(ProfileState.loaded(
profile: await profileRepository.getMyProfile(),
));
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
print(e);

View File

@@ -10,7 +10,7 @@ abstract class ProfileState with _$ProfileState {
const factory ProfileState.loading() = ProfileStateLoading;
const factory ProfileState.loaded({
required Profile profile,
required ProfileModel profile,
}) = ProfileStateLoaded;
const factory ProfileState.error({

View File

@@ -20,7 +20,7 @@ mixin _$ProfileState {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(Profile profile) loaded,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(String errorMessage) error,
}) =>
throw _privateConstructorUsedError;
@@ -28,7 +28,7 @@ mixin _$ProfileState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(Profile profile)? loaded,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(String errorMessage)? error,
}) =>
throw _privateConstructorUsedError;
@@ -36,7 +36,7 @@ mixin _$ProfileState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(Profile profile)? loaded,
TResult Function(ProfileModel profile)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) =>
@@ -126,7 +126,7 @@ class _$ProfileStateImpl implements _ProfileState {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(Profile profile) loaded,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(String errorMessage) error,
}) {
return $default();
@@ -137,7 +137,7 @@ class _$ProfileStateImpl implements _ProfileState {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(Profile profile)? loaded,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return $default?.call();
@@ -148,7 +148,7 @@ class _$ProfileStateImpl implements _ProfileState {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(Profile profile)? loaded,
TResult Function(ProfileModel profile)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
@@ -241,7 +241,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(Profile profile) loaded,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(String errorMessage) error,
}) {
return loading();
@@ -252,7 +252,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(Profile profile)? loaded,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return loading?.call();
@@ -263,7 +263,7 @@ class _$ProfileStateLoadingImpl implements ProfileStateLoading {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(Profile profile)? loaded,
TResult Function(ProfileModel profile)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
@@ -321,9 +321,9 @@ abstract class _$$ProfileStateLoadedImplCopyWith<$Res> {
$Res Function(_$ProfileStateLoadedImpl) then) =
__$$ProfileStateLoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({Profile profile});
$Res call({ProfileModel profile});
$ProfileCopyWith<$Res> get profile;
$ProfileModelCopyWith<$Res> get profile;
}
/// @nodoc
@@ -343,14 +343,14 @@ class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
profile: null == profile
? _value.profile
: profile // ignore: cast_nullable_to_non_nullable
as Profile,
as ProfileModel,
));
}
@override
@pragma('vm:prefer-inline')
$ProfileCopyWith<$Res> get profile {
return $ProfileCopyWith<$Res>(_value.profile, (value) {
$ProfileModelCopyWith<$Res> get profile {
return $ProfileModelCopyWith<$Res>(_value.profile, (value) {
return _then(_value.copyWith(profile: value));
});
}
@@ -362,7 +362,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
const _$ProfileStateLoadedImpl({required this.profile});
@override
final Profile profile;
final ProfileModel profile;
@override
String toString() {
@@ -392,7 +392,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(Profile profile) loaded,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(String errorMessage) error,
}) {
return loaded(profile);
@@ -403,7 +403,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(Profile profile)? loaded,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return loaded?.call(profile);
@@ -414,7 +414,7 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(Profile profile)? loaded,
TResult Function(ProfileModel profile)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
@@ -463,10 +463,10 @@ class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
}
abstract class ProfileStateLoaded implements ProfileState {
const factory ProfileStateLoaded({required final Profile profile}) =
const factory ProfileStateLoaded({required final ProfileModel profile}) =
_$ProfileStateLoadedImpl;
Profile get profile;
ProfileModel get profile;
@JsonKey(ignore: true)
_$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
@@ -540,7 +540,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(Profile profile) loaded,
required TResult Function(ProfileModel profile) loaded,
required TResult Function(String errorMessage) error,
}) {
return error(errorMessage);
@@ -551,7 +551,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(Profile profile)? loaded,
TResult? Function(ProfileModel profile)? loaded,
TResult? Function(String errorMessage)? error,
}) {
return error?.call(errorMessage);
@@ -562,7 +562,7 @@ class _$ProfileStateErrorImpl implements ProfileStateError {
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(Profile profile)? loaded,
TResult Function(ProfileModel profile)? loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {

View File

@@ -6,11 +6,19 @@ class ProfileRepository {
ProfileRepository({required this.profileService});
Future<Profile> getProfileBySlug(String slug) async {
Future<ProfileModel> getProfileBySlug(String slug) async {
try {
return await profileService.getProfileBySlug(slug: slug);
} catch (e) {
rethrow;
}
}
Future<ProfileModel> getMyProfile() async {
try {
return await profileService.getMyProfile();
} catch (e) {
rethrow;
}
}
}

View File

@@ -9,7 +9,10 @@ abstract class ProfileService {
factory ProfileService(Dio dio, {String baseUrl}) = _ProfileService;
@GET('/api/profile/show/{slug}')
Future<Profile> getProfileBySlug({
Future<ProfileModel> getProfileBySlug({
@Path() required String slug,
});
@GET('/api/profile/index')
Future<ProfileModel> getMyProfile();
}

View File

@@ -22,12 +22,12 @@ class _ProfileService implements ProfileService {
final ParseErrorLogger? errorLogger;
@override
Future<Profile> getProfileBySlug({required String slug}) async {
Future<ProfileModel> getProfileBySlug({required String slug}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<Profile>(Options(
final _options = _setStreamType<ProfileModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
@@ -44,9 +44,42 @@ class _ProfileService implements ProfileService {
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late Profile _value;
late ProfileModel _value;
try {
_value = Profile.fromJson(_result.data!);
_value = ProfileModel.fromJson(_result.data!);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
return _value;
}
@override
Future<ProfileModel> getMyProfile() async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<ProfileModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/api/profile/index',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late ProfileModel _value;
try {
_value = ProfileModel.fromJson(_result.data!);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;