2022-09-25 22:12:57 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2022-09-29 18:32:52 +00:00
|
|
|
import 'package:photo_view/photo_view_gallery.dart';
|
2022-09-25 22:12:57 +00:00
|
|
|
|
|
|
|
import 'data_provider/data_provider.dart';
|
2022-09-29 09:55:04 +00:00
|
|
|
import 'package:photo_view/photo_view.dart';
|
2022-09-25 22:12:57 +00:00
|
|
|
|
|
|
|
class FullScreenImageView extends StatefulWidget {
|
|
|
|
const FullScreenImageView(
|
|
|
|
{Key? key,
|
|
|
|
required this.idx,
|
|
|
|
required this.items,
|
|
|
|
required this.provider})
|
|
|
|
: super(key: key);
|
|
|
|
final int idx;
|
|
|
|
final List<Item> items;
|
|
|
|
final DataProvider provider;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<FullScreenImageView> createState() => _FullScreenImageViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _FullScreenImageViewState extends State<FullScreenImageView> {
|
|
|
|
late final PageController _controller =
|
|
|
|
PageController(initialPage: widget.idx - 1);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(title: Text(widget.items[widget.idx - 1].name)),
|
|
|
|
body: Center(
|
|
|
|
child: CallbackShortcuts(
|
|
|
|
bindings: {
|
|
|
|
const SingleActivator(LogicalKeyboardKey.arrowRight): () =>
|
|
|
|
_controller.nextPage(
|
|
|
|
duration: const Duration(milliseconds: 400),
|
|
|
|
curve: Curves.ease),
|
|
|
|
const SingleActivator(LogicalKeyboardKey.arrowLeft): () =>
|
|
|
|
_controller.previousPage(
|
|
|
|
duration: const Duration(milliseconds: 400),
|
|
|
|
curve: Curves.ease),
|
|
|
|
},
|
|
|
|
child: Focus(
|
|
|
|
autofocus: true,
|
2022-09-29 18:32:52 +00:00
|
|
|
child: PhotoViewGallery.builder(
|
|
|
|
scrollPhysics: const BouncingScrollPhysics(),
|
|
|
|
builder: (BuildContext context, int index) {
|
|
|
|
return PhotoViewGalleryPageOptions(
|
2022-09-29 19:01:28 +00:00
|
|
|
imageProvider:
|
|
|
|
widget.provider.getImageProvider(widget.items[index].uri),
|
2022-09-29 18:32:52 +00:00
|
|
|
initialScale: PhotoViewComputedScale.contained,
|
|
|
|
minScale: PhotoViewComputedScale.contained,
|
2022-09-29 19:01:28 +00:00
|
|
|
heroAttributes:
|
|
|
|
PhotoViewHeroAttributes(tag: widget.items[index].name),
|
2022-09-29 18:32:52 +00:00
|
|
|
);
|
|
|
|
},
|
2022-09-29 19:01:28 +00:00
|
|
|
itemCount: widget.items.length,
|
2022-09-29 18:32:52 +00:00
|
|
|
loadingBuilder: (context, event) => Center(
|
|
|
|
child: SizedBox(
|
|
|
|
width: 20.0,
|
|
|
|
height: 20.0,
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
value: event == null || event.expectedTotalBytes == null
|
|
|
|
? null
|
2022-09-29 19:01:28 +00:00
|
|
|
: event.cumulativeBytesLoaded /
|
|
|
|
event.expectedTotalBytes!,
|
2022-09-29 18:32:52 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
backgroundDecoration: const BoxDecoration(color: Colors.white),
|
|
|
|
pageController: _controller,
|
|
|
|
),
|
2022-09-25 22:12:57 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|