diff --git a/lib/src/widgets/recording_button.dart b/lib/src/widgets/recording_button.dart index 1453446..d7011b9 100644 --- a/lib/src/widgets/recording_button.dart +++ b/lib/src/widgets/recording_button.dart @@ -169,7 +169,8 @@ class _RecordingButtonState extends State await _speechService.stopListening(); } else { await _speechService.startListening( - partialResults: widget.partialResults); + partialResults: widget.partialResults, + ); } } catch (e) { widget.onError?.call(SpeechRecognitionError( @@ -191,60 +192,60 @@ class _RecordingButtonState extends State @override Widget build(BuildContext context) { - Color buttonColor; + Color iconColor; if (!widget.enabled || !_isInitialized) { - buttonColor = widget.disabledColor ?? Colors.grey[400]!; - } else if (_isProcessing) { - buttonColor = _isListening - ? (widget.recordingColor ?? const Color(0xFFFF5252)) - .withValues(alpha: 0.7) - : (widget.idleColor ?? const Color(0xFF2196F3)) - .withValues(alpha: 0.7); - } else if (_isListening) { - buttonColor = widget.recordingColor ?? const Color(0xFFFF5252); // 红色停止按钮 + iconColor = widget.disabledColor ?? Colors.grey[850]!; } else { - buttonColor = widget.idleColor ?? const Color(0xFF2196F3); // 蓝色录音按钮 + iconColor = _isListening + ? (widget.recordingColor ?? const Color(0xFFFF5252)) + : (widget.idleColor ?? const Color(0xFF2196F3)); } Widget button = AnimatedBuilder( animation: _scaleAnimation, builder: (context, child) { - return Transform.scale( - scale: _scaleAnimation.value, - child: Container( - width: widget.size, - height: widget.size, - decoration: BoxDecoration( - color: buttonColor, - shape: BoxShape.circle, - boxShadow: [ - BoxShadow( - color: buttonColor.withValues(alpha: 0.3), - blurRadius: _isListening ? 20 : 12, - spreadRadius: _isListening ? 5 : 3, - ), - ], - ), - child: Material( - color: Colors.transparent, - child: InkWell( - borderRadius: BorderRadius.circular(widget.size / 2), - onTap: _toggleRecording, - child: _isProcessing - ? SizedBox( - width: widget.size * 0.4, - height: widget.size * 0.4, + return Container( + width: widget.size, + height: widget.size, + decoration: BoxDecoration( + color: iconColor.withValues(alpha: 0.12), + shape: BoxShape.circle, + ), + child: Material( + color: Colors.transparent, + child: InkWell( + borderRadius: BorderRadius.circular(widget.size / 2), + onTap: _toggleRecording, + child: Stack( + children: [ + Positioned( + left: 0, + right: 0, + bottom: 0, + top: 0, + child: Icon( + _isListening ? Icons.stop_rounded : Icons.mic_rounded, + size: widget.size * 0.55, + color: iconColor, + ), + ), + if (_isProcessing || _isListening) + Positioned( + left: 0, + right: 0, + bottom: 0, + top: 0, + child: SizedBox( + width: widget.size, + height: widget.size, child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white), ), - ) - : Icon( - _isListening ? Icons.stop_rounded : Icons.mic_rounded, - size: widget.size * (_isListening ? 0.35 : 0.4), - color: Colors.white, ), + ) + ], ), ), ),