diff --git a/example/lib/main.dart b/example/lib/main.dart index b62d4a5..73824c2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -40,14 +40,10 @@ class _SpeechRecognitionPageState extends State { bool _isListening = false; String _currentText = ''; String _errorMessage = ''; - List _recognitionHistory = []; /// 本次录音开始前的文本内容(用于实时追加) String _baseText = ''; - // 录音相关 - final List _realtimeResults = []; // 存储实时识别片段 - @override void initState() { super.initState(); @@ -152,11 +148,9 @@ class _SpeechRecognitionPageState extends State { ); } - /// 清除历史记录 - void _clearHistory() { + /// 清除内容 + void _clearContent() { setState(() { - _recognitionHistory.clear(); - _realtimeResults.clear(); _currentText = ''; _baseText = ''; // 也清空基础文本 _textController.clear(); @@ -173,8 +167,8 @@ class _SpeechRecognitionPageState extends State { actions: [ IconButton( icon: const Icon(Icons.clear_all), - onPressed: _clearHistory, - tooltip: '清除历史', + onPressed: _clearContent, + tooltip: '清除内容', ), ], ), @@ -189,9 +183,6 @@ class _SpeechRecognitionPageState extends State { // 识别结果卡片 _buildRecognitionCard(), const SizedBox(height: 16), - - // 历史记录 - Expanded(child: _buildHistoryCard()), ], ), ), @@ -396,66 +387,6 @@ class _SpeechRecognitionPageState extends State { ); } - /// 构建历史记录卡片 - Widget _buildHistoryCard() { - return Card( - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - '识别历史', - style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), - ), - const SizedBox(height: 16), - Expanded( - child: _recognitionHistory.isEmpty - ? Center( - child: Text( - '暂无识别历史', - style: TextStyle( - color: Colors.grey[600], - fontStyle: FontStyle.italic, - ), - ), - ) - : ListView.builder( - itemCount: _recognitionHistory.length, - itemBuilder: (context, index) { - return Card( - margin: const EdgeInsets.only(bottom: 8.0), - child: ListTile( - leading: CircleAvatar( - backgroundColor: Theme.of(context).primaryColor, - child: Text( - '${index + 1}', - style: const TextStyle(color: Colors.white), - ), - ), - title: Text(_recognitionHistory[index]), - trailing: IconButton( - icon: const Icon(Icons.copy), - onPressed: () { - // TODO: 实现复制到剪贴板功能 - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar( - content: Text('已复制到剪贴板'), - ), - ); - }, - ), - ), - ); - }, - ), - ), - ], - ), - ), - ); - } - /// 构建浮动操作按钮 Widget _buildFloatingActionButton() { if (!_isInitialized) { @@ -508,16 +439,6 @@ class _SpeechRecognitionPageState extends State { }); if (!isListening) { - // 录音结束后,确认当前文本并保存到历史记录 - if (_currentText.isNotEmpty) { - setState(() { - _recognitionHistory.insert(0, _currentText); - // 限制历史记录数量 - if (_recognitionHistory.length > 10) { - _recognitionHistory.removeLast(); - } - }); - } // 录音结束后,更新基础文本为下次录音做准备 setState(() { _baseText = _textController.text; // 保存当前文本作为下次的基础 @@ -527,7 +448,6 @@ class _SpeechRecognitionPageState extends State { // 开始录音时记录当前文本作为基础,清空当前识别文本 setState(() { _baseText = _textController.text; // 记录录音开始前的文本 - _realtimeResults.clear(); _currentText = ''; // 清空当前识别文本 }); }