[mob] Fix cast button refresh state

This commit is contained in:
Neeraj Gupta 2024-05-06 14:17:59 +05:30
parent 4da4dcaeb5
commit 06e43bf276

View file

@ -93,6 +93,8 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
late bool isInternalUser;
late GalleryType galleryType;
final ValueNotifier<int> castNotifier = ValueNotifier<int>(0);
@override
void initState() {
super.initState();
@ -328,14 +330,16 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
Tooltip(
message: "Cast album",
child: IconButton(
icon: castService.getActiveSessions().isNotEmpty
? const Icon(Icons.cast_connected_rounded)
: const Icon(Icons.cast_outlined),
icon: ValueListenableBuilder<int>(
valueListenable: castNotifier,
builder: (context, value, child) {
return castService.getActiveSessions().isNotEmpty
? const Icon(Icons.cast_connected_rounded)
: const Icon(Icons.cast_outlined);
},
),
onPressed: () async {
await _castChoiceDialog();
if (mounted) {
setState(() {});
}
},
),
),
@ -728,6 +732,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
await castService.closeActiveCasts();
},
);
castNotifier.value++;
return;
}
@ -785,7 +790,10 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
String lastCode = '';
Future<bool> _castPair(
BuildContext bContext, CastGateway gw, String code) async {
BuildContext bContext,
CastGateway gw,
String code,
) async {
try {
if (lastCode == code) {
return false;
@ -810,6 +818,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
);
_logger.info("Casted album with token $castToken");
// showToast(bContext, S.of(context).pairingComplete);
castNotifier.value++;
return true;
} catch (e, s) {
lastCode = '';
@ -823,6 +832,7 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
} else {
await showGenericErrorDialog(context: bContext, error: e);
}
castNotifier.value++;
return false;
}
}