Gallery/lib/full_screen_image_view.dart

62 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'data_provider/data_provider.dart';
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,
child: PageView.builder(
itemCount: widget.items.length,
controller: _controller,
pageSnapping: true,
itemBuilder: (context, pagePosition) {
return Container(
margin: const EdgeInsets.all(10),
child: Image(
image: widget.provider
.getImageProvider(widget.items[pagePosition].uri),
),
);
}),
),
),
),
);
}
}