@@ -4,15 +4,15 @@ import 'dart:math';
4
4
import 'package:extended_image/extended_image.dart' ;
5
5
import 'package:flutter/material.dart' ;
6
6
import 'package:flutter/services.dart' ;
7
+ import 'package:flutter_picgo/model/uploaded.dart' ;
7
8
import 'package:flutter_picgo/utils/extended.dart' ;
8
9
import 'package:toast/toast.dart' ;
9
10
10
11
class ImagePreviewUtils {
11
12
/// 打开图片预览页面
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) {
14
14
var page = GalleryPhotoViewWrapper (
15
- galleryItems: [item ],
15
+ galleryItems: [content ],
16
16
);
17
17
Navigator .push (
18
18
context,
@@ -22,8 +22,7 @@ class ImagePreviewUtils {
22
22
);
23
23
}
24
24
25
- static void openMulti (
26
- BuildContext context, int index, List <GalleryItem > items) {
25
+ static void openMulti (BuildContext context, int index, List <Uploaded > items) {
27
26
var page = GalleryPhotoViewWrapper (
28
27
galleryItems: items,
29
28
initialIndex: index,
@@ -36,16 +35,9 @@ class ImagePreviewUtils {
36
35
}
37
36
}
38
37
39
- class GalleryItem {
40
- GalleryItem ({this .id, this .resource});
41
-
42
- final String id;
43
- final String resource;
44
- }
45
-
46
38
class GalleryPhotoViewWrapper extends StatefulWidget {
47
39
final int initialIndex;
48
- final List <GalleryItem > galleryItems;
40
+ final List <Uploaded > galleryItems;
49
41
50
42
GalleryPhotoViewWrapper ({
51
43
this .initialIndex = 0 ,
@@ -85,44 +77,67 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
85
77
color: Colors .black,
86
78
pageGestureAxis: SlideAxis .both),
87
79
child: GestureDetector (
88
- child: ExtendedImageGesturePageView .builder (
89
- itemBuilder: (BuildContext context, int index) {
90
- var item = widget.galleryItems[index];
91
- Widget image = item.resource.startsWith ('http' )
92
- ? ExtendedImage .network (
93
- item.resource,
94
- fit: BoxFit .contain,
95
- cache: true ,
96
- mode: ExtendedImageMode .gesture,
97
- enableSlideOutPage: true ,
98
- loadStateChanged: (state) =>
99
- defaultLoadStateChanged (state, iconSize: 50 ),
100
- )
101
- : ExtendedImage .file (
102
- File (item.resource),
103
- fit: BoxFit .contain,
104
- mode: ExtendedImageMode .gesture,
105
- enableSlideOutPage: true ,
106
- loadStateChanged: (state) =>
107
- defaultLoadStateChanged (state, iconSize: 50 ),
80
+ child: Stack (
81
+ // fit: StackFit.expand,
82
+ alignment: Alignment .bottomRight,
83
+ children: [
84
+ ExtendedImageGesturePageView .builder (
85
+ itemBuilder: (BuildContext context, int index) {
86
+ var item = widget.galleryItems[index];
87
+ Widget image = item.path.startsWith ('http' )
88
+ ? ExtendedImage .network (
89
+ item.path,
90
+ fit: BoxFit .contain,
91
+ cache: true ,
92
+ mode: ExtendedImageMode .gesture,
93
+ enableSlideOutPage: true ,
94
+ loadStateChanged: (state) =>
95
+ defaultLoadStateChanged (state, iconSize: 50 ),
96
+ )
97
+ : ExtendedImage .file (
98
+ File (item.path),
99
+ fit: BoxFit .contain,
100
+ mode: ExtendedImageMode .gesture,
101
+ enableSlideOutPage: true ,
102
+ loadStateChanged: (state) =>
103
+ defaultLoadStateChanged (state, iconSize: 50 ),
104
+ );
105
+ image = Container (
106
+ child: image,
107
+ );
108
+ if (index == currentIndex) {
109
+ return Hero (
110
+ tag: index,
111
+ child: image,
108
112
);
109
- image = Container (
110
- child: image,
111
- );
112
- if (index == currentIndex) {
113
- return Hero (
114
- tag: index,
115
- child: image,
116
- );
117
- } else {
118
- return image;
119
- }
120
- },
121
- itemCount: widget.galleryItems.length,
122
- controller: PageController (
123
- initialPage: currentIndex,
124
- ),
125
- scrollDirection: Axis .horizontal,
113
+ } else {
114
+ return image;
115
+ }
116
+ },
117
+ itemCount: widget.galleryItems.length,
118
+ controller: PageController (
119
+ initialPage: currentIndex,
120
+ ),
121
+ onPageChanged: onPageChanged,
122
+ scrollDirection: Axis .horizontal,
123
+ ),
124
+ SafeArea (
125
+ child: Container (
126
+ margin: EdgeInsets .only (right: 10 ),
127
+ decoration: BoxDecoration (
128
+ borderRadius: BorderRadius .all (Radius .circular (4 )),
129
+ color: Colors .grey),
130
+ padding: EdgeInsets .fromLTRB (5 , 2 , 5 , 2 ),
131
+ child: Text (
132
+ '${currentIndex + 1 } / ${widget .galleryItems .length }' ,
133
+ style: TextStyle (
134
+ color: Colors .white,
135
+ decoration: TextDecoration .none,
136
+ fontWeight: FontWeight .normal,
137
+ fontSize: 10 ),
138
+ ),
139
+ ))
140
+ ],
126
141
),
127
142
onLongPress: () {
128
143
_showBottomPane ();
@@ -142,9 +157,41 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
142
157
mainAxisSize: MainAxisSize .min,
143
158
children: [
144
159
ListTile (
145
- title: Text ('复制链接' ),
160
+ title: Text (
161
+ '图床类型' ,
162
+ style: TextStyle (fontWeight: FontWeight .bold),
163
+ ),
164
+ subtitle: Text (widget.galleryItems[currentIndex].type),
165
+ ),
166
+ ListTile (
167
+ title: Text (
168
+ '图片链接' ,
169
+ style: TextStyle (fontWeight: FontWeight .bold),
170
+ ),
171
+ subtitle: Text (widget.galleryItems[currentIndex].path),
172
+ onTap: () {
173
+ _handleCopy (
174
+ widget.galleryItems[currentIndex].path, context);
175
+ },
176
+ ),
177
+ ListTile (
178
+ title: Text (
179
+ '图片信息' ,
180
+ style: TextStyle (fontWeight: FontWeight .bold),
181
+ ),
182
+ subtitle: Text (widget.galleryItems[currentIndex].info),
183
+ onTap: () {
184
+ _handleCopy (
185
+ widget.galleryItems[currentIndex].info, context);
186
+ },
187
+ ),
188
+ ListTile (
189
+ title: Text (
190
+ '取消' ,
191
+ style: TextStyle (fontWeight: FontWeight .bold),
192
+ ),
146
193
onTap: () {
147
- _handleCopy (context);
194
+ Navigator . pop (context);
148
195
},
149
196
),
150
197
],
@@ -154,9 +201,8 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
154
201
}
155
202
156
203
/// 复制链接
157
- _handleCopy (BuildContext context) {
158
- Clipboard .setData (
159
- ClipboardData (text: widget.galleryItems[currentIndex].resource));
204
+ _handleCopy (String content, BuildContext context) {
205
+ Clipboard .setData (ClipboardData (text: content));
160
206
Toast .show ('已复制到剪切板' , context);
161
207
Navigator .pop (context);
162
208
}
0 commit comments