Skip to content

Commit

Permalink
✨ two page gallery save images
Browse files Browse the repository at this point in the history
  • Loading branch information
niuhuan committed Aug 29, 2024
1 parent 850289d commit 257fb9b
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions lib/screens/components/ImageReader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1930,7 +1930,10 @@ class _TwoPageGalleryReaderState extends _ImageReaderContentState {
Widget _buildViewer() {
return Stack(
children: [
_view,
GestureDetector(
onLongPress: _onLongPress,
child: _view,
),
_buildNextEpController(),
],
);
Expand Down Expand Up @@ -1959,7 +1962,7 @@ class _TwoPageGalleryReaderState extends _ImageReaderContentState {
child: Container(
margin: const EdgeInsets.only(bottom: 10),
padding:
const EdgeInsets.only(left: 10, right: 10, top: 4, bottom: 4),
const EdgeInsets.only(left: 10, right: 10, top: 4, bottom: 4),
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
Expand All @@ -1984,6 +1987,41 @@ class _TwoPageGalleryReaderState extends _ImageReaderContentState {
),
);
}

Future _onLongPress() async {
List<ReaderImageInfo> matchImages = [];
if (_current >= 0 && _current < widget.struct.images.length) {
var item = widget.struct.images[_current];
if (item.pkzFile != null) {
return;
}
matchImages.add(item);
}
if (_current + 1 >= 0 && _current + 1 < widget.struct.images.length) {
var item = widget.struct.images[_current + 1];
if (item.pkzFile != null) {
return;
}
matchImages.add(item);
}
if (matchImages.isEmpty) {
return;
}
String? choose = await chooseListDialog(context, '请选择', ['保存本页的图片']);
switch (choose) {
case '保存本页的图片':
for (var item in matchImages) {
if (item.downloadLocalPath != null) {
var file = await method.downloadImagePath(item.downloadLocalPath!);
saveImage(file, context);
} else {
var data = await method.remoteImageData(item.fileServer, item.path);
saveImage(data.finalPath, context);
}
}
break;
}
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 257fb9b

Please sign in to comment.