@@ -70,9 +70,7 @@ class _BetterPlayerState extends State<BetterPlayer>
70
70
void didChangeDependencies () {
71
71
if (! _initialized) {
72
72
final navigator = Navigator .of (context);
73
- setState (() {
74
- _navigatorState = navigator;
75
- });
73
+ _navigatorState = navigator;
76
74
_setup ();
77
75
_initialized = true ;
78
76
}
@@ -162,59 +160,20 @@ class _BetterPlayerState extends State<BetterPlayer>
162
160
Widget build (BuildContext context) {
163
161
return BetterPlayerControllerProvider (
164
162
controller: widget.controller,
165
- child: _buildPlayer ( ),
163
+ child: _InternalPlayer (controller : widget.controller ),
166
164
);
167
165
}
168
166
169
- Widget _buildFullScreenVideo (
170
- BuildContext context,
171
- Animation <double > animation,
172
- BetterPlayerControllerProvider controllerProvider) {
173
- return Scaffold (
174
- resizeToAvoidBottomInset: false ,
175
- body: Container (
176
- alignment: Alignment .center,
177
- color: Colors .black,
178
- child: controllerProvider,
179
- ),
180
- );
181
- }
182
-
183
- AnimatedWidget _defaultRoutePageBuilder (
184
- BuildContext context,
185
- Animation <double > animation,
186
- Animation <double > secondaryAnimation,
187
- BetterPlayerControllerProvider controllerProvider) {
188
- return AnimatedBuilder (
189
- animation: animation,
190
- builder: (BuildContext context, Widget ? child) {
191
- return _buildFullScreenVideo (context, animation, controllerProvider);
192
- },
193
- );
194
- }
195
-
196
- Widget _fullScreenRoutePageBuilder (
197
- BuildContext context,
198
- Animation <double > animation,
199
- Animation <double > secondaryAnimation,
200
- ) {
201
- final controllerProvider = BetterPlayerControllerProvider (
202
- controller: widget.controller, child: _buildPlayer ());
203
-
204
- final routePageBuilder = _betterPlayerConfiguration.routePageBuilder;
205
- if (routePageBuilder == null ) {
206
- return _defaultRoutePageBuilder (
207
- context, animation, secondaryAnimation, controllerProvider);
208
- }
209
-
210
- return routePageBuilder (
211
- context, animation, secondaryAnimation, controllerProvider);
212
- }
213
-
214
167
Future <dynamic > _pushFullScreenWidget (BuildContext context) async {
215
168
final TransitionRoute <void > route = PageRouteBuilder <void >(
216
169
settings: const RouteSettings (),
217
- pageBuilder: _fullScreenRoutePageBuilder,
170
+ pageBuilder: (context, animation, secondaryAnimation) =>
171
+ _FullScreenPageRouteBuilderWidget (
172
+ controller: widget.controller,
173
+ betterPlayerConfiguration: _betterPlayerConfiguration,
174
+ animation: animation,
175
+ secondaryAnimation: secondaryAnimation,
176
+ ),
218
177
);
219
178
220
179
await SystemChrome .setEnabledSystemUIMode (SystemUiMode .immersiveSticky);
@@ -261,21 +220,74 @@ class _BetterPlayerState extends State<BetterPlayer>
261
220
_betterPlayerConfiguration.deviceOrientationsAfterFullScreen);
262
221
}
263
222
264
- Widget _buildPlayer () {
223
+ @override
224
+ void didChangeAppLifecycleState (AppLifecycleState state) {
225
+ super .didChangeAppLifecycleState (state);
226
+ widget.controller.setAppLifecycleState (state);
227
+ }
228
+ }
229
+
230
+ class _InternalPlayer extends StatelessWidget {
231
+ final BetterPlayerController controller;
232
+
233
+ const _InternalPlayer ({required this .controller});
234
+
235
+ @override
236
+ Widget build (BuildContext context) {
265
237
return VisibilityDetector (
266
- key: Key ("${widget . controller .hashCode }_key" ),
238
+ key: Key ("${controller .hashCode }_key" ),
267
239
onVisibilityChanged: (VisibilityInfo info) =>
268
- widget. controller.onPlayerVisibilityChanged (info.visibleFraction),
240
+ controller.onPlayerVisibilityChanged (info.visibleFraction),
269
241
child: BetterPlayerWithControls (
270
- controller: widget. controller,
242
+ controller: controller,
271
243
),
272
244
);
273
245
}
246
+ }
247
+
248
+ class _FullScreenPageRouteBuilderWidget extends StatelessWidget {
249
+ final BetterPlayerController controller;
250
+ final BetterPlayerConfiguration betterPlayerConfiguration;
251
+ final Animation <double > animation;
252
+ final Animation <double > secondaryAnimation;
253
+
254
+ const _FullScreenPageRouteBuilderWidget ({
255
+ required this .controller,
256
+ required this .betterPlayerConfiguration,
257
+ required this .animation,
258
+ required this .secondaryAnimation,
259
+ });
274
260
275
261
@override
276
- void didChangeAppLifecycleState (AppLifecycleState state) {
277
- super .didChangeAppLifecycleState (state);
278
- widget.controller.setAppLifecycleState (state);
262
+ Widget build (BuildContext context) {
263
+ final controllerProvider = BetterPlayerControllerProvider (
264
+ controller: controller,
265
+ child: _InternalPlayer (controller: controller),
266
+ );
267
+
268
+ final routePageBuilder = betterPlayerConfiguration.routePageBuilder;
269
+ if (routePageBuilder == null ) {
270
+ return AnimatedBuilder (
271
+ animation: animation,
272
+ builder: (BuildContext context, Widget ? child) {
273
+ return Scaffold (
274
+ resizeToAvoidBottomInset: false ,
275
+ body: Container (
276
+ alignment: Alignment .center,
277
+ color: Colors .black,
278
+ child: controllerProvider,
279
+ ),
280
+ );
281
+ },
282
+ );
283
+ }
284
+
285
+ return routePageBuilder (
286
+ context,
287
+ animation,
288
+ secondaryAnimation,
289
+ controllerProvider,
290
+ );
279
291
}
280
292
}
281
293
0 commit comments