Created
January 12, 2021 17:19
-
-
Save jtmuller5/7e823654f140a5c0e8ff9a73ec950ff7 to your computer and use it in GitHub Desktop.
Reusable video thumbnail ViewModelWidget
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VideoThumbnail extends ViewModelWidget<StackedVideoViewModel> { | |
@override | |
Widget build(BuildContext context, StackedVideoViewModel model) { | |
return Builder( | |
builder: (context) { | |
// If we want to show the full video, we need to scale it to fit the longest side | |
if (model.showFull) { | |
bool wideVideo = | |
model.videoPlayerController.value.size.width > | |
model.videoPlayerController.value.size.height; | |
if (wideVideo) { | |
return Row( | |
children: [ | |
Expanded( | |
child: AspectRatio( | |
aspectRatio: | |
model.videoPlayerController.value.aspectRatio, | |
child: VideoPlayer(model.videoPlayerController), | |
)) | |
], | |
); | |
} else { | |
return Column( | |
children: [ | |
Expanded( | |
child: AspectRatio( | |
aspectRatio: | |
model.videoPlayerController.value.aspectRatio, | |
child: VideoPlayer(model.videoPlayerController), | |
)) | |
], | |
); | |
} | |
} | |
// Else just show a portion of the video viewport | |
else { | |
return FittedBox( | |
fit: BoxFit.cover, | |
alignment: Alignment(model.x, model.y), | |
child: SizedBox( | |
height: | |
model.videoPlayerController.value.size?.height ?? 0, | |
width: model.videoPlayerController.value.size?.width ?? 0, | |
child: VideoPlayer(model.videoPlayerController), | |
), | |
); | |
} | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment