Skip to content
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

Add parameter to allow user to set bottom bar backgrond color along w… #740

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
6 changes: 4 additions & 2 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ class _ChewieDemoState extends State<ChewieDemo> {
.videoPlayerController.value.isInitialized
? Chewie(
controller: _chewieController!,
controlBarBackgroundColor: Colors.yellow,
controlBarButtonsColor: Colors.blue,
)
: const Column(
: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
children: const [
CircularProgressIndicator(),
SizedBox(height: 20),
Text('Loading'),
Expand Down
21 changes: 14 additions & 7 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ typedef ChewieRoutePageBuilder = Widget Function(
/// `video_player` is pretty low level. Chewie wraps it in a friendly skin to
/// make it easy to use!
class Chewie extends StatefulWidget {
const Chewie({
Key? key,
required this.controller,
}) : super(key: key);
const Chewie(
{Key? key,
required this.controller,
this.controlBarBackgroundColor,
this.controlBarButtonsColor})
: super(key: key);

/// The [ChewieController]
final ChewieController controller;

final Color? controlBarBackgroundColor;
final Color? controlBarButtonsColor;
@override
ChewieState createState() {
return ChewieState();
Expand Down Expand Up @@ -87,7 +90,10 @@ class ChewieState extends State<Chewie> {
controller: widget.controller,
child: ChangeNotifierProvider<PlayerNotifier>.value(
value: notifier,
builder: (context, w) => const PlayerWithControls(),
builder: (context, w) => PlayerWithControls(
controlBarBackgroundColor: widget.controlBarBackgroundColor,
controlBarButtonsColor: widget.controlBarButtonsColor,
),
),
);
}
Expand Down Expand Up @@ -337,7 +343,8 @@ class ChewieController extends ChangeNotifier {
Animation<double>,
Animation<double>,
ChewieControllerProvider,
)? routePageBuilder,
)?
routePageBuilder,
}) {
return ChewieController(
draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar,
Expand Down
16 changes: 13 additions & 3 deletions lib/src/helpers/adaptive_controls.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';

class AdaptiveControls extends StatelessWidget {
const AdaptiveControls({
Key? key,
required this.controlBarBackgroundColor,
required this.controlBarButtonsColor,
}) : super(key: key);

final Color? controlBarBackgroundColor;
final Color? controlBarButtonsColor;
@override
Widget build(BuildContext context) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
return const MaterialControls();
return MaterialControls(
buttonColor: controlBarBackgroundColor,
backgroundColor: controlBarButtonsColor,
);

case TargetPlatform.macOS:
case TargetPlatform.windows:
Expand All @@ -24,7 +31,10 @@ class AdaptiveControls extends StatelessWidget {
iconColor: Color.fromARGB(255, 200, 200, 200),
);
default:
return const MaterialControls();
return MaterialControls(
buttonColor: controlBarBackgroundColor ?? Colors.green,
backgroundColor: controlBarButtonsColor ?? Colors.red,
);
}
}
}
33 changes: 19 additions & 14 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ import 'package:video_player/video_player.dart';
class MaterialControls extends StatefulWidget {
const MaterialControls({
this.showPlayButton = true,
required this.backgroundColor,
required this.buttonColor,
Key? key,
}) : super(key: key);

final bool showPlayButton;

final Color? backgroundColor;
final Color? buttonColor;
@override
State<StatefulWidget> createState() {
return _MaterialControlsState();
Expand Down Expand Up @@ -65,10 +68,10 @@ class _MaterialControlsState extends State<MaterialControls>
context,
chewieController.videoPlayerController.value.errorDescription!,
) ??
const Center(
Center(
child: Icon(
Icons.error,
color: Colors.white,
color: widget.buttonColor ?? Colors.white,
size: 42,
),
);
Expand Down Expand Up @@ -203,9 +206,9 @@ class _MaterialControlsState extends State<MaterialControls>
_startHideTimer();
}
},
icon: const Icon(
icon: Icon(
Icons.more_vert,
color: Colors.white,
color: widget.buttonColor ?? Colors.white,
),
),
);
Expand Down Expand Up @@ -249,12 +252,11 @@ class _MaterialControlsState extends State<MaterialControls>
AnimatedOpacity _buildBottomBar(
BuildContext context,
) {
final iconColor = Theme.of(context).textTheme.labelLarge!.color;

return AnimatedOpacity(
opacity: notifier.hideStuff ? 0.0 : 1.0,
duration: const Duration(milliseconds: 300),
child: Container(
color: widget.backgroundColor,
height: barHeight + (chewieController.isFullScreen ? 10.0 : 0),
padding: EdgeInsets.only(
left: 20,
Expand All @@ -274,7 +276,7 @@ class _MaterialControlsState extends State<MaterialControls>
if (chewieController.isLive)
const Expanded(child: Text('LIVE'))
else
_buildPosition(iconColor),
_buildPosition(widget.buttonColor),
if (chewieController.allowMuting)
_buildMuteButton(controller),
const Spacer(),
Expand Down Expand Up @@ -328,7 +330,7 @@ class _MaterialControlsState extends State<MaterialControls>
),
child: Icon(
_latestValue.volume > 0 ? Icons.volume_up : Icons.volume_off,
color: Colors.white,
color: widget.buttonColor ?? Colors.white,
),
),
),
Expand All @@ -354,7 +356,7 @@ class _MaterialControlsState extends State<MaterialControls>
chewieController.isFullScreen
? Icons.fullscreen_exit
: Icons.fullscreen,
color: Colors.white,
color: widget.buttonColor ?? Colors.white,
),
),
),
Expand Down Expand Up @@ -430,14 +432,15 @@ class _MaterialControlsState extends State<MaterialControls>
text: '/ ${formatDuration(duration)}',
style: TextStyle(
fontSize: 14.0,
color: Colors.white.withOpacity(.75),
color: widget.buttonColor?.withOpacity(.75) ??
Colors.white.withOpacity(.75),
fontWeight: FontWeight.normal,
),
)
],
style: const TextStyle(
style: TextStyle(
fontSize: 14.0,
color: Colors.white,
color: widget.buttonColor ?? Colors.white,
fontWeight: FontWeight.bold,
),
),
Expand All @@ -462,7 +465,9 @@ class _MaterialControlsState extends State<MaterialControls>
_subtitleOn
? Icons.closed_caption
: Icons.closed_caption_off_outlined,
color: _subtitleOn ? Colors.white : Colors.grey[700],
color: _subtitleOn
? (widget.buttonColor ?? Colors.white)
: (widget.buttonColor?.withOpacity(0.7) ?? Colors.grey[700]),
),
),
);
Expand Down
16 changes: 13 additions & 3 deletions lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:chewie/src/chewie_player.dart';
import 'package:chewie/src/helpers/adaptive_controls.dart';
import 'package:chewie/src/notifiers/index.dart';
Expand All @@ -6,8 +7,13 @@ import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';

class PlayerWithControls extends StatelessWidget {
const PlayerWithControls({Key? key}) : super(key: key);

const PlayerWithControls({
Key? key,
this.controlBarBackgroundColor,
this.controlBarButtonsColor,
}) : super(key: key);
final Color? controlBarBackgroundColor;
final Color? controlBarButtonsColor;
@override
Widget build(BuildContext context) {
final ChewieController chewieController = ChewieController.of(context);
Expand All @@ -25,7 +31,11 @@ class PlayerWithControls extends StatelessWidget {
ChewieController chewieController,
) {
return chewieController.showControls
? chewieController.customControls ?? const AdaptiveControls()
? chewieController.customControls ??
AdaptiveControls(
controlBarBackgroundColor: controlBarBackgroundColor,
controlBarButtonsColor: controlBarButtonsColor,
)
: const SizedBox();
}

Expand Down