@@ -4,15 +4,15 @@ import 'dart:math';
44import 'package:extended_image/extended_image.dart' ;
55import 'package:flutter/material.dart' ;
66import 'package:flutter/services.dart' ;
7+ import 'package:flutter_picgo/model/uploaded.dart' ;
78import 'package:flutter_picgo/utils/extended.dart' ;
89import 'package:toast/toast.dart' ;
910
1011class 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-
4638class GalleryPhotoViewWrapper extends StatefulWidget {
4739 final int initialIndex;
48- final List <GalleryItem > galleryItems;
40+ final List <Uploaded > galleryItems;
4941
5042 GalleryPhotoViewWrapper ({
5143 this .initialIndex = 0 ,
@@ -85,44 +77,67 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
8577 color: Colors .black,
8678 pageGestureAxis: SlideAxis .both),
8779 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,
108112 );
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+ ],
126141 ),
127142 onLongPress: () {
128143 _showBottomPane ();
@@ -142,9 +157,41 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
142157 mainAxisSize: MainAxisSize .min,
143158 children: [
144159 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+ ),
146193 onTap: () {
147- _handleCopy (context);
194+ Navigator . pop (context);
148195 },
149196 ),
150197 ],
@@ -154,9 +201,8 @@ class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> {
154201 }
155202
156203 /// 复制链接
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));
160206 Toast .show ('已复制到剪切板' , context);
161207 Navigator .pop (context);
162208 }
0 commit comments