2025-02-26 13:40:43 +03:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
|
|
import 'package:friflex_starter/app/app_context_ext.dart';
|
|
|
|
|
|
import 'package:friflex_starter/features/profile/domain/bloc/profile_bloc.dart';
|
|
|
|
|
|
|
2025-06-20 16:50:48 +03:00
|
|
|
|
/// {@template profile_screen}
|
|
|
|
|
|
/// Экран профиля пользователя.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Отвечает за:
|
|
|
|
|
|
/// - Инициализацию ProfileBloc с репозиторием профиля
|
|
|
|
|
|
/// - Отображение данных профиля пользователя
|
|
|
|
|
|
/// - Обработку состояний загрузки, успеха и ошибок
|
|
|
|
|
|
/// {@endtemplate}
|
2025-02-26 13:40:43 +03:00
|
|
|
|
class ProfileScreen extends StatelessWidget {
|
2025-06-20 16:50:48 +03:00
|
|
|
|
/// {@macro profile_screen}
|
2025-02-26 13:40:43 +03:00
|
|
|
|
const ProfileScreen({super.key});
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
final profileRepository = context.di.repositories.profileRepository;
|
2025-06-20 16:50:48 +03:00
|
|
|
|
// Инициализируем ProfileBloc с репозиторием и загружаем данные профиля
|
2025-02-26 13:40:43 +03:00
|
|
|
|
return BlocProvider(
|
2025-05-28 16:38:56 +03:00
|
|
|
|
create: (context) =>
|
|
|
|
|
|
ProfileBloc(profileRepository)
|
|
|
|
|
|
..add(const ProfileFetchProfileEvent(id: '1')),
|
2025-02-26 13:40:43 +03:00
|
|
|
|
child: const _ProfileScreenView(),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-20 16:50:48 +03:00
|
|
|
|
/// {@template profile_screen_view}
|
|
|
|
|
|
/// Виджет для отображения UI экрана профиля.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Отображает данные профиля в зависимости от состояния ProfileBloc:
|
|
|
|
|
|
/// - Индикатор загрузки во время получения данных
|
|
|
|
|
|
/// - Данные профиля при успешной загрузке
|
|
|
|
|
|
/// - Сообщение об ошибке при неудачной загрузке
|
|
|
|
|
|
/// {@endtemplate}
|
2025-02-26 13:40:43 +03:00
|
|
|
|
class _ProfileScreenView extends StatelessWidget {
|
2025-06-20 16:50:48 +03:00
|
|
|
|
/// {@macro profile_screen_view}
|
2025-02-26 13:40:43 +03:00
|
|
|
|
const _ProfileScreenView();
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return Scaffold(
|
2025-05-28 16:38:56 +03:00
|
|
|
|
appBar: AppBar(title: const Text('Profile')),
|
2025-02-26 13:40:43 +03:00
|
|
|
|
body: Center(
|
|
|
|
|
|
child: BlocBuilder<ProfileBloc, ProfileState>(
|
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
|
return switch (state) {
|
|
|
|
|
|
ProfileSuccessState() => Text('Data: ${state.props.first}'),
|
|
|
|
|
|
ProfileErrorState() => Text('Error: ${state.message}'),
|
|
|
|
|
|
_ => const CircularProgressIndicator(),
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|