1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import 'package:flutter/foundation.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/architecture/utils/prompt_box.dart';
- import 'package:vitalapp/components/dialog_input.dart';
- class BlankDoor {
- static final Map<String, String> _rolePwdMap = {
- "test": "abc123",
- "developer": "dev@2024",
- };
- static int _clickCount = 0;
- static bool _busy = false;
- static String? _cacheRole;
- static void reset() {
- _clickCount = 0;
- _cacheRole = null;
- }
- static void tryOpen() async {
- _clickCount++;
- if (_clickCount >= 3 && _clickCount <= 8) {
- PromptBox.toast("Click count: $_clickCount!");
- }
- if (_clickCount >= 8) {
- if (_busy) {
- return;
- }
- _busy = true;
- await _doOpen();
- _busy = false;
- }
- }
- static Future<void> _doOpen() async {
- if (_cacheRole == null) {
- final pwd = await _fetchPwd();
- if (pwd == null) {
- // 直接取消了
- return;
- }
- final role = _matchRoleByPwd(pwd);
- if (role == null) {
- PromptBox.toast("密码错误!");
- return;
- }
- _cacheRole = role;
- }
- Get.toNamed(
- "/admin",
- parameters: {
- "role": _cacheRole!,
- },
- );
- }
- static String? _matchRoleByPwd(String pwd) {
- for (var key in _rolePwdMap.keys) {
- final val = _rolePwdMap[key];
- if (val == pwd) {
- return key;
- }
- }
- return null;
- }
- static Future<String?> _fetchPwd() async {
- String? result = await VDialogInput(
- title: "请输入密码",
- initialValue: kDebugMode ? "dev@2024" : null,
- ).show();
- return result;
- }
- }
|