Skip to content

Commit a9b70bc

Browse files
committed
refactor:remove GalleryItem class,using Uploaded class
1 parent 9680e16 commit a9b70bc

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

lib/utils/image_preview.dart

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import 'dart:math';
44
import 'package:extended_image/extended_image.dart';
55
import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
7+
import 'package:flutter_picgo/model/uploaded.dart';
78
import 'package:flutter_picgo/utils/extended.dart';
89
import 'package:toast/toast.dart';
910

1011
class ImagePreviewUtils {
1112
/// 打开图片预览页面
12-
static void open(BuildContext context, String content) {
13-
var item = new GalleryItem(id: '0', resource: '$content');
13+
static void open(BuildContext context, Uploaded content) {
1414
var page = GalleryPhotoViewWrapper(
15-
galleryItems: [item],
15+
galleryItems: [content],
1616
);
1717
Navigator.push(
1818
context,
@@ -22,8 +22,7 @@ class ImagePreviewUtils {
2222
);
2323
}
2424

25-
static void openMulti(
26-
BuildContext context, int index, List<GalleryItem> items) {
25+
static void openMulti(BuildContext context, int index, List<Uploaded> items) {
2726
var page = GalleryPhotoViewWrapper(
2827
galleryItems: items,
2928
initialIndex: index,
@@ -36,16 +35,9 @@ class ImagePreviewUtils {
3635
}
3736
}
3837

39-
class GalleryItem {
40-
GalleryItem({this.id, this.resource});
41-
42-
final String id;
43-
final String resource;
44-
}
45-
4638
class GalleryPhotoViewWrapper extends StatefulWidget {
4739
final int initialIndex;
48-
final List<GalleryItem> galleryItems;
40+
final List<Uploaded> galleryItems;
4941

5042
GalleryPhotoViewWrapper({
5143
this.initialIndex = 0,
@@ -88,9 +80,9 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
8880
child: ExtendedImageGesturePageView.builder(
8981
itemBuilder: (BuildContext context, int index) {
9082
var item = widget.galleryItems[index];
91-
Widget image = item.resource.startsWith('http')
83+
Widget image = item.path.startsWith('http')
9284
? ExtendedImage.network(
93-
item.resource,
85+
item.path,
9486
fit: BoxFit.contain,
9587
cache: true,
9688
mode: ExtendedImageMode.gesture,
@@ -99,7 +91,7 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
9991
defaultLoadStateChanged(state, iconSize: 50),
10092
)
10193
: ExtendedImage.file(
102-
File(item.resource),
94+
File(item.path),
10395
fit: BoxFit.contain,
10496
mode: ExtendedImageMode.gesture,
10597
enableSlideOutPage: true,
@@ -156,7 +148,7 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
156148
/// 复制链接
157149
_handleCopy(BuildContext context) {
158150
Clipboard.setData(
159-
ClipboardData(text: widget.galleryItems[currentIndex].resource));
151+
ClipboardData(text: widget.galleryItems[currentIndex].path));
160152
Toast.show('已复制到剪切板', context);
161153
Navigator.pop(context);
162154
}

lib/views/album_page/album_page.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,7 @@ class _AlbumPageState extends State<AlbumPage> implements AlbumPageContract {
197197

198198
/// 处理图片点击事件
199199
handleTap(int index) {
200-
ImagePreviewUtils.openMulti(
201-
context,
202-
index,
203-
_uploadeds.map((e) {
204-
return GalleryItem(id: e.id.toString(), resource: e.path);
205-
}).toList());
200+
ImagePreviewUtils.openMulti(context, index, _uploadeds);
206201
}
207202

208203
/// 处理图片双击

0 commit comments

Comments
 (0)