1+ import 'dart:math' as math;
2+
3+ import 'package:example/src/common/constant/config.dart' ;
14import 'package:example/src/common/widget/not_found_screen.dart' ;
2- import 'package:example/src/feature/shop/model/product.dart' ;
35import 'package:example/src/feature/shop/widget/shop_scope.dart' ;
6+ import 'package:flutter/foundation.dart' ;
47import 'package:flutter/material.dart' ;
58import 'package:flutter/services.dart' ;
69import 'package:photo_view/photo_view.dart' ;
710
8- /// {@template photo_image_screen }
9- /// ProductImageViewScreen widget
11+ /// {@template photo_image_dialog }
12+ /// ProductImageDialog widget
1013/// {@endtemplate}
11- class ProductImageScreen extends StatelessWidget {
12- /// {@macro photo_image_screen }
13- const ProductImageScreen ._ ({
14+ class ProductImageDialog extends StatelessWidget {
15+ /// {@macro photo_image_dialog }
16+ const ProductImageDialog ({
1417 required this .id,
1518 required this .idx,
1619 super .key, // ignore: unused_element
@@ -22,30 +25,6 @@ class ProductImageScreen extends StatelessWidget {
2225 /// Image index in product images
2326 final Object ? idx;
2427
25- /// Show anonymous route screen
26- static Future <void > show (
27- BuildContext context, {
28- required ProductID id,
29- required int index,
30- }) {
31- final navigator = Navigator .of (context, rootNavigator: true );
32- final route = PageRouteBuilder <void >(
33- pageBuilder: (context, _, __) => BackButtonListener (
34- onBackButtonPressed: navigator.maybePop,
35- child: ProductImageScreen ._(id: id, idx: index),
36- ),
37- transitionsBuilder: (context, animation, secondayAnimation, child) =>
38- ScaleTransition (
39- scale: Tween <double >(begin: 1.25 , end: 1 ).animate (animation),
40- child: FadeTransition (
41- opacity: animation.drive (CurveTween (curve: Curves .easeIn)),
42- child: child,
43- ),
44- ),
45- );
46- return navigator.push <void >(route);
47- }
48-
4928 @override
5029 Widget build (BuildContext context) {
5130 const notFoundScreen = NotFoundScreen (
@@ -66,37 +45,53 @@ class ProductImageScreen extends StatelessWidget {
6645 };
6746 if (index == null ) return notFoundScreen;
6847 if (index < 0 || index >= product.images.length) return notFoundScreen;
69- final image = product.images[index];
48+ final image = (! kIsWeb || Config .environment.isDevelopment
49+ ? AssetImage (product.images[index])
50+ : NetworkImage ('/${product .images [index ]}' )) as ImageProvider <Object >;
7051
71- return Scaffold (
72- resizeToAvoidBottomInset: false ,
73- body: SizedBox .expand (
74- child: Stack (
75- children: < Widget > [
76- Positioned .fill (
77- child: PhotoView .customChild (
78- basePosition: Alignment .center,
79- initialScale: PhotoViewComputedScale .contained,
80- minScale: PhotoViewComputedScale .contained,
81- maxScale: 3.0 ,
82- enableRotation: false ,
83- backgroundDecoration:
84- const BoxDecoration (color: Colors .transparent),
85- child: SafeArea (
86- child: Center (
87- child: Hero (
88- tag: 'product-${product .id }-image-$index ' ,
89- child: Image .asset (
90- image,
91- fit: BoxFit .fitHeight,
52+ return Dialog (
53+ shape: const RoundedRectangleBorder (
54+ borderRadius: BorderRadius .all (Radius .circular (24 )),
55+ ),
56+ child: ClipRRect (
57+ borderRadius: const BorderRadius .all (Radius .circular (24 )),
58+ child: SizedBox .square (
59+ dimension: math.min (MediaQuery .sizeOf (context).shortestSide, 400 ),
60+ child: Stack (
61+ children: < Widget > [
62+ Positioned .fill (
63+ child: PhotoView .customChild (
64+ basePosition: Alignment .center,
65+ initialScale: PhotoViewComputedScale .contained,
66+ minScale: PhotoViewComputedScale .contained,
67+ maxScale: 3.0 ,
68+ enableRotation: false ,
69+ backgroundDecoration:
70+ const BoxDecoration (color: Colors .transparent),
71+ child: SafeArea (
72+ child: Center (
73+ child: Material (
74+ color: Colors .transparent,
75+ child: Hero (
76+ tag: 'product-${product .id }-image-$index ' ,
77+ child: Material (
78+ color: Colors .transparent,
79+ child: Image (
80+ image: image,
81+ width: 400 ,
82+ height: 400 ,
83+ fit: BoxFit .fitHeight,
84+ ),
85+ ),
86+ ),
9287 ),
9388 ),
9489 ),
9590 ),
9691 ),
97- ),
98- if ( Navigator . canPop (context)) const _ProductImageBackButton () ,
99- ] ,
92+ if ( Navigator . canPop (context)) const _ProductImageBackButton ( ),
93+ ] ,
94+ ) ,
10095 ),
10196 ),
10297 );
@@ -131,7 +126,7 @@ class _ProductImageBackButton extends StatelessWidget {
131126 },
132127 customBorder: const CircleBorder (),
133128 child: Icon (
134- Icons .fullscreen_exit ,
129+ Icons .close ,
135130 size: _isLarge ? 48 : 32 ,
136131 color: Theme .of (context).colorScheme.onSecondary,
137132 ),
0 commit comments