mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 13:33:32 +00:00
Fix multiclick error on notifications causing multiple navigations
This commit is contained in:
parent
b28db1ea84
commit
fe502f8056
1 changed files with 35 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue