Skip to content

Commit 333e385

Browse files
App: Add books endpoint to add image
1 parent 8505c56 commit 333e385

19 files changed

Lines changed: 457 additions & 218 deletions

File tree

school_data_hub_client/lib/src/protocol/client.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,19 @@ class EndpointBooks extends _i1.EndpointRef {
518518
{'isbn': isbn},
519519
);
520520

521+
_i2.Future<_i19.Book> updateBookImage(
522+
int isbn,
523+
String imagePath,
524+
) =>
525+
caller.callServerEndpoint<_i19.Book>(
526+
'books',
527+
'updateBookImage',
528+
{
529+
'isbn': isbn,
530+
'imagePath': imagePath,
531+
},
532+
);
533+
521534
_i2.Future<_i19.Book> updateBookTags(
522535
int isbn, {
523536
List<_i18.BookTag>? tags,

school_data_hub_flutter/lib/common/data/file_upload_service.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ class ClientFileUpload {
1313
static final _instance = ClientFileUpload.__internal();
1414
factory ClientFileUpload() => _instance;
1515

16-
static Future<({String? path, bool success})> uploadFile(
17-
File file,
18-
ServerStorageFolder folder,
19-
) async {
16+
static Future<({String? path, bool success})> uploadFile({
17+
required File file,
18+
required StorageId storageId,
19+
required ServerStorageFolder folder,
20+
}) async {
2021
final documentId = const Uuid().v4();
2122
final path = p.join(folder.name, '$documentId${p.extension(file.path)}');
2223
try {

school_data_hub_flutter/lib/common/widgets/unencrypted_image_in_card.dart

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter_hooks/flutter_hooks.dart';
5+
import 'package:school_data_hub_flutter/app_utils/create_and_crop_image_file.dart';
36
import 'package:school_data_hub_flutter/common/theme/app_colors.dart';
47
import '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';
510
import 'package:widget_zoom/widget_zoom.dart';
611

712
class 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

Comments
 (0)