admin管理员组

文章数量:1026939

 SizedBox(
                height: context.height,
                width: context.width,
                child: FittedBox(
                    fit: BoxFit.cover,
                    child: SizedBox(
                        height: context.height,
                        width: context.width,
                        child: VideoPlayer(videoC.value!))),

I have this and it does not fit the box but just squeeze the video into fit in that height and width. How can I make it cover the Sizedbox?

 SizedBox(
                height: context.height,
                width: context.width,
                child: FittedBox(
                    fit: BoxFit.cover,
                    child: SizedBox(
                        height: context.height,
                        width: context.width,
                        child: VideoPlayer(videoC.value!))),

I have this and it does not fit the box but just squeeze the video into fit in that height and width. How can I make it cover the Sizedbox?

Share Improve this question asked Nov 16, 2024 at 15:32 chichichichi 3,3187 gold badges37 silver badges74 bronze badges 3
  • 1 its no point in using FittedBox if both parent and child of it have the same size, are you sure you pasted the correct code? – pskink Commented Nov 16, 2024 at 15:45
  • Yeah that is what I have. if I don't have one of them then it did not work – chichi Commented Nov 16, 2024 at 22:43
  • 1 chek the below answer: here FittedBox expands to the available space while its child (with VideoPlayer) takes the size of the asset you are showing - this is the case where FittedBox can scale its child – pskink Commented Nov 17, 2024 at 7:40
Add a comment  | 

1 Answer 1

Reset to default 1

Does this work for you with the video_player plugin?

SizedBox.expand(
  child: FittedBox(
    fit: BoxFit.cover,
    child: ListenableBuilder(
      listenable: _videoController,
      builder: (context, _) => SizedBox(
        width: _videoController.value.size?.width ?? 0,
        height: _videoController.value.size?.height ?? 0,
        child: VideoPlayer(_videoController),
      ),
    ),
  ),
),
 SizedBox(
                height: context.height,
                width: context.width,
                child: FittedBox(
                    fit: BoxFit.cover,
                    child: SizedBox(
                        height: context.height,
                        width: context.width,
                        child: VideoPlayer(videoC.value!))),

I have this and it does not fit the box but just squeeze the video into fit in that height and width. How can I make it cover the Sizedbox?

 SizedBox(
                height: context.height,
                width: context.width,
                child: FittedBox(
                    fit: BoxFit.cover,
                    child: SizedBox(
                        height: context.height,
                        width: context.width,
                        child: VideoPlayer(videoC.value!))),

I have this and it does not fit the box but just squeeze the video into fit in that height and width. How can I make it cover the Sizedbox?

Share Improve this question asked Nov 16, 2024 at 15:32 chichichichi 3,3187 gold badges37 silver badges74 bronze badges 3
  • 1 its no point in using FittedBox if both parent and child of it have the same size, are you sure you pasted the correct code? – pskink Commented Nov 16, 2024 at 15:45
  • Yeah that is what I have. if I don't have one of them then it did not work – chichi Commented Nov 16, 2024 at 22:43
  • 1 chek the below answer: here FittedBox expands to the available space while its child (with VideoPlayer) takes the size of the asset you are showing - this is the case where FittedBox can scale its child – pskink Commented Nov 17, 2024 at 7:40
Add a comment  | 

1 Answer 1

Reset to default 1

Does this work for you with the video_player plugin?

SizedBox.expand(
  child: FittedBox(
    fit: BoxFit.cover,
    child: ListenableBuilder(
      listenable: _videoController,
      builder: (context, _) => SizedBox(
        width: _videoController.value.size?.width ?? 0,
        height: _videoController.value.size?.height ?? 0,
        child: VideoPlayer(_videoController),
      ),
    ),
  ),
),

本文标签: Flutter BoxFixcover does not cover but stretch the videoStack Overflow