Sonnat Project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/material.dart';
  3. class ShowImageWidget extends StatelessWidget {
  4. final String imageUrl;
  5. final _transformationController = TransformationController();
  6. late TapDownDetails _doubleTapDetails;
  7. ShowImageWidget(this.imageUrl, {super.key});
  8. @override
  9. Widget build(BuildContext context) {
  10. return Scaffold(
  11. backgroundColor: Colors.black,
  12. appBar: AppBar(
  13. leading: GestureDetector(
  14. child: const Icon(Icons.close, color: Colors.white),
  15. onTap: () {
  16. Navigator.pop(context);
  17. },
  18. ),
  19. backgroundColor: Colors.black,
  20. elevation: 0,
  21. ),
  22. body: Center(
  23. child: GestureDetector(
  24. onScaleUpdate: (ScaleUpdateDetails details) {},
  25. onDoubleTap: _handleDoubleTap,
  26. onDoubleTapDown: _handleDoubleTapDown,
  27. child: InteractiveViewer(
  28. minScale: 0.5,
  29. maxScale: 20,
  30. panEnabled: false,
  31. transformationController: _transformationController,
  32. child: Container(
  33. height: MediaQuery.of(context).size.height,
  34. alignment: Alignment.center,
  35. child: CachedNetworkImage(
  36. imageUrl: imageUrl,
  37. fit: BoxFit.fill,
  38. ),
  39. ),
  40. ),
  41. ),
  42. ),
  43. );
  44. }
  45. void _handleDoubleTapDown(TapDownDetails details) {
  46. _doubleTapDetails = details;
  47. }
  48. void _handleDoubleTap() {
  49. if (_transformationController.value != Matrix4.identity()) {
  50. _transformationController.value = Matrix4.identity();
  51. } else {
  52. final position = _doubleTapDetails.localPosition;
  53. _transformationController.value = Matrix4.identity()
  54. ..translate(-position.dx * 2, -position.dy * 2)
  55. ..scale(4.0);
  56. }
  57. }
  58. }