1+ import 'dart:io' ;
2+
13import 'package:flutter/material.dart' ;
24import 'package:flutter_hooks/flutter_hooks.dart' ;
5+ import 'package:school_data_hub_flutter/app_utils/create_and_crop_image_file.dart' ;
36import 'package:school_data_hub_flutter/common/theme/app_colors.dart' ;
47import 'package:school_data_hub_flutter/common/widgets/cached_image_or_download_inage.dart' ;
8+ import 'package:school_data_hub_flutter/features/books/domain/book_manager.dart' ;
9+ import 'package:watch_it/watch_it.dart' ;
510import 'package:widget_zoom/widget_zoom.dart' ;
611
712class UnencryptedImageInCard extends HookWidget {
@@ -22,43 +27,53 @@ class UnencryptedImageInCard extends HookWidget {
2227 height: size,
2328 width: (21 / 30 ) * size,
2429 child: Center (
25- child: WidgetZoom (
26- heroAnimationTag: '$cacheKey $randomPart ' ,
27- zoomWidget: FutureBuilder <Image >(
28- future: cachedPublicImageOrDownloadPublicImage (
29- path: path,
30- cacheKey: cacheKey,
31- ),
32- builder: (context, snapshot) {
33- Widget child;
34- if (snapshot.connectionState == ConnectionState .waiting) {
35- // Display a loading indicator while the future is not complete
36- child = SizedBox (
37- height: 25 ,
38- width: 25 ,
39- child: CircularProgressIndicator (
40- strokeWidth: 5 ,
41- color: AppColors .backgroundColor,
42- ),
43- );
44- } else if (snapshot.hasError) {
45- // Display an error message if the future encounters an error
46- child = Text (
47- 'Error: ${snapshot .error }' ,
48- style: const TextStyle (color: Colors .orange),
30+ child: InkWell (
31+ onLongPress: () async {
32+ final File ? file = await createAndCropImageFile (context);
33+ if (file == null ) return ;
34+ await di <BookManager >().updateBookImage (
35+ file: file,
36+ isbn: int .tryParse (cacheKey)! ,
37+ );
38+ },
39+ child: WidgetZoom (
40+ heroAnimationTag: '$cacheKey $randomPart ' ,
41+ zoomWidget: FutureBuilder <Image >(
42+ future: cachedPublicImageOrDownloadPublicImage (
43+ path: path,
44+ cacheKey: cacheKey,
45+ ),
46+ builder: (context, snapshot) {
47+ Widget child;
48+ if (snapshot.connectionState == ConnectionState .waiting) {
49+ // Display a loading indicator while the future is not complete
50+ child = SizedBox (
51+ height: 25 ,
52+ width: 25 ,
53+ child: CircularProgressIndicator (
54+ strokeWidth: 5 ,
55+ color: AppColors .backgroundColor,
56+ ),
57+ );
58+ } else if (snapshot.hasError) {
59+ // Display an error message if the future encounters an error
60+ child = Text (
61+ 'Error: ${snapshot .error }' ,
62+ style: const TextStyle (color: Colors .orange),
63+ );
64+ } else {
65+ // Display the result when the future is complete
66+ child = ClipRRect (
67+ borderRadius: const BorderRadius .all (Radius .circular (5 )),
68+ child: snapshot.data! ,
69+ );
70+ }
71+ return AnimatedSwitcher (
72+ duration: const Duration (milliseconds: 300 ),
73+ child: child,
4974 );
50- } else {
51- // Display the result when the future is complete
52- child = ClipRRect (
53- borderRadius: const BorderRadius .all (Radius .circular (5 )),
54- child: snapshot.data! ,
55- );
56- }
57- return AnimatedSwitcher (
58- duration: const Duration (milliseconds: 300 ),
59- child: child,
60- );
61- },
75+ },
76+ ),
6277 ),
6378 ),
6479 ),
0 commit comments