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 {
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;
}
}