-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(viewer) Split viewer to vertical and horizontal
- Loading branch information
1 parent
a04822c
commit 7631e5e
Showing
7 changed files
with
132 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This source code is a part of Project Violet. | ||
// Copyright (C) 2020. violet-team. Licensed under the MIT License. | ||
|
||
// Reference https://github.com/rollrat/downloader/blob/master/Koromo_Copy.Framework/Extractor/PixivExtractor.cs |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// This source code is a part of Project Violet. | ||
// Copyright (C) 2020. violet-team. Licensed under the MIT License. | ||
|
||
class GalleryExampleItem { | ||
GalleryExampleItem({ | ||
this.id, | ||
this.url, | ||
this.headers, | ||
this.isSvg = false, | ||
this.loaded = false, | ||
}); | ||
|
||
final String id; | ||
final String url; | ||
final Map<String, String> headers; | ||
final bool isSvg; | ||
double height; | ||
bool loaded; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// This source code is a part of Project Violet. | ||
// Copyright (C) 2020. violet-team. Licensed under the MIT License. | ||
|
||
import 'package:cached_network_image/cached_network_image.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:photo_view/photo_view.dart'; | ||
import 'package:photo_view/photo_view_gallery.dart'; | ||
import 'package:violet/settings.dart'; | ||
import 'package:violet/pages/viewer/gallery_item.dart'; | ||
|
||
class GalleryPhotoViewWrapper extends StatefulWidget { | ||
GalleryPhotoViewWrapper({ | ||
this.loadingBuilder, | ||
this.backgroundDecoration, | ||
this.initialIndex, | ||
@required this.galleryItems, | ||
this.totalPage, | ||
this.scrollDirection = Axis.horizontal, | ||
}) : pageController = PageController(initialPage: initialIndex); | ||
|
||
final LoadingBuilder loadingBuilder; | ||
final Decoration backgroundDecoration; | ||
final int initialIndex; | ||
final PageController pageController; | ||
final List<GalleryExampleItem> galleryItems; | ||
final Axis scrollDirection; | ||
final int totalPage; | ||
int currentIndex; | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return _GalleryPhotoViewWrapperState(); | ||
} | ||
} | ||
|
||
class _GalleryPhotoViewWrapperState extends State<GalleryPhotoViewWrapper> { | ||
@override | ||
void initState() { | ||
widget.currentIndex = widget.initialIndex; | ||
super.initState(); | ||
} | ||
|
||
void onPageChanged(int index) { | ||
setState(() { | ||
widget.currentIndex = index; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
body: Container( | ||
decoration: widget.backgroundDecoration, | ||
constraints: BoxConstraints.expand( | ||
height: MediaQuery.of(context).size.height, | ||
), | ||
child: Stack( | ||
alignment: Alignment.bottomRight, | ||
children: <Widget>[ | ||
PhotoViewGallery.builder( | ||
scrollPhysics: const BouncingScrollPhysics(), | ||
builder: _buildItem, | ||
itemCount: widget.galleryItems.length, | ||
loadingBuilder: widget.loadingBuilder, | ||
backgroundDecoration: widget.backgroundDecoration, | ||
pageController: widget.pageController, | ||
onPageChanged: onPageChanged, | ||
scrollDirection: widget.scrollDirection, | ||
reverse: Settings.rightToLeft, | ||
), | ||
Container( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Text( | ||
"${widget.currentIndex + 1}/${widget.totalPage}", | ||
style: const TextStyle( | ||
color: Colors.white, | ||
fontSize: 14.0, | ||
decoration: null, | ||
), | ||
), | ||
) | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
PhotoViewGalleryPageOptions _buildItem(BuildContext context, int index) { | ||
final GalleryExampleItem item = widget.galleryItems[index]; | ||
return PhotoViewGalleryPageOptions( | ||
imageProvider: CachedNetworkImageProvider( | ||
item.url, | ||
headers: item.headers, | ||
//(context, url) => Image.file(File('assets/images/loading.gif')), | ||
), | ||
// NetworkImage(item.url, headers: item.headers), | ||
initialScale: PhotoViewComputedScale.contained, | ||
//minScale: PhotoViewComputedScale.contained * (0.5 + index / 10), | ||
//maxScale: PhotoViewComputedScale.covered * 1.1, | ||
minScale: PhotoViewComputedScale.contained * 1.0, | ||
maxScale: PhotoViewComputedScale.contained * 5.0, | ||
heroAttributes: PhotoViewHeroAttributes(tag: item.id), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters