Skip to content

feat: add onFullScreenClosed to BetterPlayer #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion example/lib/pages/auto_fullscreen_orientation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class _AutoFullscreenOrientationPageState
),
AspectRatio(
aspectRatio: 16 / 9,
child: BetterPlayer(controller: _betterPlayerController),
child: BetterPlayer(controller: _betterPlayerController,onFullScreenClosed: ()async{
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('Fullscreen closed')));
return true;
}),
),
ElevatedButton(
child: Text("Play horizontal video"),
Expand Down
21 changes: 15 additions & 6 deletions lib/src/core/better_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:wakelock/wakelock.dart';

///Widget which uses provided controller to render video player.
class BetterPlayer extends StatefulWidget {
const BetterPlayer({Key? key, required this.controller}) : super(key: key);
const BetterPlayer({Key? key, required this.controller,this.onFullScreenClosed}) : super(key: key);

factory BetterPlayer.network(
String url, {
Expand All @@ -37,7 +37,7 @@ class BetterPlayer extends StatefulWidget {
);

final BetterPlayerController controller;

final Future<bool> Function()? onFullScreenClosed;
@override
_BetterPlayerState createState() {
return _BetterPlayerState();
Expand Down Expand Up @@ -152,6 +152,9 @@ class _BetterPlayerState extends State<BetterPlayer>
await _pushFullScreenWidget(context);
} else if (_isFullScreen) {
Navigator.of(context, rootNavigator: true).pop();
if(widget.onFullScreenClosed!=null) {
await widget.onFullScreenClosed!();
}
_isFullScreen = false;
controller
.postEvent(BetterPlayerEvent(BetterPlayerEventType.hideFullscreen));
Expand Down Expand Up @@ -203,12 +206,18 @@ class _BetterPlayerState extends State<BetterPlayer>

final routePageBuilder = _betterPlayerConfiguration.routePageBuilder;
if (routePageBuilder == null) {
return _defaultRoutePageBuilder(
context, animation, secondaryAnimation, controllerProvider);
return WillPopScope(
onWillPop: widget.onFullScreenClosed,
child: _defaultRoutePageBuilder(
context, animation, secondaryAnimation, controllerProvider),
);
}

return routePageBuilder(
context, animation, secondaryAnimation, controllerProvider);
return WillPopScope(
onWillPop: widget.onFullScreenClosed,
child: routePageBuilder(
context, animation, secondaryAnimation, controllerProvider),
);
}

Future<dynamic> _pushFullScreenWidget(BuildContext context) async {
Expand Down
Loading