@@ -380,30 +380,17 @@ class MessageImage extends StatelessWidget {
380
380
final resolvedSrc = store.tryResolveUrl (src);
381
381
// TODO if src fails to parse, show an explicit "broken image"
382
382
383
- return GestureDetector (
383
+ return MessageMediaPreview (
384
384
onTap: resolvedSrc == null ? null : () { // TODO(log)
385
385
Navigator .of (context).push (getLightboxRoute (
386
386
context: context, message: message, src: resolvedSrc));
387
387
},
388
- child: UnconstrainedBox (
389
- alignment: Alignment .centerLeft,
390
- child: Padding (
391
- // TODO clean up this padding by imitating web less precisely;
392
- // in particular, avoid adding loose whitespace at end of message.
393
- padding: const EdgeInsets .only (right: 5 , bottom: 5 ),
394
- child: ColoredBox (
395
- color: const Color .fromRGBO (0 , 0 , 0 , 0.03 ),
396
- child: Padding (
397
- padding: const EdgeInsets .all (1 ),
398
- child: SizedBox (
399
- height: 100 ,
400
- width: 150 ,
401
- child: resolvedSrc == null ? null : LightboxHero (
402
- message: message,
403
- src: resolvedSrc,
404
- child: RealmContentNetworkImage (
405
- resolvedSrc,
406
- filterQuality: FilterQuality .medium))))))));
388
+ child: resolvedSrc == null ? null : LightboxHero (
389
+ message: message,
390
+ src: resolvedSrc,
391
+ child: RealmContentNetworkImage (
392
+ resolvedSrc,
393
+ filterQuality: FilterQuality .medium)));
407
394
}
408
395
}
409
396
@@ -435,7 +422,7 @@ class _MessageInlineVideoState extends State<MessageInlineVideo> {
435
422
Future <void > _initialize () async {
436
423
try {
437
424
final store = PerAccountStoreWidget .of (context);
438
- // _resolvedSrcUrl = store.tryResolveUrl(widget.node.srcUrl);
425
+ _resolvedSrcUrl = store.tryResolveUrl (widget.node.srcUrl);
439
426
if (_resolvedSrcUrl == null ) {
440
427
return ; // TODO(log)
441
428
}
@@ -480,7 +467,7 @@ class _MessageInlineVideoState extends State<MessageInlineVideo> {
480
467
Widget build (BuildContext context) {
481
468
final message = InheritedMessage .of (context);
482
469
483
- return GestureDetector (
470
+ return MessageMediaPreview (
484
471
onTap: ! _didAttemptInitialization
485
472
? null
486
473
: () { // TODO(log)
@@ -503,43 +490,33 @@ class _MessageInlineVideoState extends State<MessageInlineVideo> {
503
490
));
504
491
}
505
492
},
506
- child: UnconstrainedBox (
507
- alignment: Alignment .centerLeft,
508
- child: Padding (
509
- // TODO clean up this padding by imitating web less precisely;
510
- // in particular, avoid adding loose whitespace at end of message.
511
- padding: const EdgeInsets .only (right: 5 , bottom: 5 ),
512
- child: Container (
513
- height: 100 ,
514
- width: 150 ,
515
- color: Colors .black,
516
- child: ! _didAttemptInitialization
517
- ? Container (
518
- color: Colors .black,
519
- child: const Center (
520
- child: SizedBox (
521
- height: 16 ,
522
- width: 16 ,
523
- child: CircularProgressIndicator (
524
- color: Colors .white,
525
- strokeWidth: 2 ))))
526
- : Stack (
527
- alignment: Alignment .center,
528
- children: [
529
- if (_resolvedSrcUrl == null || _controller! .value.hasError)
530
- Container (color: Colors .black)
531
- else
532
- LightboxHero (
533
- message: message,
534
- src: _resolvedSrcUrl! ,
535
- child: AspectRatio (
536
- aspectRatio: _controller! .value.aspectRatio,
537
- child: VideoPlayer (_controller! ))),
538
- const Icon (
539
- Icons .play_arrow_rounded,
540
- color: Colors .white,
541
- size: 32 )
542
- ])))));
493
+ child: ! _didAttemptInitialization
494
+ ? Container (
495
+ color: Colors .black,
496
+ child: const Center (
497
+ child: SizedBox (
498
+ height: 16 ,
499
+ width: 16 ,
500
+ child: CircularProgressIndicator (
501
+ color: Colors .white,
502
+ strokeWidth: 2 ))))
503
+ : Stack (
504
+ alignment: Alignment .center,
505
+ children: [
506
+ if (_resolvedSrcUrl == null || _controller! .value.hasError)
507
+ Container (color: Colors .black)
508
+ else
509
+ LightboxHero (
510
+ message: message,
511
+ src: _resolvedSrcUrl! ,
512
+ child: AspectRatio (
513
+ aspectRatio: _controller! .value.aspectRatio,
514
+ child: VideoPlayer (_controller! ))),
515
+ const Icon (
516
+ Icons .play_arrow_rounded,
517
+ color: Colors .white,
518
+ size: 32 )
519
+ ]));
543
520
}
544
521
}
545
522
@@ -555,30 +532,51 @@ class MessageEmbedVideo extends StatelessWidget {
555
532
final store = PerAccountStoreWidget .of (context);
556
533
final previewImageSrcUrl = store.tryResolveUrl (node.previewImageSrcUrl);
557
534
558
- return GestureDetector (
535
+ return MessageMediaPreview (
559
536
onTap: () => _launchUrl (context, node.hrefUrl),
537
+ child: Stack (
538
+ alignment: Alignment .center,
539
+ children: [
540
+ if (previewImageSrcUrl != null )
541
+ RealmContentNetworkImage (
542
+ previewImageSrcUrl,
543
+ filterQuality: FilterQuality .medium),
544
+ const Icon (
545
+ Icons .play_arrow_rounded,
546
+ color: Colors .white,
547
+ size: 32 ),
548
+ ]));
549
+ }
550
+ }
551
+
552
+ class MessageMediaPreview extends StatelessWidget {
553
+ const MessageMediaPreview ({
554
+ super .key,
555
+ required this .onTap,
556
+ required this .child,
557
+ });
558
+
559
+ final void Function ()? onTap;
560
+ final Widget ? child;
561
+
562
+ @override
563
+ Widget build (BuildContext context) {
564
+ return GestureDetector (
565
+ onTap: onTap,
560
566
child: UnconstrainedBox (
561
567
alignment: Alignment .centerLeft,
562
568
child: Padding (
563
569
// TODO clean up this padding by imitating web less precisely;
564
570
// in particular, avoid adding loose whitespace at end of message.
565
571
padding: const EdgeInsets .only (right: 5 , bottom: 5 ),
566
- child: Container (
567
- height: 100 ,
568
- width: 150 ,
569
- color: Colors .black,
570
- child: Stack (
571
- alignment: Alignment .center,
572
- children: [
573
- if (previewImageSrcUrl != null )
574
- RealmContentNetworkImage (
575
- previewImageSrcUrl,
576
- filterQuality: FilterQuality .medium),
577
- const Icon (
578
- Icons .play_arrow_rounded,
579
- color: Colors .white,
580
- size: 32 ),
581
- ])))));
572
+ child: ColoredBox (
573
+ color: const Color .fromRGBO (0 , 0 , 0 , 0.03 ),
574
+ child: Padding (
575
+ padding: const EdgeInsets .all (1 ),
576
+ child: SizedBox (
577
+ height: 100 ,
578
+ width: 150 ,
579
+ child: child))))));
582
580
}
583
581
}
584
582
0 commit comments