Fix multiclick error on notifications causing multiple navigations

codemagic-setup
Hank Grabowski 2023-11-16 10:03:20 -05:00
rodzic b28db1ea84
commit fe502f8056
1 zmienionych plików z 35 dodań i 12 usunięć

Wyświetl plik

@ -20,8 +20,9 @@ import 'image_control.dart';
class NotificationControl extends StatelessWidget { class NotificationControl extends StatelessWidget {
static final _logger = Logger('$NotificationControl'); static final _logger = Logger('$NotificationControl');
final UserNotification notification; final UserNotification notification;
bool _processingTap = false;
const NotificationControl({ NotificationControl({
super.key, super.key,
required this.notification, required this.notification,
}); });
@ -85,17 +86,17 @@ class NotificationControl extends StatelessWidget {
), ),
); );
Function()? onTap; Function()? onTapCallFunction;
switch (notification.type) { switch (notification.type) {
case NotificationType.follow: case NotificationType.follow:
onTap = () { onTapCallFunction = () async {
context.pushNamed(ScreenPaths.userProfile, await context.pushNamed(ScreenPaths.userProfile,
pathParameters: {'id': notification.fromId}); pathParameters: {'id': notification.fromId});
}; };
break; break;
case NotificationType.follow_request: case NotificationType.follow_request:
onTap = () { onTapCallFunction = () async {
context.push('/connect/${notification.fromId}'); await context.push('/connect/${notification.fromId}');
}; };
break; break;
case NotificationType.unknown: case NotificationType.unknown:
@ -106,30 +107,43 @@ class NotificationControl extends StatelessWidget {
case NotificationType.reshare: case NotificationType.reshare:
case NotificationType.reblog: case NotificationType.reblog:
case NotificationType.status: case NotificationType.status:
onTap = () { onTapCallFunction = () async {
_goToStatus(context); await _goToStatus(context);
}; };
break; break;
case NotificationType.direct_message: case NotificationType.direct_message:
onTap = () => context.pushNamed( onTapCallFunction = () async => await context.pushNamed(
ScreenPaths.thread, ScreenPaths.thread,
queryParameters: {'uri': notification.iid}, queryParameters: {'uri': notification.iid},
); );
break; break;
} }
final onTap = onTapCallFunction == null
? null
: () async {
if (_processingTap) {
return true;
}
_tapProcessingStarted();
await onTapCallFunction!();
_tapProcessingStop();
return true;
};
return ListTile( return ListTile(
tileColor: notification.dismissed ? null : Colors.black12, tileColor: notification.dismissed ? null : Colors.black12,
leading: fromIcon, leading: fromIcon,
title: GestureDetector( title: GestureDetector(
onTap: onTap == null ? null : () async => onTap!(), onTap: onTap,
child: HtmlTextViewerControl( child: HtmlTextViewerControl(
content: notification.content, content: notification.content,
onTapUrl: onTap == null ? null : (_) async => onTap!(), onTapUrl: (_) async => onTap!(),
), ),
), ),
subtitle: GestureDetector( subtitle: GestureDetector(
onTap: onTap == null ? null : () async => onTap!(), onTap: onTap,
child: Text( child: Text(
ElapsedDateUtils.epochSecondsToString(notification.timestamp), ElapsedDateUtils.epochSecondsToString(notification.timestamp),
), ),
@ -150,4 +164,13 @@ class NotificationControl extends StatelessWidget {
icon: const Icon(Icons.close_rounded)), icon: const Icon(Icons.close_rounded)),
); );
} }
void _tapProcessingStarted() {
_processingTap = true;
Future.delayed(Duration(seconds: 10), () => _processingTap = false);
}
void _tapProcessingStop() {
_processingTap = false;
}
} }