part of '../neon_notifications.dart'; class NotificationsMainPage extends StatefulWidget { const NotificationsMainPage({ required this.bloc, super.key, }); final NotificationsBloc bloc; @override State createState() => _NotificationsMainPageState(); } class _NotificationsMainPageState extends State { @override void initState() { super.initState(); widget.bloc.errors.listen((final error) { NeonException.showSnackbar(context, error); }); } @override Widget build(final BuildContext context) => ResultBuilder>( stream: widget.bloc.notifications, builder: (final context, final notifications) => Scaffold( resizeToAvoidBottomInset: false, floatingActionButton: FloatingActionButton( onPressed: () async { widget.bloc.deleteAllNotifications(); }, child: const Icon(MdiIcons.checkAll), ), body: NeonListView( scrollKey: 'notifications-notifications', withFloatingActionButton: true, items: notifications.data, isLoading: notifications.loading, error: notifications.error, onRefresh: widget.bloc.refresh, builder: _buildNotification, ), ), ); Widget _buildNotification( final BuildContext context, final NextcloudNotificationsNotification notification, ) { final matchingAppImplementations = Provider.of>(context, listen: false) .where((final a) => a.id == notification.app) .toList(); return ListTile( title: Text(notification.subject), subtitle: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ if (notification.message.isNotEmpty) ...[ Text( notification.message, overflow: TextOverflow.ellipsis, ), const SizedBox( height: 5, ), ], RelativeTime( date: DateTime.parse(notification.datetime), ), ], ), leading: matchingAppImplementations.isNotEmpty ? matchingAppImplementations.single.buildIcon( context, width: 40, height: 40, ) : SizedBox( width: 40, height: 40, child: NeonCachedUrlImage( url: notification.icon, width: 40, height: 40, svgColor: Theme.of(context).colorScheme.primary, ), ), onTap: () async { if (notification.app == 'notifications') { return; } final allAppImplementations = Provider.of>(context, listen: false); final matchingAppImplementations = allAppImplementations.where((final a) => a.id == notification.app); if (matchingAppImplementations.isNotEmpty) { final accountsBloc = Provider.of(context, listen: false); await accountsBloc.getAppsBloc(accountsBloc.activeAccount.value!).setActiveApp(notification.app); } else { await showDialog( context: context, builder: (final context) => AlertDialog( title: Text(AppLocalizations.of(context).notificationsNextcloudAppNotImplementedYet), actions: [ ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.red, foregroundColor: Theme.of(context).colorScheme.onPrimary, ), onPressed: () { Navigator.of(context).pop(); }, child: Text(AppLocalizations.of(context).close), ), ], ), ); } }, onLongPress: () { widget.bloc.deleteNotification(notification.notificationId); }, ); } }