Skip to content

WIP: Fadeout placeholder #34

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

Closed
Closed
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
3 changes: 2 additions & 1 deletion lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Chewie extends StatefulWidget {
this.aspectRatio,
this.autoInitialize = false,
this.autoPlay = false,
this.startAt,
this.startAt = const Duration(),
this.looping = false,
this.cupertinoProgressColors,
this.materialProgressColors,
Expand Down Expand Up @@ -84,6 +84,7 @@ class _ChewiePlayerState extends State<Chewie> {
placeholder: widget.placeholder,
autoPlay: widget.autoPlay,
showControls: widget.showControls,
startAt: widget.startAt,
);
}

Expand Down
53 changes: 53 additions & 0 deletions lib/src/fadeout_placeholder.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

class fadeoutPlaceholder extends StatefulWidget {
final VideoPlayerController controller;
final Widget placeholder;
final Duration fadeAfter;

fadeoutPlaceholder({this.controller, this.placeholder, this.fadeAfter});

@override
_fadeoutPlaceholderState createState() => _fadeoutPlaceholderState();
}

class _fadeoutPlaceholderState extends State<fadeoutPlaceholder> {
VoidCallback listener;

VideoPlayerController get controller => widget.controller;

_fadeoutPlaceholderState() {
listener = () {
setState(() {});
};
}

@override
void didUpdateWidget(fadeoutPlaceholder oldWidget) {
if (oldWidget.controller != controller) {
controller.addListener(listener);
}
super.didUpdateWidget(oldWidget);
}

@override
void initState() {
super.initState();
controller.addListener(listener);
}

@override
void deactivate() {
controller.removeListener(listener);
super.deactivate();
}

@override
Widget build(BuildContext context) {
return AnimatedOpacity(
opacity: controller.value.position > widget.fadeAfter ? 0.0 : 1.0,
duration: Duration(milliseconds: 200),
child: widget.placeholder ?? Container());
}
}
9 changes: 8 additions & 1 deletion lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:ui';

import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/src/cupertino_controls.dart';
import 'package:chewie/src/fadeout_placeholder.dart';
import 'package:chewie/src/material_controls.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -18,6 +19,7 @@ class PlayerWithControls extends StatefulWidget {
final double aspectRatio;
final bool autoPlay;
final bool showControls;
final Duration startAt;

PlayerWithControls({
Key key,
Expand All @@ -30,6 +32,7 @@ class PlayerWithControls extends StatefulWidget {
this.materialProgressColors,
this.placeholder,
this.autoPlay,
this.startAt,
}) : super(key: key);

@override
Expand Down Expand Up @@ -62,7 +65,6 @@ class _VideoPlayerWithControlsState extends State<PlayerWithControls> {
return new Container(
child: new Stack(
children: <Widget>[
widget.placeholder ?? new Container(),
new Center(
child: new Hero(
tag: controller,
Expand All @@ -76,6 +78,11 @@ class _VideoPlayerWithControlsState extends State<PlayerWithControls> {
),
),
),
fadeoutPlaceholder(
controller: controller,
placeholder: widget.placeholder,
fadeAfter: widget.startAt,
),
_buildControls(context, controller),
],
),
Expand Down