ExpandedControls: improved castingToText
This commit is contained in:
parent
7c2896a9de
commit
f7fa33d04c
3 changed files with 25 additions and 6 deletions
|
|
@ -30,6 +30,8 @@ const _bottomUpBlackGradient = BoxDecoration(
|
||||||
|
|
||||||
class ExpandedControls extends StatefulWidget {
|
class ExpandedControls extends StatefulWidget {
|
||||||
final FlutterCastFramework castFramework;
|
final FlutterCastFramework castFramework;
|
||||||
|
|
||||||
|
/// Label to introduce cast device. Default is "Casting to {{device_name}}", where {{device_name}} is replaced with the device name
|
||||||
final String? castingToText;
|
final String? castingToText;
|
||||||
|
|
||||||
/// This is called when the back button is tapped or when the session is closed
|
/// This is called when the back button is tapped or when the session is closed
|
||||||
|
|
@ -129,6 +131,7 @@ class _ExpandedControlsState extends State<ExpandedControls> {
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ExpandedControlsConnectedDeviceLabel(
|
child: ExpandedControlsConnectedDeviceLabel(
|
||||||
castFramework: widget.castFramework,
|
castFramework: widget.castFramework,
|
||||||
|
castingToText: widget.castingToText,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,29 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_cast_framework/cast.dart';
|
import 'package:flutter_cast_framework/cast.dart';
|
||||||
|
|
||||||
|
/// Placeholder to be used for the castingToText of ExpandedControlsConnectedDeviceLabel
|
||||||
|
const CAST_DEVICE_NAME_PLACEHOLDER = "{{cast_device_name}}";
|
||||||
|
|
||||||
class ExpandedControlsConnectedDeviceLabel extends StatelessWidget {
|
class ExpandedControlsConnectedDeviceLabel extends StatelessWidget {
|
||||||
final FlutterCastFramework castFramework;
|
final FlutterCastFramework castFramework;
|
||||||
final String castingToText;
|
final _defaultCastingToText = "Casting to $CAST_DEVICE_NAME_PLACEHOLDER";
|
||||||
|
|
||||||
const ExpandedControlsConnectedDeviceLabel({
|
/// Label to introduce cast device. Default is "Casting to {{cast_device_name}}",
|
||||||
|
/// where {{cast_device_name}} is replaced with the device name.
|
||||||
|
/// {{cast_device_name}} can be found in the constant CAST_DEVICE_NAME_PLACEHOLDER.
|
||||||
|
final String? castingToText;
|
||||||
|
|
||||||
|
ExpandedControlsConnectedDeviceLabel({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.castFramework,
|
required this.castFramework,
|
||||||
this.castingToText = "Casting to",
|
this.castingToText,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
String _replaceDeviceName(String textWithPlaceholder, String deviceName) {
|
||||||
|
return textWithPlaceholder.replaceAll(
|
||||||
|
CAST_DEVICE_NAME_PLACEHOLDER, deviceName);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final textStyle =
|
final textStyle =
|
||||||
|
|
@ -21,9 +34,11 @@ class ExpandedControlsConnectedDeviceLabel extends StatelessWidget {
|
||||||
future: castFramework.castContext.sessionManager.getCastDevice(),
|
future: castFramework.castContext.sessionManager.getCastDevice(),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
var castDevice = snapshot.data;
|
final castDevice = snapshot.data;
|
||||||
var castDeviceName = castDevice?.friendlyName ?? "";
|
final castDeviceName = castDevice?.friendlyName ?? "";
|
||||||
return Text("$castingToText $castDeviceName", style: textStyle);
|
final baseCastLabel = castingToText ?? _defaultCastingToText;
|
||||||
|
final label = _replaceDeviceName(baseCastLabel, castDeviceName);
|
||||||
|
return Text(label, style: textStyle);
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
debugPrint("error while retrieving cast device ${snapshot.error}");
|
debugPrint("error while retrieving cast device ${snapshot.error}");
|
||||||
return Text("");
|
return Text("");
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@ export 'src/cast/widgets/expanded_controls/ExpandedControls.dart';
|
||||||
export 'src/cast/widgets/expanded_controls/ExpandedControlsPlayer.dart';
|
export 'src/cast/widgets/expanded_controls/ExpandedControlsPlayer.dart';
|
||||||
export 'src/cast/widgets/expanded_controls/ExpandedControlsProgress.dart';
|
export 'src/cast/widgets/expanded_controls/ExpandedControlsProgress.dart';
|
||||||
export 'src/cast/widgets/expanded_controls/ExpandedControlsToolbar.dart';
|
export 'src/cast/widgets/expanded_controls/ExpandedControlsToolbar.dart';
|
||||||
|
export 'src/cast/widgets/expanded_controls/ExpandedControlsConnectedDeviceLabel.dart';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue