Open1
VideoPlayerでもBoxFit.coverを使いたい!#Flutter
AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: FittedBox(
fit: BoxFit.cover,
child: Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width / _controller.value.aspectRatio,
child: VideoPlayer(_controller),
),
),
)
これ!
横幅いっぱいの例だけど、まあうまくカスタムしてください!
コンポーネントにするならこんな感じ(GetX使ってるけどGet.with以外特に変わらないです)
class CommVideoPlayer extends StatelessWidget {
const CommVideoPlayer({
required this.controller,
this.fit = BoxFit.cover,
Key? key,
}) : super(key: key);
final VideoPlayerController controller;
final BoxFit fit;
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: controller.value.aspectRatio,
child: FittedBox(
fit: fit,
child: SizedBox(
height: Get.width / controller.value.aspectRatio,
width: Get.width,
child: VideoPlayer(controller),
),
),
);
}
}
Commって接頭語使いやすくて好き