fix tutorial gets open to often

This commit is contained in:
otsmr 2025-05-31 19:38:04 +02:00
parent 7997bc2fa0
commit 33ab69b1b7
2 changed files with 90 additions and 85 deletions

View file

@ -1,48 +1,42 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:mutex/mutex.dart';
import 'package:tutorial_coach_mark/tutorial_coach_mark.dart';
import 'package:twonly/src/utils/misc.dart';
import 'package:twonly/src/utils/storage.dart';
final lockDisplayTutorial = Mutex();
Future showTutorial(BuildContext context, List<TargetFocus> targets) async {
await lockDisplayTutorial.protect(() async {
Completer completer = Completer();
TutorialCoachMark(
targets: targets,
colorShadow: context.color.primary,
textSkip: context.lang.ok,
alignSkip: Alignment.bottomCenter,
textStyleSkip: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
),
onClickTarget: (target) {
print(target);
},
onClickTargetWithTapPosition: (target, tapDetails) {
print("target: $target");
print(
"clicked at position local: ${tapDetails.localPosition} - global: ${tapDetails.globalPosition}");
},
onClickOverlay: (target) {
print(target);
},
onSkip: () {
completer.complete();
return true;
},
onFinish: () {
completer.complete();
},
).show(context: context);
Completer completer = Completer();
TutorialCoachMark(
targets: targets,
colorShadow: context.color.primary,
textSkip: context.lang.ok,
alignSkip: Alignment.bottomCenter,
textStyleSkip: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 20,
),
onClickTarget: (target) {
print(target);
},
onClickTargetWithTapPosition: (target, tapDetails) {
print("target: $target");
print(
"clicked at position local: ${tapDetails.localPosition} - global: ${tapDetails.globalPosition}");
},
onClickOverlay: (target) {
print(target);
},
onSkip: () {
completer.complete();
return true;
},
onFinish: () {
completer.complete();
},
).show(context: context);
await completer.future;
});
await completer.future;
}
Future<bool> checkIfTutorialAlreadyShown(String tutorialId) async {

View file

@ -1,76 +1,87 @@
import 'package:flutter/material.dart';
import 'package:mutex/mutex.dart';
import 'package:tutorial_coach_mark/tutorial_coach_mark.dart';
import 'package:twonly/src/utils/misc.dart';
import 'package:twonly/src/views/tutorial/show_tutorial.dart';
final lockDisplayTutorial = Mutex();
Future showChatListTutorialSearchOtherUsers(
BuildContext context,
GlobalKey searchForOtherUsers,
) async {
if (await checkIfTutorialAlreadyShown("chat_list:search_users")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
searchForOtherUsers,
context.lang.tutorialChatListSearchUsersTitle,
context.lang.tutorialChatListSearchUsersDesc,
));
await showTutorial(context, targets);
await lockDisplayTutorial.protect(() async {
if (await checkIfTutorialAlreadyShown("chat_list:search_users")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
searchForOtherUsers,
context.lang.tutorialChatListSearchUsersTitle,
context.lang.tutorialChatListSearchUsersDesc,
));
await showTutorial(context, targets);
});
}
Future showChatListTutorialContextMenu(
BuildContext context,
GlobalKey firstUserListItemKey,
) async {
if (await checkIfTutorialAlreadyShown("chat_list:context_menu")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
firstUserListItemKey,
context.lang.tutorialChatListContextMenuTitle,
context.lang.tutorialChatListContextMenuDesc,
));
await showTutorial(context, targets);
await lockDisplayTutorial.protect(() async {
if (await checkIfTutorialAlreadyShown("chat_list:context_menu")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
firstUserListItemKey,
context.lang.tutorialChatListContextMenuTitle,
context.lang.tutorialChatListContextMenuDesc,
));
await showTutorial(context, targets);
});
}
Future showVerifyShieldTutorial(
BuildContext context,
GlobalKey firstUserListItemKey,
) async {
if (await checkIfTutorialAlreadyShown("chat_messages:verify_shield")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
firstUserListItemKey,
context.lang.tutorialChatMessagesVerifyShieldTitle,
context.lang.tutorialChatMessagesVerifyShieldDesc,
));
await showTutorial(context, targets);
await lockDisplayTutorial.protect(() async {
if (await checkIfTutorialAlreadyShown("chat_messages:verify_shield")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
firstUserListItemKey,
context.lang.tutorialChatMessagesVerifyShieldTitle,
context.lang.tutorialChatMessagesVerifyShieldDesc,
));
await showTutorial(context, targets);
});
}
Future showReopenMediaFilesTutorial(
BuildContext context,
GlobalKey firstUserListItemKey,
) async {
if (await checkIfTutorialAlreadyShown("chat_messages:reopen_message")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
firstUserListItemKey,
context.lang.tutorialChatMessagesReopenMessageTitle,
context.lang.tutorialChatMessagesReopenMessageDesc,
));
await showTutorial(context, targets);
await lockDisplayTutorial.protect(() async {
if (await checkIfTutorialAlreadyShown("chat_messages:reopen_message")) {
return;
}
if (!context.mounted) return;
List<TargetFocus> targets = [];
targets.add(getTargetFocus(
context,
firstUserListItemKey,
context.lang.tutorialChatMessagesReopenMessageTitle,
context.lang.tutorialChatMessagesReopenMessageDesc,
));
await showTutorial(context, targets);
});
}