add notification, fix appbar,fix style subscription

This commit is contained in:
2026-05-21 12:19:06 +03:00
parent e7d2154d98
commit c996d0847f
60 changed files with 774 additions and 365 deletions

View File

@@ -1038,6 +1038,55 @@ class ApiService {
return controller.stream;
}
Future<List<Map<String, dynamic>>> getNotifications() async {
final url = Uri.parse('$baseUrl/notification/client');
final accessToken = await _securityService.getAccessToken();
if (accessToken == null) {
print("APISERVICE Error: Access token is null.");
throw UnauthorizedException();
}
print("GET NOTIFICATIONS REQUEST:");
print("URL: $url");
final response = await http.get(
url,
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer $accessToken",
},
);
print("GET NOTIFICATIONS RESPONSE:");
print("STATUS: ${response.statusCode}");
print("BODY: ${response.body}");
if (response.statusCode == 200) {
final data = jsonDecode(utf8.decode(response.bodyBytes));
// ✅ Проверяем, является ли ответ массивом или объектом с data[]
if (data is List) {
return data.cast<Map<String, dynamic>>();
} else if (data is Map<String, dynamic>) {
final list = data['data'];
if (list is List) {
return list.cast<Map<String, dynamic>>();
} else {
throw Exception('Expected a List under "data" but got ${list.runtimeType}');
}
} else {
throw Exception('Expected a List or Map but got ${data.runtimeType}');
}
} else if (response.statusCode == 401) {
throw UnauthorizedException();
} else if (response.statusCode == 403) {
throw AuthBlockException();
}
throw Exception('Ошибка сервера: ${response.statusCode}');
}
Future<List<Certificate>> getCertificates() async {
try {
final response = await _dio.get(

View File

@@ -33,4 +33,22 @@ class NotificationRepositoryImpl implements NotificationRepository {
void closeStream() {
// соединение закрывается автоматически при отписке от stream
}
@override
Future<List<ClientNotification>> getNotifications() async {
try {
final List<Map<String, dynamic>> data = await _apiService.getNotifications();
final notifications = data.map((json) {
final dto = ClientNotificationDto.fromJson(json);
return dto.toEntity();
}).toList();
// dev.log('NotificationRepository: Загружено ${notifications.length} уведомлений');
return notifications;
} catch (e, stackTrace) {
// dev.log('NotificationRepository: Ошибка: $e', stackTrace: stackTrace);
throw Exception('Не удалось загрузить уведомления: $e');
}
}
}

View File

@@ -92,6 +92,7 @@ import '../domain/service/device_info_service.dart';
import '../domain/usecase/activate_subscription_usecase.dart';
import '../domain/usecase/get_client_subscriptions_usecase.dart';
import '../domain/usecase/get_news_by_id_usecase.dart';
import '../domain/usecase/get_notifications_usecase.dart';
import '../domain/usecase/get_scooter_by_title_usecase.dart';
import '../domain/usecase/get_scooter_order_history_usecase.dart';
import '../domain/usecase/remove_payment_card_usecase.dart';
@@ -100,6 +101,7 @@ import '../presentation/viewmodel/auth_bloc.dart';
import '../presentation/viewmodel/edit_profile_bloc.dart';
import '../presentation/viewmodel/map_bloc.dart';
import '../presentation/viewmodel/news_bloc.dart';
import '../presentation/viewmodel/notifications_bloc.dart';
import '../presentation/viewmodel/order_history_bloc.dart';
import '../presentation/viewmodel/scooter_detail_modal_bloc.dart';
import '../presentation/viewmodel/subscription_list_bloc.dart';
@@ -286,6 +288,13 @@ Future<void> setupDependencies() async {
getIt.registerSingleton<GetScooterByTitleUsecase>(
GetScooterByTitleUsecase(getIt()),
);
getIt.registerSingleton<GetNotificationsUsecase>(
GetNotificationsUsecase(getIt<NotificationRepository>()),
);
getIt.registerFactory<NotificationsBloc>(
() => NotificationsBloc(getIt<GetNotificationsUsecase>()),
);
// Blocs
getIt.registerLazySingleton<SplashBloc>(() => SplashBloc(getIt()));

View File

@@ -9,4 +9,7 @@ abstract class NotificationRepository {
/// Закрывает SSE-соединение
void closeStream();
/// получить список уведомлений
Future<List<ClientNotification>> getNotifications();
}

View File

@@ -0,0 +1,12 @@
import '../entities/client_notification.dart';
import '../repositories/notification_repository.dart';
class GetNotificationsUsecase {
final NotificationRepository repository;
GetNotificationsUsecase(this.repository);
Future<List<ClientNotification>> call() {
return repository.getNotifications();
}
}

View File

@@ -0,0 +1,3 @@
sealed class NotificationsEvent {}
class NotificationsFetchRequested extends NotificationsEvent {}

View File

@@ -75,6 +75,7 @@ import '../event/tariff_sheet_event.dart';
import '../event/top_up_event.dart';
import '../screens/add_card_screen.dart'; // ← новый импорт
import '../screens/license_agreement_screen.dart';
import '../screens/notifications_screen.dart';
import '../screens/order_history_screen.dart';
import '../screens/payment_methods_screen.dart';
import '../screens/phone_login_screen.dart';
@@ -456,6 +457,10 @@ class AppRouter {
builder: (context, state) => const OrderHistoryScreen(),
routes: []
),
GoRoute(
path: 'notifications',
builder: (context, state) => const NotificationsScreen(),
),
],
),
],

View File

@@ -35,6 +35,7 @@ class AddCardScreen extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
const SizedBox(height: 16),
const CustomAppBar(title: 'Добавление карты'),
const SizedBox(height: 24),

View File

@@ -14,7 +14,7 @@ class LicenseAgreementScreen extends StatelessWidget {
child: SafeArea(
child: Column(
children: [
// 🔹 APPBAR С КНОПКОЙ НАЗАД
const SizedBox(height: 16),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: ' '),

View File

@@ -696,13 +696,13 @@ class _MapScreenState extends State<MapScreen> {
children: [
_RoundIconButton(
icon: Icons.notifications_sharp,
onPressed: _onNotificationTap,
onPressed: () => context.push("/home/notifications"),
),
const SizedBox(height: 12),
_RoundIconButton(
icon: Icons.directions_run,
_RoundButton(
imagePath: 'assets/icons/scooter_placemark.png',
onPressed: () => context.push("/home/current-rides-sheet"),
),
)
],
),
),
@@ -810,6 +810,40 @@ class _RoundIconButton extends StatelessWidget {
}
}
class _RoundButton extends StatelessWidget {
final String imagePath;
final VoidCallback onPressed;
const _RoundButton({
required this.imagePath,
required this.onPressed,
});
@override
Widget build(BuildContext context) {
return Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: AppColors.darkBlue,
borderRadius: BorderRadius.circular(12),
),
child: GestureDetector(
onTap: onPressed,
child: Center(
child: Image.asset(
imagePath,
width: 20,
height: 20,
fit: BoxFit.contain,
color: Colors.white,
),
),
),
);
}
}
class _CircleIconButton extends StatelessWidget {
final IconData icon;
final VoidCallback onPressed;

View File

@@ -61,7 +61,7 @@ class _NewsDetailScreenState extends State<NewsDetailScreen> {
child: SafeArea(
child: Column(
children: [
// 🔹 Заголовок в AppBar
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: widget.title),

View File

@@ -4,6 +4,7 @@ import 'dart:developer' as dev;
import '../../core/app_colors.dart';
import '../../di/service_locator.dart';
import '../components/custom_app_bar.dart';
import '../components/gradient_button.dart';
import '../event/news_event.dart';
import '../state/news_state.dart';
import '../viewmodel/news_bloc.dart';
@@ -14,11 +15,8 @@ class NewsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
dev.log('🔍 NewsScreen: Создание экрана новостей');
return BlocProvider(
create: (context) {
dev.log('🔍 NewsScreen: Создание NewsBloc');
return getIt<NewsBloc>()..add(const NewsFetchRequested());
},
child: const NewsView(),
@@ -31,7 +29,6 @@ class NewsView extends StatelessWidget {
@override
Widget build(BuildContext context) {
dev.log('🔍 NewsView: Построение UI');
return Scaffold(
body: Container(
@@ -48,7 +45,6 @@ class NewsView extends StatelessWidget {
Expanded(
child: BlocBuilder<NewsBloc, NewsState>(
builder: (context, state) {
dev.log('🔍 NewsView: Состояние ${state.status}, новостей: ${state.news.length}');
if (state.status == NewsStatus.initial || state.status == NewsStatus.loading) {
return const Center(
@@ -84,7 +80,6 @@ class NewsView extends StatelessWidget {
const SizedBox(height: 24),
ElevatedButton(
onPressed: () {
dev.log('🔍 NewsView: Повторная загрузка');
context.read<NewsBloc>().add(const NewsFetchRequested());
},
style: ElevatedButton.styleFrom(
@@ -173,7 +168,7 @@ class _NewsCard extends StatelessWidget {
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFF141530),
color: const Color(0xFF0A0F2E).withOpacity(0.7),
borderRadius: BorderRadius.circular(16),
),
child: Column(
@@ -196,6 +191,18 @@ class _NewsCard extends StatelessWidget {
),
),
const SizedBox(height: 8),
Container(
width: double.infinity,
height: 80,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/news_def.png'),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(8),
),
),
const SizedBox(height: 16),
Text(
news.previewText,
style: const TextStyle(
@@ -205,51 +212,28 @@ class _NewsCard extends StatelessWidget {
),
),
const SizedBox(height: 16),
SizedBox(
height: 40,
child: OutlinedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewsDetailScreen(
newsId: news.id,
title: news.title,
Align(
alignment: Alignment.centerRight,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 150),
child: GradientButton(
text: 'Подробнее',
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => NewsDetailScreen(
newsId: news.id,
title: news.title,
),
),
),
);
},
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(24),
),
side: BorderSide(color: AppColors.smsDigit.withOpacity(0.3)),
padding: const EdgeInsets.symmetric(horizontal: 20),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
'Подробнее',
style: TextStyle(color: AppColors.smsDigit),
),
const SizedBox(width: 8),
Icon(
Icons.arrow_forward_ios_sharp,
size: 12,
color: AppColors.smsDigit,
),
Icon(
Icons.arrow_forward_ios_sharp,
size: 12,
color: AppColors.smsDigit.withOpacity(0.6),
),
Icon(
Icons.arrow_forward_ios_sharp,
size: 12,
color: AppColors.smsDigit.withOpacity(0.3),
),
],
);
},
showArrows: true,
fontSize: 14,
height: 40,
width: double.infinity,
),
),
),

View File

@@ -0,0 +1,350 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'dart:developer' as dev;
import '../../core/app_colors.dart';
import '../../di/service_locator.dart';
import '../../domain/entities/client_notification.dart';
import '../components/custom_app_bar.dart';
import '../event/notifications_event.dart';
import '../state/notifications_state.dart';
import '../viewmodel/notifications_bloc.dart';
enum NotificationFilter {
all,
auth,
payment,
order,
}
class NotificationsScreen extends StatelessWidget {
const NotificationsScreen({super.key});
@override
Widget build(BuildContext context) {
return _NotificationsScreenContent();
}
}
class _NotificationsScreenContent extends StatefulWidget {
const _NotificationsScreenContent();
@override
State<_NotificationsScreenContent> createState() => _NotificationsScreenContentState();
}
class _NotificationsScreenContentState extends State<_NotificationsScreenContent> {
NotificationFilter _filter = NotificationFilter.all;
void _setFilter(NotificationFilter filter) {
setState(() {
_filter = filter;
});
}
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => getIt<NotificationsBloc>()..add(NotificationsFetchRequested()),
child: NotificationsView(
filter: _filter,
onFilterChanged: _setFilter,
),
);
}
}
class NotificationsView extends StatelessWidget {
final NotificationFilter filter;
final ValueChanged<NotificationFilter> onFilterChanged;
const NotificationsView({
super.key,
this.filter = NotificationFilter.all,
required this.onFilterChanged,
});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: 'Уведомления'),
),
const SizedBox(height: 16),
_buildFilterBar(),
const SizedBox(height: 16),
Expanded(
child: BlocBuilder<NotificationsBloc, NotificationsState>(
builder: (context, state) {
if (state.status == NotificationsStatus.loading) {
return const Center(child: CircularProgressIndicator(color: Colors.white));
}
if (state.status == NotificationsStatus.failure) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Ошибка загрузки уведомлений',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Text(
state.errorMessage ?? '',
style: TextStyle(
color: Colors.white.withOpacity(0.6),
fontSize: 14,
),
textAlign: TextAlign.center,
),
),
const SizedBox(height: 24),
ElevatedButton(
onPressed: () {
context.read<NotificationsBloc>().add(NotificationsFetchRequested());
},
child: const Text('Повторить'),
),
],
),
);
}
final filtered = state.notifications.where((n) {
switch (filter) {
case NotificationFilter.all:
return true;
case NotificationFilter.auth:
return n.category == NotificationCategory.auth;
case NotificationFilter.payment:
return n.category == NotificationCategory.payment;
case NotificationFilter.order:
return n.category == NotificationCategory.scooter;
// || n.category == NotificationCategory.adminInfo
// || n.category == NotificationCategory.companyInfo;
default:
return true;
}
}).toList();
if (filtered.isEmpty) {
return const _EmptyState();
}
return RefreshIndicator(
onRefresh: () async {
context.read<NotificationsBloc>().add(NotificationsFetchRequested());
},
child: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 20),
itemCount: filtered.length,
itemBuilder: (context, index) {
return _NotificationCard(notification: filtered[index]);
},
),
);
},
),
),
],
),
),
),
);
}
Widget _buildFilterBar() {
final items = [
{'label': 'Все', 'value': NotificationFilter.all},
{'label': 'Авторизация', 'value': NotificationFilter.auth},
{'label': 'Оплата', 'value': NotificationFilter.payment},
{'label': 'Поездка', 'value': NotificationFilter.order},
];
return Container(
height: 40,
padding: const EdgeInsets.symmetric(horizontal: 20),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: items.map((item) {
final isActive = item['value'] == filter;
return Padding(
padding: const EdgeInsets.only(right: 12),
child: GestureDetector(
onTap: () => onFilterChanged(item['value'] as NotificationFilter),
child: Container(
height: 32,
padding: const EdgeInsets.symmetric(horizontal: 16),
alignment: Alignment.center,
decoration: BoxDecoration(
gradient: isActive ? AppColors.activeButtonGradient : null,
color: isActive ? null : Colors.transparent,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: isActive
? Colors.transparent
: Colors.white.withOpacity(0.4),
width: 1,
),
),
child: Text(
item['label'] as String,
textAlign: TextAlign.center,
style: TextStyle(
color: isActive
? AppColors.activeButtonText
: Colors.white,
fontSize: 14,
fontWeight: isActive ? FontWeight.bold : FontWeight.normal,
),
),
),
),
);
}).toList(),
),
),
);
}
}
class _EmptyState extends StatelessWidget {
const _EmptyState();
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
'assets/notification_empty.png',
width: 280,
height: 280,
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
return const Icon(
Icons.notifications_none_outlined,
size: 120,
color: Colors.white38,
);
},
),
const SizedBox(height: 32),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Text(
'У вас пока нет уведомлений.',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white70,
fontSize: 16,
height: 1.5,
),
),
),
],
);
}
}
class _NotificationCard extends StatelessWidget {
final ClientNotification notification;
const _NotificationCard({required this.notification});
@override
Widget build(BuildContext context) {
final date = _formatDate(notification.createdAt);
return Container(
margin: const EdgeInsets.only(bottom: 12),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFF141530).withOpacity(0.7),
borderRadius: BorderRadius.circular(16),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
date,
style: TextStyle(
color: Colors.white.withOpacity(0.6),
fontSize: 12,
),
),
const SizedBox(height: 8),
Text(
notification.content,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
),
),
],
),
);
}
String _formatDate(DateTime date) {
final now = DateTime.now();
final difference = now.difference(date);
if (difference.inDays == 0) {
return 'Сегодня, ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}';
} else if (difference.inDays == 1) {
return 'Вчера, ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}';
} else {
return '${date.day.toString().padLeft(2, '0')}.${date.month.toString().padLeft(2, '0')}.${date.year}';
}
}
String _getTypeLabel(NotificationType type) {
switch (type) {
case NotificationType.info:
return 'Информация';
case NotificationType.attention:
return 'Внимание';
case NotificationType.warning:
return 'Предупреждение';
}
}
String _getCategoryLabel(NotificationCategory category) {
switch (category) {
case NotificationCategory.auth:
return 'Авторизация';
case NotificationCategory.zone:
return 'Зоны';
case NotificationCategory.payment:
return 'Оплата';
case NotificationCategory.companyInfo:
return 'Акции';
case NotificationCategory.adminInfo:
return 'Админ';
case NotificationCategory.scooter:
return 'Самокат';
}
}
}

View File

@@ -32,7 +32,7 @@ class OrderHistoryDetailScreen extends StatelessWidget {
child: SafeArea(
child: Column(
children: [
// 🔹 HEADER
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: 'Поездка $date'),

View File

@@ -32,6 +32,7 @@ class OrderHistoryView extends StatelessWidget {
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: 'История поездок'),

View File

@@ -62,6 +62,7 @@ class _PaymentConfirmScreenContent extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 16),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: 'Завершение поездки'),

View File

@@ -19,6 +19,7 @@ class PaymentMethodsScreen extends StatelessWidget {
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: 'Способы оплаты'),

View File

@@ -14,6 +14,7 @@ class PrivacyPolicyScreen extends StatelessWidget {
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: ''),

View File

@@ -45,6 +45,7 @@ class _PromoCodeScreenState extends State<PromoCodeScreen> {
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
const SizedBox(height: 16),
CustomAppBar(title: 'Промокоды'),
const SizedBox(height: 32),

View File

@@ -17,6 +17,7 @@ class QRScanInfoScreen extends StatelessWidget {
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: "Сканирование QR-кода"),

View File

@@ -6,6 +6,7 @@ import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:go_router/go_router.dart';
import 'package:be_happy/di/service_locator.dart';
import 'package:be_happy/domain/usecase/get_scooter_by_title_usecase.dart';
import '../components/custom_app_bar.dart';
import '../components/gradient_button.dart';
class QrScanScreen extends StatefulWidget {
@@ -149,15 +150,17 @@ class _QrScanScreenState extends State<QrScanScreen> {
),
),
// ✅ ИЗМЕНЕНО: прижимаем аппбар к левому краю
SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start, // ✅ Выравнивание по левому краю
children: [
const SizedBox(height: 16),
CustomAppBar(title: "Сканирование QR-кода"),
const SizedBox(height: 60),
const Text(
'Наведите рамку на QR-код — номер будет распознан автоматически',
textAlign: TextAlign.center,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 16,
@@ -170,7 +173,6 @@ class _QrScanScreenState extends State<QrScanScreen> {
],
),
),
),
SafeArea(
child: Align(

View File

@@ -58,6 +58,7 @@ class _ScooterCodeInputScreenState extends State<ScooterCodeInputScreen> {
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: "Ввод QR-кода"),

View File

@@ -70,6 +70,7 @@ class ScooterDetailScreen extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Column(
children: [
const SizedBox(height: 16),
CustomAppBar(
title: scooter?.title != null ? 'Самокат ${scooter!.title}' : 'Самокат',
),

View File

@@ -123,6 +123,11 @@ class _SendPhotoViewState extends State<SendPhotoView> {
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: "Отправить фото"),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 100),
child: Text(

View File

@@ -2,7 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import '../../core/app_colors.dart';
import '../components/app_checkbox.dart';
import '../components/custom_app_bar.dart'; // ✅ Добавь импорт
import '../components/gradient_button.dart';
import '../components/period_selector.dart';
import '../event/subscription_details_event.dart';
@@ -17,66 +19,74 @@ class SubscriptionDetailsScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF1A2355),
appBar: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios, color: Colors.white),
onPressed: () => context.pop(),
),
title: BlocBuilder<SubscriptionDetailsBloc, SubscriptionDetailsState>(
builder: (context, state) {
if (state is DetailsContentState) {
return Text(state.subscription.title);
}
return const Text("Загрузка...");
},
body: Container(
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: BlocBuilder<SubscriptionDetailsBloc, SubscriptionDetailsState>(
builder: (context, state) {
String title = "Загрузка...";
if (state is DetailsContentState) {
title = state.subscription.title;
}
return CustomAppBar(title: title);
},
),
),
const SizedBox(height: 20),
// 🔹 Контент
Expanded(
child: Stack(
children: [
// Волна снизу
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Opacity(
opacity: 0.5,
child: Image.asset('assets/wave.png'),
),
),
BlocBuilder<SubscriptionDetailsBloc, SubscriptionDetailsState>(
builder: (context, state) {
if (state is DetailsLoading) {
return const Center(
child: CircularProgressIndicator(color: Color(0xFF80FFD1)),
);
}
if (state is DetailsError) {
return Center(
child: Text(
state.message,
style: const TextStyle(color: Colors.white),
),
);
}
if (state is DetailsContentState) {
return _buildContent(context, state);
}
return const SizedBox();
},
),
],
),
),
],
),
),
),
body: Stack(
children: [
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Opacity(
opacity: 0.5,
child: Image.asset('assets/wave.png'),
),
),
BlocBuilder<SubscriptionDetailsBloc, SubscriptionDetailsState>(
builder: (context, state) {
if (state is DetailsLoading) {
return const Center(
child: CircularProgressIndicator(color: Color(0xFF80FFD1)),
);
}
if (state is DetailsError) {
return Center(
child: Text(
state.message,
style: const TextStyle(color: Colors.white),
),
);
}
if (state is DetailsContentState) {
return _buildContent(context, state);
}
return const SizedBox();
},
),
],
)
);
}
Widget _buildContent(BuildContext context, DetailsContentState state) {
return SingleChildScrollView(
padding: const EdgeInsets.all(20.0),
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -104,6 +114,7 @@ class SubscriptionDetailsScreen extends StatelessWidget {
fontSize: 16,
showArrows: true,
),
const SizedBox(height: 20),
],
),
);
@@ -125,9 +136,6 @@ class _ActionCard extends StatelessWidget {
state.selectedPeriod,
);
context.read<SubscriptionDetailsBloc>().add(
SelectPeriodEvent(state.subscription.options[selectedIndex]));
return Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
@@ -205,7 +213,7 @@ class _PriceRow extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset("assets/icons/money_icon.png", width: 72, height: 72),
SizedBox(width: 15),
const SizedBox(width: 15),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -224,5 +232,4 @@ class _PriceRow extends StatelessWidget {
),
);
}
}
}

View File

@@ -21,6 +21,7 @@ class SubscriptionsListScreen extends StatelessWidget {
child: SafeArea(
child: Column(
children: [
const SizedBox(height: 16),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomAppBar(title: 'Абонементы'),

View File

@@ -21,53 +21,55 @@ class TopUpScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF1A234E),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
const SizedBox(height: 16),
const CustomAppBar(title: 'Пополнение баланса'),
const SizedBox(height: 20),
body: Container(
decoration: const BoxDecoration(gradient: AppColors.phoneScreenBg),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
children: [
const SizedBox(height: 16),
const CustomAppBar(title: 'Пополнение баланса'),
const SizedBox(height: 20),
BlocBuilder<TopUpBloc, TopUpState>(
builder: (context, state) {
if (state.isLoading) {
return const Center(child: CircularProgressIndicator());
}
BlocBuilder<TopUpBloc, TopUpState>(
builder: (context, state) {
if (state.isLoading) {
return const Center(child: CircularProgressIndicator());
}
return Expanded(
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildTariffList(state, context),
const SizedBox(height: 30),
_buildPriceInfo(state),
const SizedBox(height: 40),
const Text(
'Способ оплаты',
style: TextStyle(color: Colors.white70),
),
const SizedBox(height: 15),
_buildCardSelector(state, context),
const SizedBox(height: 20),
_buildAgreement(state, context),
const Spacer(),
_buildPayButton(state),
const SizedBox(height: 30),
],
),
],
),
);
},
),
],
return Expanded(
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildTariffList(state, context),
const SizedBox(height: 30),
_buildPriceInfo(state),
const SizedBox(height: 40),
const Text(
'Способ оплаты',
style: TextStyle(color: Colors.white70),
),
const SizedBox(height: 15),
_buildCardSelector(state, context),
const SizedBox(height: 20),
_buildAgreement(state, context),
const Spacer(),
_buildPayButton(state),
const SizedBox(height: 30),
],
),
],
),
);
},
),
],
),
),
),
)
),
);
}

View File

@@ -0,0 +1,27 @@
import '../../domain/entities/client_notification.dart';
enum NotificationsStatus { initial, loading, success, failure }
class NotificationsState {
final NotificationsStatus status;
final List<ClientNotification> notifications;
final String? errorMessage;
const NotificationsState({
this.status = NotificationsStatus.initial,
this.notifications = const [],
this.errorMessage,
});
NotificationsState copyWith({
NotificationsStatus? status,
List<ClientNotification>? notifications,
String? errorMessage,
}) {
return NotificationsState(
status: status ?? this.status,
notifications: notifications ?? this.notifications,
errorMessage: errorMessage ?? this.errorMessage,
);
}
}

View File

@@ -0,0 +1,34 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'dart:developer' as dev;
import '../../domain/usecase/get_notifications_usecase.dart';
import '../event/notifications_event.dart';
import '../state/notifications_state.dart';
class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
final GetNotificationsUsecase _getNotificationsUsecase;
NotificationsBloc(this._getNotificationsUsecase) : super(const NotificationsState()) {
on<NotificationsFetchRequested>(_onFetchRequested);
}
Future<void> _onFetchRequested(
NotificationsFetchRequested event,
Emitter<NotificationsState> emit,
) async {
emit(state.copyWith(status: NotificationsStatus.loading));
try {
final notifications = await _getNotificationsUsecase();
emit(state.copyWith(
status: NotificationsStatus.success,
notifications: notifications,
));
} catch (e) {
dev.log('NotificationsBloc: Ошибка загрузки: $e');
emit(state.copyWith(
status: NotificationsStatus.failure,
errorMessage: e.toString(),
));
}
}
}