Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
notifications_screen.dart
Go to the documentation of this file.
1import 'package:aidra_drive/core/ui/widgets/loading.dart';
2import 'package:easy_localization/easy_localization.dart';
3import 'package:flutter_bloc/flutter_bloc.dart';
4import 'package:fluentui_system_icons/fluentui_system_icons.dart';
5import 'package:flutter/material.dart';
6import '../../../../../core/ui/theme/color_palette.dart';
7import '../../../../../core/ui/widgets/custom_scaffold.dart';
8import 'package:flutter_screenutil/flutter_screenutil.dart';
9import '../../../../../core/ui/widgets/error_widget.dart';
10import '../../../../../core/ui/widgets/logo_header.dart';
11import '../../../../auth/presentation/bloc/authentication_bloc/authentication_bloc.dart';
12import '../../../domain/entities/notification_entity.dart';
13import '../../bloc/notifications_bloc.dart';
14import 'widgets/notification_card.dart';
15
17 const NotificationsScreen({super.key});
18
19 @override
20 State<NotificationsScreen> createState() => _NotificationsScreenState();
21}
22
23class _NotificationsScreenState extends State<NotificationsScreen> {
24 @override
25 void initState() {
26 final authState = context.read<AuthenticationBloc>().state;
27 if (authState is AuthenticatedState) {
28 context.read<NotificationsBloc>().add(
29 LoadNotificationsEvent(userId: authState.session.uid ?? 0),
30 );
31 }
32 super.initState();
33 }
34
35 @override
36 Widget build(BuildContext context) {
37 return CustomScaffold(
38 backgroundColor: ColorPalette.antiFlashWhite,
39 isLeadingVisible: false,
40 body: BlocConsumer<NotificationsBloc, NotificationsState>(
41 listener: (context, state) {
42 if (state is NotificationsError) {
43 ScaffoldMessenger.of(context).showSnackBar(
44 SnackBar(
45 content: Text(state.failure.message),
46 backgroundColor: Colors.red,
47 behavior: SnackBarBehavior.floating,
48 ),
49 );
50 }
51 },
52 builder: (context, state) {
53 return RefreshIndicator(
54 onRefresh: () async {
55 final authState = context.read<AuthenticationBloc>().state;
56 if (authState is AuthenticatedState) {
57 context.read<NotificationsBloc>().add(
58 LoadNotificationsEvent(userId: authState.session.uid ?? 0),
59 );
60 }
61 },
62 child: _buildContent(state),
63 );
64 },
65 ),
66 );
67 }
68
70 if (state is NotificationsLoading) {
71 return _buildLoadingWidget();
72 }
73
74 if (state is NotificationsError) {
75 return CustomErrorWidget(
76 message: "common.connection_failed".tr(),
77 onReload: () {
78 final authState = context.read<AuthenticationBloc>().state;
79 if (authState is AuthenticatedState) {
80 context.read<NotificationsBloc>().add(
81 LoadNotificationsEvent(userId: authState.session.uid ?? 0),
82 );
83 }
84 },
85 );
86 }
87
88 if (state is NotificationsLoaded) {
89 if (state.notifications.isEmpty) {
90 return _buildEmptyWidget();
91 }
92 return _buildNotificationsList(state.notifications);
93 }
94
95 return _buildEmptyWidget();
96 }
97
99 return const Loading();
100 }
101
103 return Center(
104 child: Column(
105 mainAxisAlignment: MainAxisAlignment.center,
106 children: [
107 Icon(
108 FluentIcons.chat_12_regular,
109 size: 48.sp,
111 ),
112 SizedBox(height: 16.sp),
113 Text(
114 'notifications.no_notifications'.tr(),
115 style: TextStyle(
116 fontSize: 16.sp,
118 ),
119 ),
120 ],
121 ),
122 );
123 }
124
125 Widget _buildNotificationsList(List<NotificationEntity> notifications) {
126 return Column(
127 children: [
128 LogoHeader(title: "notifications.title".tr()),
129 Expanded(
130 child: ListView.builder(
131 physics: const AlwaysScrollableScrollPhysics(),
132 padding: EdgeInsets.symmetric(horizontal: 16.sp, vertical: 16.sp),
133 itemCount: notifications.length,
134 itemBuilder: (context, index) {
135 final notification = notifications[index];
136 return NotificationCard(notification: notification);
137 },
138 ),
139 ),
140 ],
141 );
142 }
143}
override void initState()
class App extends StatefulWidget build(BuildContext context)
Definition app.dart:31
sealed class CheckInOutEvent extends Equatable userId
static const antiFlashWhite
static const grey
override State< NotificationsScreen > createState()
const NotificationsScreen({super.key})
final Widget child
final EdgeInsets padding
final Color color
Definition failures.dart:1
final String message
Definition failures.dart:0
const LoadNotificationsEvent({required this.userId})
const NotificationsScreen({super.key})
Widget _buildLoadingWidget()
Widget _buildNotificationsList(List< NotificationEntity > notifications)
Widget _buildEmptyWidget()
Widget _buildContent(NotificationsState state)
sealed class NotificationsState extends Equatable notifications
const NotificationsLoaded({required this.notifications})
final String title
style Text( '${ 'scheduling.reference'.tr()}:${collection.internalCode}', style:Theme.of(context).textTheme.bodySmall,)
style SizedBox(height:2.h)
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)