Skip to content

Commit ac5a2a3

Browse files
committed
合并图片和视频浏览器
1 parent 37544f3 commit ac5a2a3

File tree

3 files changed

+380
-7
lines changed

3 files changed

+380
-7
lines changed

file_server_fe/lib/pages/file_explorer.dart

+30-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:developer';
22
import 'dart:io';
33

44
import 'package:file_server_fe/common/env.dart';
5+
import 'package:file_server_fe/pages/media_player.dart';
56
import 'package:file_server_fe/pages/video_player.dart';
67
import 'package:file_server_fe/widgets/dir_path_widget.dart';
78
import 'package:file_server_fe/widgets/dir_tree_widget.dart';
@@ -163,6 +164,24 @@ class _FileExplorerState extends State<FileExplorer> {
163164
ImageViewer(images: imageFiles, selectedIndex: initialIndex)));
164165
}
165166

167+
void _fileClickShowMediaViewerFunc(File file) {
168+
// 弹出图片浏览
169+
var initialIndex = 0;
170+
var index = 0;
171+
var mediaFiles = files
172+
.where((item) => item.group == "image"||item.group == "video").toList();
173+
mediaFiles.sort((a, b) => a.path.compareTo(b.path));
174+
for (var item in mediaFiles) {
175+
if (item.path == file.path) {
176+
initialIndex = index;
177+
}
178+
index = index + 1;
179+
}
180+
Navigator.of(context).push(MaterialPageRoute(
181+
builder: (context) =>
182+
MediaPlayerPage(files: mediaFiles, selectedIndex: initialIndex)));
183+
}
184+
166185
void _fileClickPlayVideoFunc(File file) {
167186
// 弹出视频播放
168187
Navigator.of(context).push(MaterialPageRoute(
@@ -174,13 +193,18 @@ class _FileExplorerState extends State<FileExplorer> {
174193
if (file.group == "dir") {
175194
_fileClickChangePathFunc(file);
176195
}
177-
if (file.group == "image") {
178-
_fileClickShowImageViewerFunc(file);
179-
180-
}
181-
if (file.group == "video") {
182-
_fileClickPlayVideoFunc(file);
196+
if (file.group == "image" || file.group == "video") {
197+
// 下载文件
198+
// _fileClickDownloadFunc(file);
199+
_fileClickShowMediaViewerFunc(file);
183200
}
201+
// if (file.group == "image") {
202+
// _fileClickShowImageViewerFunc(file);
203+
204+
// }
205+
// if (file.group == "video") {
206+
// _fileClickPlayVideoFunc(file);
207+
// }
184208
}
185209
}
186210

0 commit comments

Comments
 (0)