39 lines
1.0 KiB
Dart
39 lines
1.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
class Utils{
|
|
Utils._internal();
|
|
|
|
/// 关闭键盘
|
|
static void hideKeyboard() {
|
|
FocusScopeNode? currentFocus = Get.focusScope?.nearestScope;
|
|
if (currentFocus == null) {
|
|
return;
|
|
}
|
|
if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
|
|
FocusManager.instance.primaryFocus?.unfocus();
|
|
}
|
|
}
|
|
|
|
// 是否是平板
|
|
static bool isPad([double mobilePhoneScale = 1.2]) {
|
|
return ScreenUtil().scaleWidth > mobilePhoneScale;
|
|
}
|
|
|
|
static String getDoubleRemoveZero(double? val, [String? defaultVal]) {
|
|
try {
|
|
if (val == null) throw Exception('数据为空');
|
|
List<String> _valArr = val.toString().split('.');
|
|
if (_valArr.length >= 2) {
|
|
if (int.parse(_valArr[1]) == 0) {
|
|
return val.toInt().toString();
|
|
}
|
|
return val.toString();
|
|
}
|
|
return val.toInt().toString();
|
|
} catch (e) {
|
|
return defaultVal ?? '';
|
|
}
|
|
}
|
|
} |