Skip to content

Commit a6e3675

Browse files
fa0311androidseb
authored andcommitted
[video_player] Fix layout issue caused by Transform.rotate not affecting space calculation. (flutter#8685)
This pull request resolves [#159724](flutter/flutter#159724). The issue occurs because `Transform.rotate` is used when `rotation` is not 0. Since `Transform` does not affect space calculations, this leads to the issues. This is related to [flutter#7846](flutter#7846).
1 parent 7b67d10 commit a6e3675

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.9.5
2+
3+
* Fixes layout issue caused by `Transform.rotate` not affecting space calculation.
4+
15
## 2.9.4
26

37
* Reduces the position update interval from 500ms to 100ms.

packages/video_player/video_player/lib/video_player.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:async';
66
import 'dart:io';
7-
import 'dart:math' as math;
87

98
import 'package:flutter/foundation.dart';
109
import 'package:flutter/material.dart';
@@ -882,17 +881,22 @@ class _VideoPlayerState extends State<VideoPlayer> {
882881
}
883882

884883
class _VideoPlayerWithRotation extends StatelessWidget {
885-
const _VideoPlayerWithRotation({required this.rotation, required this.child});
884+
const _VideoPlayerWithRotation({required this.rotation, required this.child})
885+
: assert(rotation % 90 == 0, 'Rotation must be a multiple of 90');
886+
886887
final int rotation;
887888
final Widget child;
888889

889890
@override
890-
Widget build(BuildContext context) => rotation == 0
891-
? child
892-
: Transform.rotate(
893-
angle: rotation * math.pi / 180,
894-
child: child,
895-
);
891+
Widget build(BuildContext context) {
892+
if (rotation == 0) {
893+
return child;
894+
}
895+
return RotatedBox(
896+
quarterTurns: rotation ~/ 90,
897+
child: child,
898+
);
899+
}
896900
}
897901

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

packages/video_player/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android, iOS, and web.
44
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
6-
version: 2.9.4
6+
version: 2.9.5
77

88
environment:
99
sdk: ^3.4.0

packages/video_player/video_player/test/video_player_test.dart

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import 'dart:async';
66
import 'dart:io';
7-
import 'dart:math' as math;
8-
import 'dart:typed_data';
97

108
import 'package:flutter/foundation.dart' show kIsWeb;
119
import 'package:flutter/material.dart';
@@ -178,28 +176,20 @@ void main() {
178176
addTearDown(controller.dispose);
179177
controller.textureId = 1;
180178
await tester.pumpWidget(VideoPlayer(controller));
181-
final Transform actualRotationCorrection =
182-
find.byType(Transform).evaluate().single.widget as Transform;
183-
final Float64List actualRotationCorrectionStorage =
184-
actualRotationCorrection.transform.storage;
185-
final Float64List expectedMatrixStorage =
186-
Matrix4.rotationZ(math.pi).storage;
187-
expect(actualRotationCorrectionStorage.length,
188-
equals(expectedMatrixStorage.length));
189-
for (int i = 0; i < actualRotationCorrectionStorage.length; i++) {
190-
expect(actualRotationCorrectionStorage[i],
191-
moreOrLessEquals(expectedMatrixStorage[i]));
192-
}
179+
final RotatedBox actualRotationCorrection =
180+
find.byType(RotatedBox).evaluate().single.widget as RotatedBox;
181+
final int actualQuarterTurns = actualRotationCorrection.quarterTurns;
182+
expect(actualQuarterTurns, equals(2));
193183
});
194184

195-
testWidgets('no transform when rotationCorrection is zero',
185+
testWidgets('no RotatedBox when rotationCorrection is zero',
196186
(WidgetTester tester) async {
197187
final FakeController controller =
198188
FakeController.value(const VideoPlayerValue(duration: Duration.zero));
199189
addTearDown(controller.dispose);
200190
controller.textureId = 1;
201191
await tester.pumpWidget(VideoPlayer(controller));
202-
expect(find.byType(Transform), findsNothing);
192+
expect(find.byType(RotatedBox), findsNothing);
203193
});
204194

205195
group('ClosedCaption widget', () {

0 commit comments

Comments
 (0)