增加若干基础页面
This commit is contained in:
@@ -1,9 +1,45 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ToolFn {
|
||||
DateTime? lastPressedAt; //上次点击时间
|
||||
|
||||
// 字符串是否为空
|
||||
static bool isBlank(String? str) {
|
||||
if (str == null || str.isEmpty) {
|
||||
static bool isBlank(String str) {
|
||||
if (str.isEmpty) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///手机号验证(只验证前三位号段)
|
||||
static bool checkMobile(String str) {
|
||||
if (isBlank(str)) {
|
||||
return true;
|
||||
}
|
||||
return !RegExp(r"^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}")
|
||||
.hasMatch(str);
|
||||
}
|
||||
|
||||
static void tips(String msg) {
|
||||
BotToast.showText(
|
||||
text: msg,
|
||||
contentColor: Colors.black,
|
||||
textStyle: const TextStyle(fontSize: 17, color: Colors.white));
|
||||
}
|
||||
|
||||
// 监听返回键
|
||||
void isExit() {
|
||||
if (lastPressedAt == null ||
|
||||
DateTime.now().difference(lastPressedAt!) >
|
||||
const Duration(seconds: 1)) {
|
||||
//两次点击间隔超过1秒则重新计时
|
||||
lastPressedAt = DateTime.now();
|
||||
ToolFn.tips("再按一次退出程序");
|
||||
return;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user