Add file type labeling in file explorer; categorize files as Video, Track, Photo, Document, or File based on extensions.
This commit is contained in:
@@ -36,6 +36,80 @@ class FileExplorer extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _FileExplorerState extends State<FileExplorer> {
|
||||
String _getFileTypeLabel(FileItem file) {
|
||||
if (file.type == FileType.folder) return 'Folder';
|
||||
final name = file.name.toLowerCase();
|
||||
final ext = p.extension(name);
|
||||
// Video
|
||||
const videoExts = [
|
||||
'.mp4',
|
||||
'.webm',
|
||||
'.mov',
|
||||
'.avi',
|
||||
'.mkv',
|
||||
'.flv',
|
||||
'.wmv',
|
||||
'.m4v',
|
||||
'.ogv',
|
||||
'.3gp',
|
||||
'.ts',
|
||||
'.mpg',
|
||||
'.mpeg',
|
||||
];
|
||||
if (videoExts.contains(ext)) return 'Video';
|
||||
// Audio
|
||||
const audioExts = [
|
||||
'.mp3',
|
||||
'.wav',
|
||||
'.flac',
|
||||
'.ogg',
|
||||
'.aac',
|
||||
'.m4a',
|
||||
'.opus',
|
||||
'.wma',
|
||||
'.alac',
|
||||
'.aiff',
|
||||
'.amr',
|
||||
];
|
||||
if (audioExts.contains(ext)) return 'Track';
|
||||
// Image
|
||||
const imageExts = [
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.png',
|
||||
'.gif',
|
||||
'.bmp',
|
||||
'.tiff',
|
||||
'.tif',
|
||||
'.webp',
|
||||
'.heic',
|
||||
'.svg',
|
||||
'.ico',
|
||||
];
|
||||
if (imageExts.contains(ext)) return 'Photo';
|
||||
// Document
|
||||
const docExts = [
|
||||
'.pdf',
|
||||
'.doc',
|
||||
'.docx',
|
||||
'.odt',
|
||||
'.rtf',
|
||||
'.txt',
|
||||
'.md',
|
||||
'.tex',
|
||||
'.ppt',
|
||||
'.pptx',
|
||||
'.odp',
|
||||
'.xls',
|
||||
'.xlsx',
|
||||
'.ods',
|
||||
'.csv',
|
||||
'.tsv',
|
||||
];
|
||||
if (docExts.contains(ext)) return 'Document';
|
||||
return 'File';
|
||||
}
|
||||
|
||||
String? _selectedFilePath;
|
||||
bool _isSearching = false;
|
||||
bool _showField = false;
|
||||
@@ -992,7 +1066,7 @@ class _FileExplorerState extends State<FileExplorer> {
|
||||
subtitle: Text(
|
||||
file.type == FileType.folder
|
||||
? 'Folder'
|
||||
: 'File - ${_formatFileSize(file.size)}',
|
||||
: '${_getFileTypeLabel(file)} - ${_formatFileSize(file.size)}',
|
||||
style: const TextStyle(color: AppTheme.secondaryText),
|
||||
),
|
||||
trailing: Row(
|
||||
|
||||
Reference in New Issue
Block a user