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(
|
return Scaffold(
|
||||||
body: ExpandedControls(
|
body: ExpandedControls(
|
||||||
castFramework: castFramework,
|
castFramework: castFramework,
|
||||||
onBackTapped: () => Navigator.pop(context),
|
onCloseRequested: () => Navigator.pop(context),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_cast_framework/src/cast/widgets/expanded_controls/ExpandedControlsToolbar.dart';
|
|
||||||
|
|
||||||
import '../../../../cast.dart';
|
import '../../../../cast.dart';
|
||||||
import 'ExpandedControlsConnectedDeviceLabel.dart';
|
import 'ExpandedControlsConnectedDeviceLabel.dart';
|
||||||
import 'ExpandedControlsPlayer.dart';
|
import 'ExpandedControlsPlayer.dart';
|
||||||
import 'ExpandedControlsProgress.dart';
|
import 'ExpandedControlsProgress.dart';
|
||||||
|
import 'ExpandedControlsToolbar.dart';
|
||||||
|
|
||||||
const _topDownBlackGradient = BoxDecoration(
|
const _topDownBlackGradient = BoxDecoration(
|
||||||
gradient: LinearGradient(
|
gradient: LinearGradient(
|
||||||
|
|
@ -31,13 +31,15 @@ const _bottomUpBlackGradient = BoxDecoration(
|
||||||
class ExpandedControls extends StatefulWidget {
|
class ExpandedControls extends StatefulWidget {
|
||||||
final FlutterCastFramework castFramework;
|
final FlutterCastFramework castFramework;
|
||||||
final String? castingToText;
|
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();
|
final controller = ExpandedControlsProgressController();
|
||||||
|
|
||||||
ExpandedControls({
|
ExpandedControls({
|
||||||
required this.castFramework,
|
required this.castFramework,
|
||||||
this.castingToText,
|
this.castingToText,
|
||||||
this.onBackTapped,
|
this.onCloseRequested,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -48,6 +50,9 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||||
|
sessionManager.state.addListener(_onSessionStateChanged);
|
||||||
|
sessionManager.remoteMediaClient.playerState
|
||||||
|
.addListener(_onPlayerStateChanged);
|
||||||
sessionManager.remoteMediaClient.onProgressUpdated = _onProgressUpdated;
|
sessionManager.remoteMediaClient.onProgressUpdated = _onProgressUpdated;
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
@ -56,6 +61,9 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
final sessionManager = widget.castFramework.castContext.sessionManager;
|
final sessionManager = widget.castFramework.castContext.sessionManager;
|
||||||
|
sessionManager.state.removeListener(_onSessionStateChanged);
|
||||||
|
sessionManager.remoteMediaClient.playerState
|
||||||
|
.removeListener(_onPlayerStateChanged);
|
||||||
sessionManager.remoteMediaClient.onProgressUpdated = null;
|
sessionManager.remoteMediaClient.onProgressUpdated = null;
|
||||||
|
|
||||||
widget.controller.dispose();
|
widget.controller.dispose();
|
||||||
|
|
@ -63,6 +71,33 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
||||||
super.dispose();
|
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) {
|
void _onProgressUpdated(int progress, int duration) {
|
||||||
widget.controller.updateProgress(progress, duration);
|
widget.controller.updateProgress(progress, duration);
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +115,7 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
||||||
castFramework: widget.castFramework,
|
castFramework: widget.castFramework,
|
||||||
title: title,
|
title: title,
|
||||||
subtitle: subtitle,
|
subtitle: subtitle,
|
||||||
onBackTapped: widget.onBackTapped,
|
onBackTapped: widget.onCloseRequested,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue