Skip to content

Commit e0d2373

Browse files
committed
fix: get rid of manual selection which side to fix
also, cover all paths by moving up sizing logic to build function
1 parent e53f37d commit e0d2373

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed

lib/src/widgets/video_track_renderer.dart

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ class VideoTrackRenderer extends StatefulWidget {
4848
final rtc.RTCVideoViewObjectFit fit;
4949
final VideoViewMirrorMode mirrorMode;
5050
final VideoRenderMode renderMode;
51-
final bool preferFixHeight;
5251

5352
const VideoTrackRenderer(
5453
this.track, {
5554
this.fit = rtc.RTCVideoViewObjectFit.RTCVideoViewObjectFitContain,
5655
this.mirrorMode = VideoViewMirrorMode.auto,
5756
this.renderMode = VideoRenderMode.texture,
58-
this.preferFixHeight = true,
5957
Key? key,
6058
}) : super(key: key);
6159

@@ -227,45 +225,23 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
227225
widget.track.onVideoViewBuild?.call(_internalKey);
228226
});
229227

228+
if (!lkPlatformIsMobile() || widget.track is! LocalVideoTrack) {
229+
return _videoRendererView();
230+
}
230231
return LayoutBuilder(
231-
builder: (BuildContext context, BoxConstraints constraints) {
232-
final bool fixHeight = (widget.preferFixHeight &&
233-
constraints.hasBoundedHeight) ||
234-
!constraints.hasBoundedWidth;
235-
final Widget child;
236-
if (!lkPlatformIsMobile() ||
237-
widget.track is! LocalVideoTrack) {
238-
child = _videoRendererView();
239-
} else {
240-
child = GestureDetector(
241-
onScaleStart: (details) {},
242-
onScaleUpdate: (details) {
243-
if (details.scale != 1.0) {
244-
setZoom(details.scale);
245-
}
246-
},
247-
onTapDown: (TapDownDetails details) =>
248-
onViewFinderTap(details, constraints),
249-
child: _videoRendererView(),
250-
);
251-
}
252-
final double? aspectRatio = _aspectRatio;
253-
final double width;
254-
final double height;
255-
if (aspectRatio != null) {
256-
if (fixHeight) {
257-
height = constraints.maxHeight;
258-
width = height * aspectRatio;
259-
} else {
260-
width = constraints.maxWidth;
261-
height = width / aspectRatio;
232+
builder: (BuildContext context, BoxConstraints constraints) {
233+
return GestureDetector(
234+
onScaleStart: (details) {},
235+
onScaleUpdate: (details) {
236+
if (details.scale != 1.0) {
237+
setZoom(details.scale);
262238
}
263-
return SizedBox(width: width, height: height, child: child);
264-
} else {
265-
return child;
266-
}
267-
},
268-
);
239+
},
240+
onTapDown: (TapDownDetails details) =>
241+
onViewFinderTap(details, constraints),
242+
child: _videoRendererView(),
243+
);
244+
});
269245
},
270246
);
271247
}
@@ -275,8 +251,42 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
275251
// FutureBuilder will cause flickering for flutter web. so using
276252
// different rendering methods for web and native.
277253
@override
278-
Widget build(BuildContext context) =>
279-
kIsWeb ? _videoViewForWeb() : _videoViewForNative();
254+
Widget build(BuildContext context) {
255+
final child = kIsWeb ? _videoViewForWeb() : _videoViewForNative();
256+
257+
return LayoutBuilder(
258+
builder: (BuildContext context, BoxConstraints constraints) {
259+
if (!constraints.hasBoundedWidth && !constraints.hasBoundedHeight) {
260+
return child;
261+
}
262+
if (_aspectRatio == null) {
263+
return child;
264+
}
265+
266+
bool fixHeight;
267+
if (!constraints.hasBoundedWidth) {
268+
fixHeight = true;
269+
} else if (!constraints.hasBoundedHeight) {
270+
fixHeight = false;
271+
} else {
272+
// both width and height are bound, figure out which to fix based on aspect ratios
273+
final constraintsAspectRatio =
274+
constraints.maxWidth / constraints.maxHeight;
275+
fixHeight = constraintsAspectRatio > _aspectRatio!;
276+
}
277+
final double width;
278+
final double height;
279+
if (fixHeight) {
280+
height = constraints.maxHeight;
281+
width = height * _aspectRatio!;
282+
} else {
283+
width = constraints.maxWidth;
284+
height = width / _aspectRatio!;
285+
}
286+
return SizedBox(width: width, height: height, child: child);
287+
},
288+
);
289+
}
280290

281291
bool _shouldMirror() {
282292
// off for screen share

0 commit comments

Comments
 (0)