refs #21: fix video aspect ratio

This commit is contained in:
Salvatore Giordano
2020-04-10 11:00:55 +02:00
parent e549ae89f7
commit 092fed6fdd
+49 -34
View File
@@ -39,6 +39,7 @@ class MessageWidget extends StatefulWidget {
this.isParent = false, this.isParent = false,
this.onMentionTap, this.onMentionTap,
this.showOtherMessageUsername = false, this.showOtherMessageUsername = false,
this.showVideoFullScreen = true,
}) : super(key: key); }) : super(key: key);
/// Function called on mention tap /// Function called on mention tap
@@ -65,6 +66,9 @@ class MessageWidget extends StatefulWidget {
/// True if this is the parent of the thread being showed /// True if this is the parent of the thread being showed
final bool isParent; final bool isParent;
/// True if the video player will allow fullscreen mode
final bool showVideoFullScreen;
@override @override
_MessageWidgetState createState() => _MessageWidgetState(); _MessageWidgetState createState() => _MessageWidgetState();
} }
@@ -944,42 +948,53 @@ class _MessageWidgetState extends State<MessageWidget>
_videoControllers[attachment.assetUrl] = videoController; _videoControllers[attachment.assetUrl] = videoController;
} }
ChewieController chewieController; return FutureBuilder<void>(
if (_chuwieControllers.containsKey(attachment.assetUrl)) { future: videoController.initialize(),
chewieController = _chuwieControllers[attachment.assetUrl]; builder: (_, snapshot) {
} else { if (snapshot.connectionState != ConnectionState.done) {
chewieController = ChewieController( return Center(
videoPlayerController: videoController, child: CircularProgressIndicator(),
autoInitialize: true, );
errorBuilder: (_, e) { }
return Stack( ChewieController chewieController;
children: <Widget>[ if (_chuwieControllers.containsKey(attachment.assetUrl)) {
Container( chewieController = _chuwieControllers[attachment.assetUrl];
decoration: BoxDecoration( } else {
image: DecorationImage( chewieController = ChewieController(
fit: BoxFit.cover, allowFullScreen: widget.showVideoFullScreen,
image: CachedNetworkImageProvider( videoPlayerController: videoController,
attachment.thumbUrl, autoInitialize: false,
aspectRatio: videoController.value.aspectRatio,
errorBuilder: (_, e) {
return Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: CachedNetworkImageProvider(
attachment.thumbUrl,
),
),
), ),
), ),
), Material(
), color: Colors.transparent,
Material( child: InkWell(
color: Colors.transparent, onTap: () => _launchURL(attachment.titleLink),
child: InkWell( ),
onTap: () => _launchURL(attachment.titleLink), ),
), ],
), );
], });
); _chuwieControllers[attachment.assetUrl] = chewieController;
}); }
_chuwieControllers[attachment.assetUrl] = chewieController; return Chewie(
} key: ValueKey<String>(
'ATTACHMENT-${attachment.title}-${widget.message.id}'),
return Chewie( controller: chewieController,
key: ValueKey<String>( );
'ATTACHMENT-${attachment.title}-${widget.message.id}'), },
controller: chewieController,
); );
} }