@@ -48,14 +48,12 @@ class VideoTrackRenderer extends StatefulWidget {
48
48
final rtc.RTCVideoViewObjectFit fit;
49
49
final VideoViewMirrorMode mirrorMode;
50
50
final VideoRenderMode renderMode;
51
- final bool preferFixHeight;
52
51
53
52
const VideoTrackRenderer (
54
53
this .track, {
55
54
this .fit = rtc.RTCVideoViewObjectFit .RTCVideoViewObjectFitContain ,
56
55
this .mirrorMode = VideoViewMirrorMode .auto,
57
56
this .renderMode = VideoRenderMode .texture,
58
- this .preferFixHeight = true ,
59
57
Key ? key,
60
58
}) : super (key: key);
61
59
@@ -227,45 +225,23 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
227
225
widget.track.onVideoViewBuild? .call (_internalKey);
228
226
});
229
227
228
+ if (! lkPlatformIsMobile () || widget.track is ! LocalVideoTrack ) {
229
+ return _videoRendererView ();
230
+ }
230
231
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);
262
238
}
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
+ } );
269
245
},
270
246
);
271
247
}
@@ -275,8 +251,42 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
275
251
// FutureBuilder will cause flickering for flutter web. so using
276
252
// different rendering methods for web and native.
277
253
@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
+ }
280
290
281
291
bool _shouldMirror () {
282
292
// off for screen share
0 commit comments