Fix CastButton and CastIcon

- CastButton padding
- CastIcon `setState() after dispose()`
This commit is contained in:
gianlucaparadise 2021-10-26 07:42:19 +02:00
parent 2eb46b4f0f
commit 8fefb7dbe9
2 changed files with 18 additions and 6 deletions

View file

@ -5,16 +5,21 @@ import 'CastIcon.dart';
class CastButton extends StatelessWidget { class CastButton extends StatelessWidget {
final Color color; final Color color;
final EdgeInsets padding;
CastButton({ CastButton({
required this.color, this.color = const Color(0xFFFFFFFF), // white
this.padding = const EdgeInsets.all(8.0),
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
child: CastIcon( child: Padding(
color: color, padding: padding,
child: CastIcon(
color: color,
),
), ),
onTap: () => FlutterCastFramework.castContext.showCastChooserDialog()); onTap: () => FlutterCastFramework.castContext.showCastChooserDialog());
} }

View file

@ -39,7 +39,10 @@ class _CastIconState extends State<CastIcon> with TickerProviderStateMixin {
} }
void _onCastStateChanged() { void _onCastStateChanged() {
if (!mounted) return;
setState(() { setState(() {
if (!mounted) return;
_castState = FlutterCastFramework.castContext.state.value; _castState = FlutterCastFramework.castContext.state.value;
}); });
} }
@ -101,6 +104,7 @@ class _ConnectingIconState extends State<_ConnectingIcon> {
if (!this.mounted) return; if (!this.mounted) return;
setState(() { setState(() {
if (!mounted) return;
_frameIndex = 0; _frameIndex = 0;
isAnimating = true; isAnimating = true;
}); });
@ -111,9 +115,12 @@ class _ConnectingIconState extends State<_ConnectingIcon> {
if (_frameIndex < _connectingAnimationFrames.length - 1) { if (_frameIndex < _connectingAnimationFrames.length - 1) {
await Future.delayed(const Duration(milliseconds: 300)); await Future.delayed(const Duration(milliseconds: 300));
setState(() { if (mounted) {
_frameIndex += 1; setState(() {
}); if (!mounted) return;
_frameIndex += 1;
});
}
} else { } else {
// When I reach the end, I re-start from the beginning // When I reach the end, I re-start from the beginning
await Future.delayed(const Duration(seconds: 1)); await Future.delayed(const Duration(seconds: 1));