Skip to content

Instantly share code, notes, and snippets.

@jtmuller5
Created January 12, 2021 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtmuller5/7e823654f140a5c0e8ff9a73ec950ff7 to your computer and use it in GitHub Desktop.
Save jtmuller5/7e823654f140a5c0e8ff9a73ec950ff7 to your computer and use it in GitHub Desktop.
Reusable video thumbnail ViewModelWidget
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