Skip to content

Commit c2b3fbd

Browse files
committed
Update example
1 parent c1c8d8e commit c2b3fbd

File tree

1 file changed

+116
-115
lines changed

1 file changed

+116
-115
lines changed

examples/flyer_chat/lib/local.dart

Lines changed: 116 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -423,129 +423,130 @@ class LocalState extends State<Local> {
423423
Navigator.pop(context);
424424
// Uncomment to use picker instead of hardcoding the video url
425425

426-
final picker = ImagePicker();
427-
final result = await picker.pickVideo(
428-
source: ImageSource.gallery,
429-
);
426+
// final picker = ImagePicker();
427+
// final result = await picker.pickVideo(
428+
// source: ImageSource.gallery,
429+
// );
430430

431-
if (result != null) {
432-
String? thumbHash;
433-
int? width;
434-
int? height;
435-
int? fileSizeInBytes;
436-
try {
437-
// Optionally get the file size
438-
fileSizeInBytes = await result.length();
439-
440-
// Get the video width and height
441-
final fullSizeimageBytes =
442-
await VideoThumbnail.thumbnailData(
443-
video: result.path,
444-
imageFormat: ImageFormat.WEBP,
445-
quality: 1,
446-
);
447-
448-
final fullSizedecoded = img.decodeImage(
449-
fullSizeimageBytes!,
450-
);
451-
if (fullSizedecoded != null) {
452-
width = fullSizedecoded.width;
453-
height = fullSizedecoded.height;
454-
}
455-
456-
// Generate the thumbhash
457-
final thumbSizeImageBytes =
458-
await VideoThumbnail.thumbnailData(
459-
video: result.path,
460-
imageFormat: ImageFormat.WEBP,
461-
maxWidth: 100,
462-
maxHeight: 100,
463-
quality: 25,
464-
);
465-
final decoded = img.decodeImage(thumbSizeImageBytes!);
466-
if (decoded != null) {
467-
final thumbHashBytes = rgbaToThumbHash(
468-
decoded.width,
469-
decoded.height,
470-
decoded.getBytes(),
471-
);
431+
// if (result != null) {
432+
// String? thumbHash;
433+
// int? width;
434+
// int? height;
435+
// int? fileSizeInBytes;
436+
// try {
437+
// // Optionally get the file size
438+
// fileSizeInBytes = await result.length();
439+
440+
// // Get the video width and height
441+
// final fullSizeimageBytes =
442+
// await VideoThumbnail.thumbnailData(
443+
// video: result.path,
444+
// imageFormat: ImageFormat.WEBP,
445+
// quality: 1,
446+
// );
447+
448+
// final fullSizedecoded = img.decodeImage(
449+
// fullSizeimageBytes!,
450+
// );
451+
// if (fullSizedecoded != null) {
452+
// width = fullSizedecoded.width;
453+
// height = fullSizedecoded.height;
454+
// }
455+
456+
// // Generate the thumbhash
457+
// final thumbSizeImageBytes =
458+
// await VideoThumbnail.thumbnailData(
459+
// video: result.path,
460+
// imageFormat: ImageFormat.WEBP,
461+
// maxWidth: 100,
462+
// maxHeight: 100,
463+
// quality: 25,
464+
// );
465+
// final decoded = img.decodeImage(thumbSizeImageBytes!);
466+
// if (decoded != null) {
467+
// final thumbHashBytes = rgbaToThumbHash(
468+
// decoded.width,
469+
// decoded.height,
470+
// decoded.getBytes(),
471+
// );
472472

473-
thumbHash = base64.encode(thumbHashBytes);
474-
}
475-
} catch (e) {
476-
debugPrint(e.toString());
477-
}
473+
// thumbHash = base64.encode(thumbHashBytes);
474+
// }
475+
// } catch (e) {
476+
// debugPrint(e.toString());
477+
// }
478478

479-
// Create a proper file message
480-
final videoMessage = VideoMessage(
481-
id: _uuid.v4(),
482-
authorId: _currentUser.id,
483-
createdAt: DateTime.now().toUtc(),
484-
sentAt: DateTime.now().toUtc(),
485-
source: result.path,
486-
thumbhash: thumbHash,
487-
width: width?.toDouble(),
488-
height: height?.toDouble(),
489-
size: fileSizeInBytes,
490-
);
491-
await _chatController.insertMessage(videoMessage);
492-
}
479+
// // Create a proper file message
480+
// final videoMessage = VideoMessage(
481+
// id: _uuid.v4(),
482+
// authorId: _currentUser.id,
483+
// createdAt: DateTime.now().toUtc(),
484+
// sentAt: DateTime.now().toUtc(),
485+
// source: result.path,
486+
// thumbhash: thumbHash,
487+
// width: width?.toDouble(),
488+
// height: height?.toDouble(),
489+
// size: fileSizeInBytes,
490+
// );
491+
// await _chatController.insertMessage(videoMessage);
492+
// }
493493

494-
// const videoUrl =
495-
// 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4';
496-
// String? thumbHash;
497-
// int? width;
498-
// int? height;
499-
// try {
500-
// // Get the video width and height
501-
// final fullSizeimageBytes =
502-
// await VideoThumbnail.thumbnailData(
503-
// video: videoUrl,
504-
// imageFormat: ImageFormat.WEBP,
505-
// quality: 1,
506-
// );
494+
const videoUrl =
495+
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4';
496+
String? thumbHash;
497+
int? width;
498+
int? height;
499+
try {
500+
// Get the video width and height
501+
// iOS/ Android ONLY
502+
final fullSizeimageBytes =
503+
await VideoThumbnail.thumbnailData(
504+
video: videoUrl,
505+
imageFormat: ImageFormat.WEBP,
506+
quality: 1,
507+
);
507508

508-
// final fullSizedecoded = img.decodeImage(
509-
// fullSizeimageBytes!,
510-
// );
511-
// if (fullSizedecoded != null) {
512-
// width = fullSizedecoded.width;
513-
// height = fullSizedecoded.height;
514-
// }
509+
final fullSizedecoded = img.decodeImage(
510+
fullSizeimageBytes!,
511+
);
512+
if (fullSizedecoded != null) {
513+
width = fullSizedecoded.width;
514+
height = fullSizedecoded.height;
515+
}
515516

516-
// // Generate the thumbhash
517-
// final thumbSizeImageBytes =
518-
// await VideoThumbnail.thumbnailData(
519-
// video: videoUrl,
520-
// imageFormat: ImageFormat.WEBP,
521-
// maxWidth: 100,
522-
// maxHeight: 100,
523-
// quality: 25,
524-
// );
525-
// final decoded = img.decodeImage(thumbSizeImageBytes!);
526-
// if (decoded != null) {
527-
// final thumbHashBytes = rgbaToThumbHash(
528-
// decoded.width,
529-
// decoded.height,
530-
// decoded.getBytes(),
531-
// );
517+
// Generate the thumbhash
518+
final thumbSizeImageBytes =
519+
await VideoThumbnail.thumbnailData(
520+
video: videoUrl,
521+
imageFormat: ImageFormat.WEBP,
522+
maxWidth: 100,
523+
maxHeight: 100,
524+
quality: 25,
525+
);
526+
final decoded = img.decodeImage(thumbSizeImageBytes!);
527+
if (decoded != null) {
528+
final thumbHashBytes = rgbaToThumbHash(
529+
decoded.width,
530+
decoded.height,
531+
decoded.getBytes(),
532+
);
532533

533-
// thumbHash = base64.encode(thumbHashBytes);
534-
// }
535-
// } catch (e) {
536-
// debugPrint(e.toString());
537-
// }
534+
thumbHash = base64.encode(thumbHashBytes);
535+
}
536+
} catch (e) {
537+
debugPrint(e.toString());
538+
}
538539

539-
// final videoMessage = VideoMessage(
540-
// id: _uuid.v4(),
541-
// authorId: _currentUser.id,
542-
// createdAt: DateTime.now().toUtc(),
543-
// source: videoUrl,
544-
// thumbhash: thumbHash,
545-
// width: width?.toDouble(),
546-
// height: height?.toDouble(),
547-
// );
548-
// await _chatController.insertMessage(videoMessage);
540+
final videoMessage = VideoMessage(
541+
id: _uuid.v4(),
542+
authorId: _currentUser.id,
543+
createdAt: DateTime.now().toUtc(),
544+
source: videoUrl,
545+
thumbhash: thumbHash,
546+
width: width?.toDouble(),
547+
height: height?.toDouble(),
548+
);
549+
await _chatController.insertMessage(videoMessage);
549550
},
550551
),
551552
],

0 commit comments

Comments
 (0)