Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[video_player] using RotatedBox
Signed-off-by: ふぁ <[email protected]>
  • Loading branch information
fa0311 committed Feb 24, 2025
commit 00cdd547171bd712d0c5d23ff5b6df08d76103be
16 changes: 9 additions & 7 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';
import 'dart:io';
import 'dart:math' as math;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -888,12 +887,15 @@ class _VideoPlayerWithRotation extends StatelessWidget {
final Widget child;

@override
Widget build(BuildContext context) => rotation == 0
? child
: Transform.rotate(
angle: rotation * math.pi / 180,
child: child,
);
Widget build(BuildContext context) {
if (rotation % 90 != 0 || rotation == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is silently ignoring any rotation value that's not a multiple of 90 correct? If there are actually cases where this happens, wouldn't silently ignoring them be even more broken than the current behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stuartmorgan
The rotation value in this context can only be 0, 90, 180, or 270 degrees, as most video formats (such as MP4 and MOV) store rotation metadata in 90-degree increments within the tkhd (Track Header) box.

For example, in the current Flutter ExoPlayer backend, any value outside this range is ignored:

try {
reportedRotationCorrection = RotationDegrees.fromDegrees(rotationCorrection);
} catch (IllegalArgumentException e) {
// Rotation correction other than 0, 90, 180, 270 reported by Format. Because this is
// unexpected we apply no rotation correction.
reportedRotationCorrection = RotationDegrees.ROTATE_0;
rotationCorrection = 0;
}

Since RotatedBox only supports quarter-turn rotations, this shouldn't be an issue. However, if an unexpected rotation value appears, should we fall back to Transform.rotate instead of ignoring it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the expectation is that it's impossible for this Dart code to receive values that aren't multiples of 90 degrees, that should be expressed via an assert, not a runtime conditional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an assert to ensure that only multiples of 90 degrees are allowed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional statement should be updated to reflect that change as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the conditional statement to reflect the assert change

return child;
}
return RotatedBox(
quarterTurns: rotation ~/ 90,
child: child,
);
}
}

/// Used to configure the [VideoProgressIndicator] widget's colors for how it
Expand Down