|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_dogfooding/theme/app_palette.dart'; |
| 3 | +import 'package:flutter_dogfooding/widgets/settings_menu/standard_action_menu_item.dart'; |
| 4 | +import 'package:stream_video_flutter/stream_video_flutter.dart'; |
| 5 | + |
| 6 | +class NoiseCancellationMenuItem extends StatefulWidget { |
| 7 | + const NoiseCancellationMenuItem({ |
| 8 | + super.key, |
| 9 | + required this.call, |
| 10 | + }); |
| 11 | + |
| 12 | + final Call call; |
| 13 | + |
| 14 | + @override |
| 15 | + State<NoiseCancellationMenuItem> createState() => |
| 16 | + _NoiseCancellationMenuItemState(); |
| 17 | +} |
| 18 | + |
| 19 | +class _NoiseCancellationMenuItemState extends State<NoiseCancellationMenuItem> { |
| 20 | + @override |
| 21 | + Widget build(BuildContext context) { |
| 22 | + return StreamBuilder( |
| 23 | + stream: widget.call.state.asStream(), |
| 24 | + builder: (context, snapshot) { |
| 25 | + if (snapshot.hasData) { |
| 26 | + final callState = snapshot.data as CallState; |
| 27 | + |
| 28 | + if (callState.settings.audio.noiseCancellation?.mode == |
| 29 | + NoiceCancellationSettingsMode.disabled) { |
| 30 | + return const SizedBox.shrink(); |
| 31 | + } |
| 32 | + |
| 33 | + return Column( |
| 34 | + children: [ |
| 35 | + const SizedBox(height: 16), |
| 36 | + StandardActionMenuItem( |
| 37 | + icon: callState.isAudioProcessing |
| 38 | + ? Icons.hearing |
| 39 | + : Icons.hearing_disabled, |
| 40 | + label: 'Toggle Noise Cancellation', |
| 41 | + trailing: Text( |
| 42 | + callState.isAudioProcessing ? 'On' : 'Off', |
| 43 | + style: TextStyle( |
| 44 | + color: callState.isAudioProcessing |
| 45 | + ? AppColorPalette.appGreen |
| 46 | + : null, |
| 47 | + ), |
| 48 | + ), |
| 49 | + onPressed: () { |
| 50 | + if (!callState.isAudioProcessing) { |
| 51 | + widget.call.startAudioProcessing(); |
| 52 | + } else { |
| 53 | + widget.call.stopAudioProcessing(); |
| 54 | + } |
| 55 | + }, |
| 56 | + ), |
| 57 | + ], |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + return const SizedBox.shrink(); |
| 62 | + }); |
| 63 | + } |
| 64 | +} |
0 commit comments