12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import 'dart:async';
- import 'package:flutter_smartscan_plugin/id_card_recognition.dart'
- if (dart.library.html) "package:vitalapp/architecture/utils/id_card.dart";
- class CommonUtil {
- static const deFaultDurationTime = 1000;
- static Timer? timer;
- static IDCardRecognition idCardRecognition = IDCardRecognition();
-
- static const String REGEX_EMAIL =
- "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}\$";
-
- static const String DIGIT_REGEX = "[0-9]+";
-
- static const String CONTAIN_DIGIT_REGEX = ".*[0-9].*";
-
- static const String LETTER_REGEX = "[a-zA-Z]+";
-
- static const String SMALL_CONTAIN_LETTER_REGEX = ".*[a-z].*";
-
- static const String BIG_CONTAIN_LETTER_REGEX = ".*[A-Z].*";
-
- static const String CONTAIN_LETTER_REGEX = ".*[a-zA-Z].*";
-
- static const String CHINESE_REGEX = "[\u4e00-\u9fa5]";
-
- static const String BLANK_SPACE = "[ ]";
-
- static const String LETTER_DIGIT_REGEX = "^[a-z0-9A-Z]+\$";
- static const String CHINESE_LETTER_REGEX = "([\u4e00-\u9fa5]+|[a-zA-Z]+)";
- static const String CHINESE_LETTER_DIGIT_REGEX =
- "^[a-z0-9A-Z\u4e00-\u9fa5]+\$";
-
- static const String deFaultThrottleId = 'DeFaultThrottleId';
- static Map<String, int> startTimeMap = {deFaultThrottleId: 0};
-
-
-
- static debounce(Function doSomething, {durationTime = deFaultDurationTime}) {
- timer?.cancel();
- timer = Timer(Duration(milliseconds: durationTime), () {
- doSomething.call();
- timer = null;
- });
- }
-
- static bool hasDigit(String input) {
- if (input.isEmpty) return false;
- return RegExp(CONTAIN_DIGIT_REGEX).hasMatch(input);
- }
-
- static bool isChinese(String input) {
- if (input.isEmpty) return false;
- return RegExp(CHINESE_REGEX).hasMatch(input);
- }
-
- static bool isOnly(String input) {
- if (input.isEmpty) return false;
- return RegExp(DIGIT_REGEX).hasMatch(input);
- }
- static throttle(Function doSomething,
- {String throttleId = deFaultThrottleId,
- int durationTime = deFaultDurationTime,
- Function? continueClick}) {
- int currentTime = DateTime.now().millisecondsSinceEpoch;
- if (currentTime - (startTimeMap[throttleId] ?? 0) > durationTime) {
- doSomething.call();
- startTimeMap[throttleId] = DateTime.now().millisecondsSinceEpoch;
- } else {
- continueClick?.call();
- }
- }
- }
|