4
4
5
5
import 'dart:async' ;
6
6
import 'dart:io' ;
7
+ import 'dart:math' as math;
7
8
8
9
import 'package:flutter/foundation.dart' ;
9
10
import 'package:flutter/material.dart' ;
@@ -48,6 +49,7 @@ class VideoPlayerValue {
48
49
this .isBuffering = false ,
49
50
this .volume = 1.0 ,
50
51
this .playbackSpeed = 1.0 ,
52
+ this .rotationCorrection = 0 ,
51
53
this .errorDescription,
52
54
});
53
55
@@ -111,6 +113,9 @@ class VideoPlayerValue {
111
113
/// The [size] of the currently loaded video.
112
114
final Size size;
113
115
116
+ /// Degrees to rotate the video (clockwise) so it is displayed correctly.
117
+ final int rotationCorrection;
118
+
114
119
/// Indicates whether or not the video has been loaded and is ready to play.
115
120
final bool isInitialized;
116
121
@@ -136,7 +141,7 @@ class VideoPlayerValue {
136
141
}
137
142
138
143
/// Returns a new instance that has the same values as this current instance,
139
- /// except for any overrides passed in as arguments to [copyWidth ] .
144
+ /// except for any overrides passed in as arguments to [copyWith ] .
140
145
VideoPlayerValue copyWith ({
141
146
Duration ? duration,
142
147
Size ? size,
@@ -150,6 +155,7 @@ class VideoPlayerValue {
150
155
bool ? isBuffering,
151
156
double ? volume,
152
157
double ? playbackSpeed,
158
+ int ? rotationCorrection,
153
159
String ? errorDescription = _defaultErrorDescription,
154
160
}) {
155
161
return VideoPlayerValue (
@@ -165,6 +171,7 @@ class VideoPlayerValue {
165
171
isBuffering: isBuffering ?? this .isBuffering,
166
172
volume: volume ?? this .volume,
167
173
playbackSpeed: playbackSpeed ?? this .playbackSpeed,
174
+ rotationCorrection: rotationCorrection ?? this .rotationCorrection,
168
175
errorDescription: errorDescription != _defaultErrorDescription
169
176
? errorDescription
170
177
: this .errorDescription,
@@ -368,6 +375,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
368
375
value = value.copyWith (
369
376
duration: event.duration,
370
377
size: event.size,
378
+ rotationCorrection: event.rotationCorrection,
371
379
isInitialized: event.duration != null ,
372
380
errorDescription: null ,
373
381
);
@@ -761,10 +769,29 @@ class _VideoPlayerState extends State<VideoPlayer> {
761
769
Widget build (BuildContext context) {
762
770
return _textureId == VideoPlayerController .kUninitializedTextureId
763
771
? Container ()
764
- : _videoPlayerPlatform.buildView (_textureId);
772
+ : _VideoPlayerWithRotation (
773
+ rotation: widget.controller.value.rotationCorrection,
774
+ child: _videoPlayerPlatform.buildView (_textureId),
775
+ );
765
776
}
766
777
}
767
778
779
+ class _VideoPlayerWithRotation extends StatelessWidget {
780
+ const _VideoPlayerWithRotation (
781
+ {Key ? key, required this .rotation, required this .child})
782
+ : super (key: key);
783
+ final int rotation;
784
+ final Widget child;
785
+
786
+ @override
787
+ Widget build (BuildContext context) => rotation == 0
788
+ ? child
789
+ : Transform .rotate (
790
+ angle: rotation * math.pi / 180 ,
791
+ child: child,
792
+ );
793
+ }
794
+
768
795
/// Used to configure the [VideoProgressIndicator] widget's colors for how it
769
796
/// describes the video's status.
770
797
///
0 commit comments