-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from arafaysaleem/feature/youtube-player-for-t…
…railers feature(Widgets): add overlay actions to trailer video player
- Loading branch information
Showing
7 changed files
with
451 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:better_player/better_player.dart'; | ||
import 'package:auto_route/auto_route.dart'; | ||
|
||
class OverlayBackButton extends StatefulWidget { | ||
final BetterPlayerController betterPlayerController; | ||
|
||
const OverlayBackButton({ | ||
Key? key, | ||
required this.betterPlayerController, | ||
}) : super(key: key); | ||
|
||
@override | ||
_OverlayBackButtonState createState() => _OverlayBackButtonState(); | ||
} | ||
|
||
class _OverlayBackButtonState extends State<OverlayBackButton> { | ||
bool _isVisible = false; | ||
|
||
BetterPlayerController get _betterPlayerController => widget.betterPlayerController; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_betterPlayerController.addEventsListener(_handlePlayerEventChanges); | ||
} | ||
|
||
/// Listens to all events sent by [_betterPlayerController] | ||
/// and handles them with the appropriate response. | ||
void _handlePlayerEventChanges(BetterPlayerEvent event) { | ||
final eventType = event.betterPlayerEventType; | ||
//handle events if initialized | ||
final controlsVisible = eventType == BetterPlayerEventType.controlsVisible; | ||
final controlsHidden = eventType == BetterPlayerEventType.controlsHidden; | ||
if (controlsVisible || controlsHidden) { //if overlay controls toggled | ||
setState(() { | ||
_isVisible = controlsVisible; | ||
}); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (!_isVisible) { | ||
return const SizedBox.shrink(); | ||
} | ||
return InkWell( | ||
onTap: () => context.router.pop(), | ||
child: const Padding( | ||
padding: EdgeInsets.all(15), | ||
child: Icon( | ||
Icons.arrow_back_sharp, | ||
color: Colors.white, | ||
size: 28, | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_betterPlayerController.removeEventsListener(_handlePlayerEventChanges); | ||
super.dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:better_player/better_player.dart'; | ||
|
||
class OverlayBlackHeader extends StatefulWidget { | ||
final BetterPlayerController betterPlayerController; | ||
|
||
const OverlayBlackHeader({ | ||
Key? key, | ||
required this.betterPlayerController, | ||
}) : super(key: key); | ||
|
||
@override | ||
_OverlayBlackHeaderState createState() => _OverlayBlackHeaderState(); | ||
} | ||
|
||
class _OverlayBlackHeaderState extends State<OverlayBlackHeader> { | ||
bool _isVisible = false; | ||
|
||
BetterPlayerController get _betterPlayerController => widget.betterPlayerController; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_betterPlayerController.addEventsListener(_handlePlayerEventChanges); | ||
} | ||
|
||
/// Listens to all events sent by [_betterPlayerController] | ||
/// and handles them with the appropriate response. | ||
void _handlePlayerEventChanges(BetterPlayerEvent event) { | ||
final eventType = event.betterPlayerEventType; | ||
//handle events if initialized | ||
final controlsVisible = eventType == BetterPlayerEventType.controlsVisible; | ||
final controlsHidden = eventType == BetterPlayerEventType.controlsHidden; | ||
if (controlsVisible || controlsHidden) { //if overlay controls toggled | ||
setState(() { | ||
_isVisible = controlsVisible; | ||
}); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (!_isVisible) { | ||
return const SizedBox.shrink(); | ||
} | ||
return const IgnorePointer( | ||
child: SizedBox( | ||
width: double.infinity, | ||
height: 55, | ||
child: ColoredBox( | ||
color: Colors.black54, | ||
), | ||
), | ||
); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_betterPlayerController.removeEventsListener(_handlePlayerEventChanges); | ||
super.dispose(); | ||
} | ||
} |
Oops, something went wrong.