blank_door.dart 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:flutter/foundation.dart';
  2. import 'package:get/get.dart';
  3. import 'package:vitalapp/architecture/utils/prompt_box.dart';
  4. import 'package:vitalapp/components/dialog_input.dart';
  5. class BlankDoor {
  6. static final Map<String, String> _rolePwdMap = {
  7. "test": "abc123",
  8. "developer": "dev@2024",
  9. };
  10. static int _clickCount = 0;
  11. static bool _busy = false;
  12. static String? _cacheRole;
  13. static void reset() {
  14. _clickCount = 0;
  15. _cacheRole = null;
  16. }
  17. static void tryOpen() async {
  18. _clickCount++;
  19. if (_clickCount >= 3 && _clickCount <= 8) {
  20. PromptBox.toast("Click count: $_clickCount!");
  21. }
  22. if (_clickCount >= 8) {
  23. if (_busy) {
  24. return;
  25. }
  26. _busy = true;
  27. await _doOpen();
  28. _busy = false;
  29. }
  30. }
  31. static Future<void> _doOpen() async {
  32. if (_cacheRole == null) {
  33. final pwd = await _fetchPwd();
  34. if (pwd == null) {
  35. // 直接取消了
  36. return;
  37. }
  38. final role = _matchRoleByPwd(pwd);
  39. if (role == null) {
  40. PromptBox.toast("密码错误!");
  41. return;
  42. }
  43. _cacheRole = role;
  44. }
  45. Get.toNamed(
  46. "/admin",
  47. parameters: {
  48. "role": _cacheRole!,
  49. },
  50. );
  51. }
  52. static String? _matchRoleByPwd(String pwd) {
  53. for (var key in _rolePwdMap.keys) {
  54. final val = _rolePwdMap[key];
  55. if (val == pwd) {
  56. return key;
  57. }
  58. }
  59. return null;
  60. }
  61. static Future<String?> _fetchPwd() async {
  62. String? result = await VDialogInput(
  63. title: "请输入密码",
  64. initialValue: kDebugMode ? "dev@2024" : null,
  65. ).show();
  66. return result;
  67. }
  68. }