fix
This commit is contained in:
@@ -23,7 +23,10 @@ class NotificationsScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _NotificationsScreenContent();
|
||||
return BlocProvider(
|
||||
create: (context) => getIt<NotificationsBloc>()..add(NotificationsFetchRequested(page: 1)),
|
||||
child: _NotificationsScreenContent(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,21 +39,31 @@ class _NotificationsScreenContent extends StatefulWidget {
|
||||
|
||||
class _NotificationsScreenContentState extends State<_NotificationsScreenContent> {
|
||||
NotificationFilter _filter = NotificationFilter.all;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _setFilter(NotificationFilter filter) {
|
||||
setState(() {
|
||||
_filter = filter;
|
||||
});
|
||||
setState(() => _filter = filter);
|
||||
_scrollController.jumpTo(0);
|
||||
context.read<NotificationsBloc>().add(NotificationsFetchRequested(page: 1));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => getIt<NotificationsBloc>()..add(NotificationsFetchRequested()),
|
||||
child: NotificationsView(
|
||||
filter: _filter,
|
||||
onFilterChanged: _setFilter,
|
||||
),
|
||||
return NotificationsView(
|
||||
filter: _filter,
|
||||
onFilterChanged: _setFilter,
|
||||
scrollController: _scrollController,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -58,11 +71,13 @@ class _NotificationsScreenContentState extends State<_NotificationsScreenContent
|
||||
class NotificationsView extends StatelessWidget {
|
||||
final NotificationFilter filter;
|
||||
final ValueChanged<NotificationFilter> onFilterChanged;
|
||||
final ScrollController? scrollController;
|
||||
|
||||
const NotificationsView({
|
||||
super.key,
|
||||
this.filter = NotificationFilter.all,
|
||||
required this.onFilterChanged,
|
||||
this.scrollController,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -119,7 +134,7 @@ class NotificationsView extends StatelessWidget {
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<NotificationsBloc>().add(NotificationsFetchRequested());
|
||||
context.read<NotificationsBloc>().add(NotificationsFetchRequested(page: 1));
|
||||
},
|
||||
child: const Text('Повторить'),
|
||||
),
|
||||
@@ -138,9 +153,6 @@ class NotificationsView extends StatelessWidget {
|
||||
return n.category == NotificationCategory.payment;
|
||||
case NotificationFilter.order:
|
||||
return n.category == NotificationCategory.scooter;
|
||||
// || n.category == NotificationCategory.adminInfo
|
||||
// || n.category == NotificationCategory.companyInfo;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@@ -152,14 +164,39 @@ class NotificationsView extends StatelessWidget {
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
context.read<NotificationsBloc>().add(NotificationsFetchRequested());
|
||||
context.read<NotificationsBloc>().add(NotificationsFetchRequested(page: 1));
|
||||
},
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
itemCount: filtered.length,
|
||||
itemBuilder: (context, index) {
|
||||
return _NotificationCard(notification: filtered[index]);
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (scrollInfo) {
|
||||
if (scrollInfo.metrics.pixels >= scrollInfo.metrics.maxScrollExtent - 50 &&
|
||||
scrollInfo.metrics.maxScrollExtent > 0 &&
|
||||
state.hasMore &&
|
||||
!state.isLoadingMore &&
|
||||
state.status == NotificationsStatus.success) {
|
||||
context.read<NotificationsBloc>().add(NotificationsLoadMoreRequested());
|
||||
}
|
||||
return false;
|
||||
},
|
||||
child: ListView.builder(
|
||||
controller: scrollController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
itemCount: filtered.length + (state.hasMore && filtered.length >= 10 ? 1 : 0),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == filtered.length && state.hasMore && filtered.length >= 10) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _NotificationCard(notification: filtered[index]);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -308,16 +345,23 @@ class _NotificationCard extends StatelessWidget {
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
final localDate = date.toLocal();
|
||||
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}';
|
||||
if (localDate.year == now.year &&
|
||||
localDate.month == now.month &&
|
||||
localDate.day == now.day) {
|
||||
return 'Сегодня, ${localDate.hour.toString().padLeft(2, '0')}:${localDate.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
final yesterday = now.subtract(const Duration(days: 1));
|
||||
if (localDate.year == yesterday.year &&
|
||||
localDate.month == yesterday.month &&
|
||||
localDate.day == yesterday.day) {
|
||||
return 'Вчера, ${localDate.hour.toString().padLeft(2, '0')}:${localDate.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
return '${localDate.day.toString().padLeft(2, '0')}.${localDate.month.toString().padLeft(2, '0')}.${localDate.year}';
|
||||
}
|
||||
|
||||
String _getTypeLabel(NotificationType type) {
|
||||
|
||||
Reference in New Issue
Block a user