You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.8 KiB
Dart

class Common {
factory Common() => _getInstance();
static Common get instance => _getInstance();
static Common _instance; // 单例对象
static Common _getInstance() {
if (_instance == null) {
_instance = Common._internal();
}
return _instance;
}
Common._internal();
/////////////////////////////////////////////////////////////
String sDCardDir;
String getFileSize(int fileSize) {
String str = '';
if (fileSize < 1024) {
str = '${fileSize.toStringAsFixed(2)}B';
} else if (1024 <= fileSize && fileSize < 1048576) {
str = '${(fileSize / 1024).toStringAsFixed(2)}KB';
} else if (1048576 <= fileSize && fileSize < 1073741824) {
str = '${(fileSize / 1024 / 1024).toStringAsFixed(2)}MB';
}
return str;
}
String selectIcon(String ext) {
String iconImg = 'assets/files_icons/unknown.png';
switch (ext) {
case '.ppt':
case '.pptx':
iconImg = 'assets/files_icons/ppt.png';
break;
case '.doc':
case '.docx':
iconImg = 'assets/files_icons/word.png';
break;
case '.xls':
case '.xlsx':
iconImg = 'assets/files_icons/excel.png';
break;
case '.jpg':
case '.jpeg':
case '.png':
iconImg = 'assets/files_icons/image.png';
break;
case '.txt':
iconImg = 'assets/files_icons/txt.png';
break;
case '.mp3':
iconImg = 'assets/files_icons/mp3.png';
break;
case '.mp4':
iconImg = 'assets/files_icons/video.png';
break;
case '.rar':
case '.zip':
iconImg = 'assets/files_icons/zip.png';
break;
case '.psd':
iconImg = 'assets/files_icons/psd.png';
break;
default:
iconImg = 'assets/files_icons/file.png';
break;
}
return iconImg;
}
}