ExpandedControls: autoclose on stop
This commit is contained in:
parent
3eb9e5a7b9
commit
7c2896a9de
2 changed files with 40 additions and 5 deletions
|
|
@ -14,7 +14,7 @@ class ExpandedControlsRoute extends StatelessWidget {
|
|||
return Scaffold(
|
||||
body: ExpandedControls(
|
||||
castFramework: castFramework,
|
||||
onBackTapped: () => Navigator.pop(context),
|
||||
onCloseRequested: () => Navigator.pop(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cast_framework/src/cast/widgets/expanded_controls/ExpandedControlsToolbar.dart';
|
||||
|
||||
import '../../../../cast.dart';
|
||||
import 'ExpandedControlsConnectedDeviceLabel.dart';
|
||||
import 'ExpandedControlsPlayer.dart';
|
||||
import 'ExpandedControlsProgress.dart';
|
||||
import 'ExpandedControlsToolbar.dart';
|
||||
|
||||
const _topDownBlackGradient = BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
|
|
@ -31,13 +31,15 @@ const _bottomUpBlackGradient = BoxDecoration(
|
|||
class ExpandedControls extends StatefulWidget {
|
||||
final FlutterCastFramework castFramework;
|
||||
final String? castingToText;
|
||||
final VoidCallback? onBackTapped;
|
||||
|
||||
/// This is called when the back button is tapped or when the session is closed
|
||||
final VoidCallback? onCloseRequested;
|
||||
final controller = ExpandedControlsProgressController();
|
||||
|
||||
ExpandedControls({
|
||||
required this.castFramework,
|
||||
this.castingToText,
|
||||
this.onBackTapped,
|
||||
this.onCloseRequested,
|
||||
});
|
||||
|
||||
@override
|
||||
|
|
@ -48,6 +50,9 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
|||
@override
|
||||
void initState() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
sessionManager.state.addListener(_onSessionStateChanged);
|
||||
sessionManager.remoteMediaClient.playerState
|
||||
.addListener(_onPlayerStateChanged);
|
||||
sessionManager.remoteMediaClient.onProgressUpdated = _onProgressUpdated;
|
||||
|
||||
super.initState();
|
||||
|
|
@ -56,6 +61,9 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
|||
@override
|
||||
void dispose() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
sessionManager.state.removeListener(_onSessionStateChanged);
|
||||
sessionManager.remoteMediaClient.playerState
|
||||
.removeListener(_onPlayerStateChanged);
|
||||
sessionManager.remoteMediaClient.onProgressUpdated = null;
|
||||
|
||||
widget.controller.dispose();
|
||||
|
|
@ -63,6 +71,33 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
void _onPlayerStateChanged() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
final state = sessionManager.remoteMediaClient.playerState.value;
|
||||
switch (state) {
|
||||
case PlayerState.idle:
|
||||
widget.onCloseRequested?.call();
|
||||
break;
|
||||
default:
|
||||
// unhandled
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _onSessionStateChanged() {
|
||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||
final state = sessionManager.state.value;
|
||||
switch (state) {
|
||||
case SessionState.idle:
|
||||
case SessionState.ended:
|
||||
widget.onCloseRequested?.call();
|
||||
break;
|
||||
default:
|
||||
// unhandled
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void _onProgressUpdated(int progress, int duration) {
|
||||
widget.controller.updateProgress(progress, duration);
|
||||
}
|
||||
|
|
@ -80,7 +115,7 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
|||
castFramework: widget.castFramework,
|
||||
title: title,
|
||||
subtitle: subtitle,
|
||||
onBackTapped: widget.onBackTapped,
|
||||
onBackTapped: widget.onCloseRequested,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue