@@ -60,7 +60,7 @@ use the provided [`setCallback`][] method to listen to surface lifecycle events:
60
60
surfaceProducer. setCallback(
61
61
new TextureRegistry .SurfaceProducer .Callback () {
62
62
@Override
63
- public void onSurfaceCreated () {
63
+ public void onSurfaceAvailable () {
64
64
// Do surface initialization here, and draw the current frame.
65
65
}
66
66
@@ -75,6 +75,12 @@ surfaceProducer.setCallback(
75
75
A full example of using this new API can be found in [ PR 6989] [ ] for the
76
76
` video_player_android ` plugin.
77
77
78
+ ::: note
79
+ In early versions of this API, the callback was named ` onSurfaceCreated ` , and
80
+ was invoked even if the original surface was not destroyed. This has been fixed
81
+ in the latest (pending 3.27) version of the API.
82
+ :::
83
+
78
84
## Note on camera previews
79
85
80
86
If your plugin implements a camera preview, your migration might also require
@@ -91,13 +97,16 @@ rotation = (sensorOrientationDegrees - deviceOrientationDegrees * sign + 360) %
91
97
```
92
98
93
99
where ` deviceOrientationDegrees ` is counterclockwise degrees and ` sign ` is 1 for
94
- front-facing cameras and -1 for back-facing cameras.
100
+ front-facing cameras and -1 for back-facing cameras.
95
101
96
102
To calculate this rotation,
103
+
104
+ - Use [ ` SurfaceProducer.handlesCropAndRotation ` ] [ ] to check if the underlying
105
+ ` Surface ` handles rotation (if ` false ` , you may need to handle the rotation).
97
106
- Retrieve the sensor orientation degrees by retrieving the value of
98
- [ ` CameraCharacteristics.SENSOR_ORIENTATION ` ] [ ] .
107
+ [ ` CameraCharacteristics.SENSOR_ORIENTATION ` ] [ ] .
99
108
- Retrieve the device orientation degrees in one of the ways that the
100
- [ Android orientation calculation documentation] [ ] details.
109
+ [ Android orientation calculation documentation] [ ] details.
101
110
102
111
To apply this rotation, you can use a [ ` RotatedBox ` ] [ ] widget.
103
112
@@ -116,6 +125,9 @@ plugins that migrate to this API should set `3.24` as a minimum version constrai
116
125
117
126
In stable release: 3.24
118
127
128
+ In the upcoming stable release, 3.27, ` onSurfaceCreated ` is deprecated, and
129
+ ` onSurfaceAvailable ` and ` handlesCropAndRotation ` are added.
130
+
119
131
## References
120
132
121
133
API documentation:
@@ -142,6 +154,7 @@ Relevant PRs:
142
154
[ `HardwareBuffer` ] : https://developer.android.com/reference/android/hardware/HardwareBuffer
143
155
[ `Surface` ] : https://developer.android.com/reference/android/view/Surface
144
156
[ `SurfaceProducer` ] : {{site.api}}/javadoc/io/flutter/view/TextureRegistry.SurfaceProducer.html
157
+ [ `SurfaceProducer.handlesCropAndRotation` ] : {{site.api}}/javadoc/io/flutter/view/TextureRegistry.SurfaceProducer.html#handlesCropAndRotation()
145
158
[ `SurfaceTexture` ] : https://source.android.com/docs/core/graphics/arch-st
146
159
[ `createSurfaceProducer` ] : {{site.api}}/javadoc/io/flutter/view/TextureRegistry.html#createSurfaceProducer()
147
160
[ `createSurfaceTexture` ] : {{site.api}}/javadoc/io/flutter/view/TextureRegistry.html#createSurfaceTexture()
0 commit comments