From fe502f8056dbe203531ac14b9af44353616a7e51 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Thu, 16 Nov 2023 10:03:20 -0500 Subject: [PATCH] Fix multiclick error on notifications causing multiple navigations --- lib/controls/notifications_control.dart | 47 ++++++++++++++++++------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/lib/controls/notifications_control.dart b/lib/controls/notifications_control.dart index 7a11eb5..d38dce6 100644 --- a/lib/controls/notifications_control.dart +++ b/lib/controls/notifications_control.dart @@ -20,8 +20,9 @@ import 'image_control.dart'; class NotificationControl extends StatelessWidget { static final _logger = Logger('$NotificationControl'); final UserNotification notification; + bool _processingTap = false; - const NotificationControl({ + NotificationControl({ super.key, required this.notification, }); @@ -85,17 +86,17 @@ class NotificationControl extends StatelessWidget { ), ); - Function()? onTap; + Function()? onTapCallFunction; switch (notification.type) { case NotificationType.follow: - onTap = () { - context.pushNamed(ScreenPaths.userProfile, + onTapCallFunction = () async { + await context.pushNamed(ScreenPaths.userProfile, pathParameters: {'id': notification.fromId}); }; break; case NotificationType.follow_request: - onTap = () { - context.push('/connect/${notification.fromId}'); + onTapCallFunction = () async { + await context.push('/connect/${notification.fromId}'); }; break; case NotificationType.unknown: @@ -106,30 +107,43 @@ class NotificationControl extends StatelessWidget { case NotificationType.reshare: case NotificationType.reblog: case NotificationType.status: - onTap = () { - _goToStatus(context); + onTapCallFunction = () async { + await _goToStatus(context); }; break; case NotificationType.direct_message: - onTap = () => context.pushNamed( + onTapCallFunction = () async => await context.pushNamed( ScreenPaths.thread, queryParameters: {'uri': notification.iid}, ); break; } + final onTap = onTapCallFunction == null + ? null + : () async { + if (_processingTap) { + return true; + } + + _tapProcessingStarted(); + await onTapCallFunction!(); + _tapProcessingStop(); + return true; + }; + return ListTile( tileColor: notification.dismissed ? null : Colors.black12, leading: fromIcon, title: GestureDetector( - onTap: onTap == null ? null : () async => onTap!(), + onTap: onTap, child: HtmlTextViewerControl( content: notification.content, - onTapUrl: onTap == null ? null : (_) async => onTap!(), + onTapUrl: (_) async => onTap!(), ), ), subtitle: GestureDetector( - onTap: onTap == null ? null : () async => onTap!(), + onTap: onTap, child: Text( ElapsedDateUtils.epochSecondsToString(notification.timestamp), ), @@ -150,4 +164,13 @@ class NotificationControl extends StatelessWidget { icon: const Icon(Icons.close_rounded)), ); } + + void _tapProcessingStarted() { + _processingTap = true; + Future.delayed(Duration(seconds: 10), () => _processingTap = false); + } + + void _tapProcessingStop() { + _processingTap = false; + } }