showImageViewer function
Shows a fullscreen image viewer.
This function pushes an ImageViewer onto the navigation stack with a fade transition and transparent background.
Example
showImageViewer(
context: context,
imageFile: File('/path/to/image.png'),
heroTag: 'unique-tag', // Optional, for hero animation
);
Returns a Future that completes when the viewer is closed.
Implementation
Future<void> showImageViewer({
required BuildContext context,
required File imageFile,
String? heroTag,
Color backgroundColor = Colors.black87,
Color closeButtonColor = Colors.black54,
Color closeIconColor = Colors.white,
double minScale = 0.5,
double maxScale = 4.0,
}) {
return Navigator.of(context).push(
PageRouteBuilder(
opaque: false,
barrierDismissible: true,
barrierColor: Colors.transparent,
pageBuilder: (context, animation, secondaryAnimation) {
return ImageViewer(
imageFile: imageFile,
heroTag: heroTag,
backgroundColor: backgroundColor,
closeButtonColor: closeButtonColor,
closeIconColor: closeIconColor,
minScale: minScale,
maxScale: maxScale,
);
},
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return FadeTransition(opacity: animation, child: child);
},
),
);
}