forked from eatvio/eatvio_app
feat(feed, profile): добавлен переход на страинцу автора в посте, рецепте и дете. при нажатии на изображение в рецепте и диеты теперь переход на страницу с подробнее.
This commit is contained in:
82
lib/features/profile/models/profile_model.dart
Normal file
82
lib/features/profile/models/profile_model.dart
Normal file
@@ -0,0 +1,82 @@
|
||||
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({
|
||||
@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: "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;
|
||||
|
||||
factory Profile.fromJson(Map<String, Object?> json) => _$ProfileFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class User with _$User {
|
||||
const factory User({
|
||||
@JsonKey(name: "id") required int id,
|
||||
@JsonKey(name: "name") required String name,
|
||||
@JsonKey(name: "email") required String email,
|
||||
@JsonKey(name: "email_verified_at") required DateTime emailVerifiedAt,
|
||||
@JsonKey(name: "two_factor_confirmed_at") required dynamic twoFactorConfirmedAt,
|
||||
@JsonKey(name: "current_team_id") required dynamic currentTeamId,
|
||||
@JsonKey(name: "profile_photo_path") required String profilePhotoPath,
|
||||
@JsonKey(name: "created_at") required DateTime createdAt,
|
||||
@JsonKey(name: "updated_at") required DateTime updatedAt,
|
||||
@JsonKey(name: "is_consultant") required int isConsultant,
|
||||
@JsonKey(name: "is_public_profile") required int isPublicProfile,
|
||||
@JsonKey(name: "slug") required String slug,
|
||||
@JsonKey(name: "user_settings_id") required dynamic userSettingsId,
|
||||
@JsonKey(name: "profile_photo_url") required String profilePhotoUrl,
|
||||
@JsonKey(name: "detailz") required UserDetails detailz,
|
||||
}) = _User;
|
||||
|
||||
factory User.fromJson(Map<String, Object?> json) => _$UserFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class UserDetails with _$UserDetails {
|
||||
const factory UserDetails({
|
||||
@JsonKey(name: "id") required int id,
|
||||
@JsonKey(name: "user_id") required int userId,
|
||||
@JsonKey(name: "first_name") required String firstName,
|
||||
@JsonKey(name: "last_name") required String lastName,
|
||||
@JsonKey(name: "birthdate") required DateTime birthdate,
|
||||
@JsonKey(name: "gender") required String gender,
|
||||
@JsonKey(name: "country") required String country,
|
||||
@JsonKey(name: "city") required String city,
|
||||
@JsonKey(name: "lang") required String lang,
|
||||
@JsonKey(name: "weight") required int weight,
|
||||
@JsonKey(name: "height") required int height,
|
||||
@JsonKey(name: "chest_circumference") required int chestCircumference,
|
||||
@JsonKey(name: "waist_circumference") required int waistCircumference,
|
||||
@JsonKey(name: "hip_circumference") required int hipCircumference,
|
||||
@JsonKey(name: "blood_pressure_up") required int bloodPressureUp,
|
||||
@JsonKey(name: "blood_pressure_down") required int bloodPressureDown,
|
||||
@JsonKey(name: "has_hypo") required int hasHypo,
|
||||
@JsonKey(name: "has_hyper") required int hasHyper,
|
||||
@JsonKey(name: "about_alergy") required String aboutAlergy,
|
||||
@JsonKey(name: "about_taking_pils") required String aboutTakingPils,
|
||||
@JsonKey(name: "about_sport_hobbies") required String aboutSportHobbies,
|
||||
@JsonKey(name: "favorite_foods") required String favoriteFoods,
|
||||
@JsonKey(name: "unfavorite_foods") required String unfavoriteFoods,
|
||||
@JsonKey(name: "additional_info") required String additionalInfo,
|
||||
@JsonKey(name: "created_at") required DateTime createdAt,
|
||||
@JsonKey(name: "updated_at") required DateTime updatedAt,
|
||||
@JsonKey(name: "is_mood_fillable") required int isMoodFillable,
|
||||
@JsonKey(name: "is_bedtime_fillable") required int isBedtimeFillable,
|
||||
@JsonKey(name: "activity_coefficient") required double activityCoefficient,
|
||||
}) = _UserDetails;
|
||||
|
||||
factory UserDetails.fromJson(Map<String, Object?> json) => _$UserDetailsFromJson(json);
|
||||
}
|
||||
1817
lib/features/profile/models/profile_model.freezed.dart
Normal file
1817
lib/features/profile/models/profile_model.freezed.dart
Normal file
File diff suppressed because it is too large
Load Diff
139
lib/features/profile/models/profile_model.g.dart
Normal file
139
lib/features/profile/models/profile_model.g.dart
Normal file
@@ -0,0 +1,139 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'profile_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$ProfileImpl _$$ProfileImplFromJson(Map<String, dynamic> json) =>
|
||||
_$ProfileImpl(
|
||||
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>,
|
||||
finishedPlans: json['finishedPlans'] as List<dynamic>,
|
||||
rejectedPlans: json['rejectedPlans'] as List<dynamic>,
|
||||
startedPlan: json['startedPlan'] as List<dynamic>,
|
||||
paidPlan: json['paidPlan'] as List<dynamic>,
|
||||
requestedPlan: json['requestedPlan'] as List<dynamic>,
|
||||
initedPlan: json['initedPlan'] as List<dynamic>,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ProfileImplToJson(_$ProfileImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'user': instance.user,
|
||||
'chartPoints': instance.chartPoints,
|
||||
'userDetails': instance.userDetails,
|
||||
'circumferences': instance.circumferences,
|
||||
'finishedPlans': instance.finishedPlans,
|
||||
'rejectedPlans': instance.rejectedPlans,
|
||||
'startedPlan': instance.startedPlan,
|
||||
'paidPlan': instance.paidPlan,
|
||||
'requestedPlan': instance.requestedPlan,
|
||||
'initedPlan': instance.initedPlan,
|
||||
};
|
||||
|
||||
_$UserImpl _$$UserImplFromJson(Map<String, dynamic> json) => _$UserImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
name: json['name'] as String,
|
||||
email: json['email'] as String,
|
||||
emailVerifiedAt: DateTime.parse(json['email_verified_at'] as String),
|
||||
twoFactorConfirmedAt: json['two_factor_confirmed_at'],
|
||||
currentTeamId: json['current_team_id'],
|
||||
profilePhotoPath: json['profile_photo_path'] as String,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
isConsultant: (json['is_consultant'] as num).toInt(),
|
||||
isPublicProfile: (json['is_public_profile'] as num).toInt(),
|
||||
slug: json['slug'] as String,
|
||||
userSettingsId: json['user_settings_id'],
|
||||
profilePhotoUrl: json['profile_photo_url'] as String,
|
||||
detailz: UserDetails.fromJson(json['detailz'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$UserImplToJson(_$UserImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'email': instance.email,
|
||||
'email_verified_at': instance.emailVerifiedAt.toIso8601String(),
|
||||
'two_factor_confirmed_at': instance.twoFactorConfirmedAt,
|
||||
'current_team_id': instance.currentTeamId,
|
||||
'profile_photo_path': instance.profilePhotoPath,
|
||||
'created_at': instance.createdAt.toIso8601String(),
|
||||
'updated_at': instance.updatedAt.toIso8601String(),
|
||||
'is_consultant': instance.isConsultant,
|
||||
'is_public_profile': instance.isPublicProfile,
|
||||
'slug': instance.slug,
|
||||
'user_settings_id': instance.userSettingsId,
|
||||
'profile_photo_url': instance.profilePhotoUrl,
|
||||
'detailz': instance.detailz,
|
||||
};
|
||||
|
||||
_$UserDetailsImpl _$$UserDetailsImplFromJson(Map<String, dynamic> json) =>
|
||||
_$UserDetailsImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
userId: (json['user_id'] as num).toInt(),
|
||||
firstName: json['first_name'] as String,
|
||||
lastName: json['last_name'] as String,
|
||||
birthdate: DateTime.parse(json['birthdate'] as String),
|
||||
gender: json['gender'] as String,
|
||||
country: json['country'] as String,
|
||||
city: json['city'] as String,
|
||||
lang: json['lang'] as String,
|
||||
weight: (json['weight'] as num).toInt(),
|
||||
height: (json['height'] as num).toInt(),
|
||||
chestCircumference: (json['chest_circumference'] as num).toInt(),
|
||||
waistCircumference: (json['waist_circumference'] as num).toInt(),
|
||||
hipCircumference: (json['hip_circumference'] as num).toInt(),
|
||||
bloodPressureUp: (json['blood_pressure_up'] as num).toInt(),
|
||||
bloodPressureDown: (json['blood_pressure_down'] as num).toInt(),
|
||||
hasHypo: (json['has_hypo'] as num).toInt(),
|
||||
hasHyper: (json['has_hyper'] as num).toInt(),
|
||||
aboutAlergy: json['about_alergy'] as String,
|
||||
aboutTakingPils: json['about_taking_pils'] as String,
|
||||
aboutSportHobbies: json['about_sport_hobbies'] as String,
|
||||
favoriteFoods: json['favorite_foods'] as String,
|
||||
unfavoriteFoods: json['unfavorite_foods'] as String,
|
||||
additionalInfo: json['additional_info'] as String,
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
isMoodFillable: (json['is_mood_fillable'] as num).toInt(),
|
||||
isBedtimeFillable: (json['is_bedtime_fillable'] as num).toInt(),
|
||||
activityCoefficient: (json['activity_coefficient'] as num).toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$UserDetailsImplToJson(_$UserDetailsImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'user_id': instance.userId,
|
||||
'first_name': instance.firstName,
|
||||
'last_name': instance.lastName,
|
||||
'birthdate': instance.birthdate.toIso8601String(),
|
||||
'gender': instance.gender,
|
||||
'country': instance.country,
|
||||
'city': instance.city,
|
||||
'lang': instance.lang,
|
||||
'weight': instance.weight,
|
||||
'height': instance.height,
|
||||
'chest_circumference': instance.chestCircumference,
|
||||
'waist_circumference': instance.waistCircumference,
|
||||
'hip_circumference': instance.hipCircumference,
|
||||
'blood_pressure_up': instance.bloodPressureUp,
|
||||
'blood_pressure_down': instance.bloodPressureDown,
|
||||
'has_hypo': instance.hasHypo,
|
||||
'has_hyper': instance.hasHyper,
|
||||
'about_alergy': instance.aboutAlergy,
|
||||
'about_taking_pils': instance.aboutTakingPils,
|
||||
'about_sport_hobbies': instance.aboutSportHobbies,
|
||||
'favorite_foods': instance.favoriteFoods,
|
||||
'unfavorite_foods': instance.unfavoriteFoods,
|
||||
'additional_info': instance.additionalInfo,
|
||||
'created_at': instance.createdAt.toIso8601String(),
|
||||
'updated_at': instance.updatedAt.toIso8601String(),
|
||||
'is_mood_fillable': instance.isMoodFillable,
|
||||
'is_bedtime_fillable': instance.isBedtimeFillable,
|
||||
'activity_coefficient': instance.activityCoefficient,
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart';
|
||||
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());
|
||||
|
||||
getProfileBySlug(String slug) async {
|
||||
try {
|
||||
emit(ProfileState.loaded(profile: await profileRepository.getProfileBySlug(slug)));
|
||||
} catch (e) {
|
||||
emit(ProfileState.error(errorMessage: e.toString()));
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'profile_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ProfileState with _$ProfileState {
|
||||
const factory ProfileState() = _ProfileState;
|
||||
|
||||
const factory ProfileState.loading() = ProfileStateLoading;
|
||||
|
||||
const factory ProfileState.loaded({
|
||||
required Profile profile,
|
||||
}) = ProfileStateLoaded;
|
||||
|
||||
const factory ProfileState.error({
|
||||
required String errorMessage,
|
||||
}) = ProfileStateError;
|
||||
}
|
||||
@@ -0,0 +1,621 @@
|
||||
// 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 'profile_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 _$ProfileState {
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value) $default, {
|
||||
required TResult Function(ProfileStateLoading value) loading,
|
||||
required TResult Function(ProfileStateLoaded value) loaded,
|
||||
required TResult Function(ProfileStateError value) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_ProfileState value)? $default, {
|
||||
TResult? Function(ProfileStateLoading value)? loading,
|
||||
TResult? Function(ProfileStateLoaded value)? loaded,
|
||||
TResult? Function(ProfileStateError value)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value)? $default, {
|
||||
TResult Function(ProfileStateLoading value)? loading,
|
||||
TResult Function(ProfileStateLoaded value)? loaded,
|
||||
TResult Function(ProfileStateError value)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ProfileStateCopyWith<$Res> {
|
||||
factory $ProfileStateCopyWith(
|
||||
ProfileState value, $Res Function(ProfileState) then) =
|
||||
_$ProfileStateCopyWithImpl<$Res, ProfileState>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ProfileStateCopyWithImpl<$Res, $Val extends ProfileState>
|
||||
implements $ProfileStateCopyWith<$Res> {
|
||||
_$ProfileStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ProfileStateImplCopyWith<$Res> {
|
||||
factory _$$ProfileStateImplCopyWith(
|
||||
_$ProfileStateImpl value, $Res Function(_$ProfileStateImpl) then) =
|
||||
__$$ProfileStateImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ProfileStateImplCopyWithImpl<$Res>
|
||||
extends _$ProfileStateCopyWithImpl<$Res, _$ProfileStateImpl>
|
||||
implements _$$ProfileStateImplCopyWith<$Res> {
|
||||
__$$ProfileStateImplCopyWithImpl(
|
||||
_$ProfileStateImpl _value, $Res Function(_$ProfileStateImpl) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ProfileStateImpl implements _ProfileState {
|
||||
const _$ProfileStateImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ProfileState()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType && other is _$ProfileStateImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return $default();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return $default?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if ($default != null) {
|
||||
return $default();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value) $default, {
|
||||
required TResult Function(ProfileStateLoading value) loading,
|
||||
required TResult Function(ProfileStateLoaded value) loaded,
|
||||
required TResult Function(ProfileStateError value) error,
|
||||
}) {
|
||||
return $default(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_ProfileState value)? $default, {
|
||||
TResult? Function(ProfileStateLoading value)? loading,
|
||||
TResult? Function(ProfileStateLoaded value)? loaded,
|
||||
TResult? Function(ProfileStateError value)? error,
|
||||
}) {
|
||||
return $default?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value)? $default, {
|
||||
TResult Function(ProfileStateLoading value)? loading,
|
||||
TResult Function(ProfileStateLoaded value)? loaded,
|
||||
TResult Function(ProfileStateError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if ($default != null) {
|
||||
return $default(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ProfileState implements ProfileState {
|
||||
const factory _ProfileState() = _$ProfileStateImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ProfileStateLoadingImplCopyWith<$Res> {
|
||||
factory _$$ProfileStateLoadingImplCopyWith(_$ProfileStateLoadingImpl value,
|
||||
$Res Function(_$ProfileStateLoadingImpl) then) =
|
||||
__$$ProfileStateLoadingImplCopyWithImpl<$Res>;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ProfileStateLoadingImplCopyWithImpl<$Res>
|
||||
extends _$ProfileStateCopyWithImpl<$Res, _$ProfileStateLoadingImpl>
|
||||
implements _$$ProfileStateLoadingImplCopyWith<$Res> {
|
||||
__$$ProfileStateLoadingImplCopyWithImpl(_$ProfileStateLoadingImpl _value,
|
||||
$Res Function(_$ProfileStateLoadingImpl) _then)
|
||||
: super(_value, _then);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ProfileStateLoadingImpl implements ProfileStateLoading {
|
||||
const _$ProfileStateLoadingImpl();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ProfileState.loading()';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ProfileStateLoadingImpl);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loading();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loading != null) {
|
||||
return loading();
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value) $default, {
|
||||
required TResult Function(ProfileStateLoading value) loading,
|
||||
required TResult Function(ProfileStateLoaded value) loaded,
|
||||
required TResult Function(ProfileStateError value) error,
|
||||
}) {
|
||||
return loading(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_ProfileState value)? $default, {
|
||||
TResult? Function(ProfileStateLoading value)? loading,
|
||||
TResult? Function(ProfileStateLoaded value)? loaded,
|
||||
TResult? Function(ProfileStateError value)? error,
|
||||
}) {
|
||||
return loading?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value)? $default, {
|
||||
TResult Function(ProfileStateLoading value)? loading,
|
||||
TResult Function(ProfileStateLoaded value)? loaded,
|
||||
TResult Function(ProfileStateError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loading != null) {
|
||||
return loading(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ProfileStateLoading implements ProfileState {
|
||||
const factory ProfileStateLoading() = _$ProfileStateLoadingImpl;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ProfileStateLoadedImplCopyWith<$Res> {
|
||||
factory _$$ProfileStateLoadedImplCopyWith(_$ProfileStateLoadedImpl value,
|
||||
$Res Function(_$ProfileStateLoadedImpl) then) =
|
||||
__$$ProfileStateLoadedImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({Profile profile});
|
||||
|
||||
$ProfileCopyWith<$Res> get profile;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ProfileStateLoadedImplCopyWithImpl<$Res>
|
||||
extends _$ProfileStateCopyWithImpl<$Res, _$ProfileStateLoadedImpl>
|
||||
implements _$$ProfileStateLoadedImplCopyWith<$Res> {
|
||||
__$$ProfileStateLoadedImplCopyWithImpl(_$ProfileStateLoadedImpl _value,
|
||||
$Res Function(_$ProfileStateLoadedImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? profile = null,
|
||||
}) {
|
||||
return _then(_$ProfileStateLoadedImpl(
|
||||
profile: null == profile
|
||||
? _value.profile
|
||||
: profile // ignore: cast_nullable_to_non_nullable
|
||||
as Profile,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ProfileCopyWith<$Res> get profile {
|
||||
return $ProfileCopyWith<$Res>(_value.profile, (value) {
|
||||
return _then(_value.copyWith(profile: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ProfileStateLoadedImpl implements ProfileStateLoaded {
|
||||
const _$ProfileStateLoadedImpl({required this.profile});
|
||||
|
||||
@override
|
||||
final Profile profile;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ProfileState.loaded(profile: $profile)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ProfileStateLoadedImpl &&
|
||||
(identical(other.profile, profile) || other.profile == profile));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, profile);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith =>
|
||||
__$$ProfileStateLoadedImplCopyWithImpl<_$ProfileStateLoadedImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loaded(profile);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loaded?.call(profile);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loaded != null) {
|
||||
return loaded(profile);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value) $default, {
|
||||
required TResult Function(ProfileStateLoading value) loading,
|
||||
required TResult Function(ProfileStateLoaded value) loaded,
|
||||
required TResult Function(ProfileStateError value) error,
|
||||
}) {
|
||||
return loaded(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_ProfileState value)? $default, {
|
||||
TResult? Function(ProfileStateLoading value)? loading,
|
||||
TResult? Function(ProfileStateLoaded value)? loaded,
|
||||
TResult? Function(ProfileStateError value)? error,
|
||||
}) {
|
||||
return loaded?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value)? $default, {
|
||||
TResult Function(ProfileStateLoading value)? loading,
|
||||
TResult Function(ProfileStateLoaded value)? loaded,
|
||||
TResult Function(ProfileStateError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loaded != null) {
|
||||
return loaded(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ProfileStateLoaded implements ProfileState {
|
||||
const factory ProfileStateLoaded({required final Profile profile}) =
|
||||
_$ProfileStateLoadedImpl;
|
||||
|
||||
Profile get profile;
|
||||
@JsonKey(ignore: true)
|
||||
_$$ProfileStateLoadedImplCopyWith<_$ProfileStateLoadedImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ProfileStateErrorImplCopyWith<$Res> {
|
||||
factory _$$ProfileStateErrorImplCopyWith(_$ProfileStateErrorImpl value,
|
||||
$Res Function(_$ProfileStateErrorImpl) then) =
|
||||
__$$ProfileStateErrorImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({String errorMessage});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ProfileStateErrorImplCopyWithImpl<$Res>
|
||||
extends _$ProfileStateCopyWithImpl<$Res, _$ProfileStateErrorImpl>
|
||||
implements _$$ProfileStateErrorImplCopyWith<$Res> {
|
||||
__$$ProfileStateErrorImplCopyWithImpl(_$ProfileStateErrorImpl _value,
|
||||
$Res Function(_$ProfileStateErrorImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? errorMessage = null,
|
||||
}) {
|
||||
return _then(_$ProfileStateErrorImpl(
|
||||
errorMessage: null == errorMessage
|
||||
? _value.errorMessage
|
||||
: errorMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$ProfileStateErrorImpl implements ProfileStateError {
|
||||
const _$ProfileStateErrorImpl({required this.errorMessage});
|
||||
|
||||
@override
|
||||
final String errorMessage;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ProfileState.error(errorMessage: $errorMessage)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ProfileStateErrorImpl &&
|
||||
(identical(other.errorMessage, errorMessage) ||
|
||||
other.errorMessage == errorMessage));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, errorMessage);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ProfileStateErrorImplCopyWith<_$ProfileStateErrorImpl> get copyWith =>
|
||||
__$$ProfileStateErrorImplCopyWithImpl<_$ProfileStateErrorImpl>(
|
||||
this, _$identity);
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Profile profile) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return error(errorMessage);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Profile profile)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return error?.call(errorMessage);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Profile profile)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (error != null) {
|
||||
return error(errorMessage);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult map<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value) $default, {
|
||||
required TResult Function(ProfileStateLoading value) loading,
|
||||
required TResult Function(ProfileStateLoaded value) loaded,
|
||||
required TResult Function(ProfileStateError value) error,
|
||||
}) {
|
||||
return error(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult? mapOrNull<TResult extends Object?>(
|
||||
TResult? Function(_ProfileState value)? $default, {
|
||||
TResult? Function(ProfileStateLoading value)? loading,
|
||||
TResult? Function(ProfileStateLoaded value)? loaded,
|
||||
TResult? Function(ProfileStateError value)? error,
|
||||
}) {
|
||||
return error?.call(this);
|
||||
}
|
||||
|
||||
@override
|
||||
@optionalTypeArgs
|
||||
TResult maybeMap<TResult extends Object?>(
|
||||
TResult Function(_ProfileState value)? $default, {
|
||||
TResult Function(ProfileStateLoading value)? loading,
|
||||
TResult Function(ProfileStateLoaded value)? loaded,
|
||||
TResult Function(ProfileStateError value)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (error != null) {
|
||||
return error(this);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ProfileStateError implements ProfileState {
|
||||
const factory ProfileStateError({required final String errorMessage}) =
|
||||
_$ProfileStateErrorImpl;
|
||||
|
||||
String get errorMessage;
|
||||
@JsonKey(ignore: true)
|
||||
_$$ProfileStateErrorImplCopyWith<_$ProfileStateErrorImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_cubit.dart';
|
||||
import 'package:eatvio_app/features/profile/presentation/bloc/profile_cubit/profile_state.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ProfileScreen extends StatelessWidget {
|
||||
@@ -8,26 +12,58 @@ class ProfileScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Column(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
maxRadius: 128,
|
||||
minRadius: 128,
|
||||
backgroundImage: NetworkImage(author.authorProfileIcon),
|
||||
),
|
||||
SizedBox(height: 32),
|
||||
Text(
|
||||
author.authorName,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
],
|
||||
return BlocProvider<ProfileCubit>(
|
||||
create: (BuildContext context) => sl<ProfileCubit>()..getProfileBySlug(author.authorSlug),
|
||||
child: BlocBuilder<ProfileCubit, ProfileState>(
|
||||
builder: (BuildContext context, ProfileState state) {
|
||||
if (state is ProfileStateLoaded) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
state.profile.user.name,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w400,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
Center(
|
||||
child: CircleAvatar(
|
||||
maxRadius: 128,
|
||||
minRadius: 128,
|
||||
backgroundImage: NetworkImage(state.profile.user.profilePhotoUrl),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (state is ProfileStateError) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(state.errorMessage),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
16
lib/features/profile/repositories/profile_repository.dart
Normal file
16
lib/features/profile/repositories/profile_repository.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/profile/services/profile_service.dart';
|
||||
|
||||
class ProfileRepository {
|
||||
final ProfileService profileService;
|
||||
|
||||
ProfileRepository({required this.profileService});
|
||||
|
||||
Future<Profile> getProfileBySlug(String slug) async {
|
||||
try {
|
||||
return await profileService.getProfileBySlug(slug: slug);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
lib/features/profile/services/profile_service.dart
Normal file
15
lib/features/profile/services/profile_service.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
part 'profile_service.g.dart';
|
||||
|
||||
@RestApi()
|
||||
abstract class ProfileService {
|
||||
factory ProfileService(Dio dio, {String baseUrl}) = _ProfileService;
|
||||
|
||||
@GET('/api/profile/show/{slug}')
|
||||
Future<Profile> getProfileBySlug({
|
||||
@Path() required String slug,
|
||||
});
|
||||
}
|
||||
77
lib/features/profile/services/profile_service.g.dart
Normal file
77
lib/features/profile/services/profile_service.g.dart
Normal file
@@ -0,0 +1,77 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'profile_service.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RetrofitGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers,unused_element
|
||||
|
||||
class _ProfileService implements ProfileService {
|
||||
_ProfileService(
|
||||
this._dio, {
|
||||
this.baseUrl,
|
||||
});
|
||||
|
||||
final Dio _dio;
|
||||
|
||||
String? baseUrl;
|
||||
|
||||
@override
|
||||
Future<Profile> getProfileBySlug({required String slug}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _result =
|
||||
await _dio.fetch<Map<String, dynamic>>(_setStreamType<Profile>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/profile/show/${slug}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final _value = Profile.fromJson(_result.data!);
|
||||
return _value;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user