43 lines
1.1 KiB
Dart
Executable File
43 lines
1.1 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import '../widgets/kr_toast.dart';
|
|
|
|
class KRCommonUtil {
|
|
/// 提示 meesage: 提示内容, toastPosition: 提示显示的位置, timeout: 显示时间(毫秒)
|
|
static kr_showToast(String message,
|
|
{KRToastPosition toastPosition = KRToastPosition.center,
|
|
int timeout = 2500}) {
|
|
KRToast.kr_showToast(
|
|
message,
|
|
position: toastPosition,
|
|
duration: Duration(milliseconds: timeout),
|
|
);
|
|
}
|
|
|
|
/// 显示加载动画
|
|
static kr_showLoading({String? message}) {
|
|
KRToast.kr_showLoading(message: message);
|
|
}
|
|
|
|
/// 隐藏加载动画
|
|
static kr_hideLoading() {
|
|
KRToast.kr_hideLoading();
|
|
}
|
|
|
|
/// 格式化字节数为可读字符串
|
|
/// [bytes] 字节数
|
|
static String kr_formatBytes(int bytes) {
|
|
if (bytes <= 0) return "0 B";
|
|
|
|
const List<String> suffixes = ["B", "KB", "MB", "GB", "TB"];
|
|
int i = 0;
|
|
double value = bytes.toDouble();
|
|
|
|
while (value >= 1024 && i < suffixes.length - 1) {
|
|
value /= 1024;
|
|
i++;
|
|
}
|
|
|
|
return "${value.toStringAsFixed(2)} ${suffixes[i]}";
|
|
}
|
|
}
|