Remove recognition history functionality
Complete removal of recognition history features: 1. State Variables Removed: - _recognitionHistory list variable - _realtimeResults list variable - All history-related state management 2. Methods Updated: - _clearHistory() renamed to _clearContent() - Simplified to only clear current text and base text - Removed history list operations 3. UI Components Removed: - _buildHistoryCard() method completely removed - History card from main layout removed - History-related ListView and ListTile widgets removed 4. Callback Logic Simplified: - onListeningStatusChanged callback cleaned up - Removed history insertion logic when recording stops - Removed _realtimeResults.clear() operations - Simplified state management to focus only on current text 5. App Bar Updated: - Clear button tooltip changed from '清除历史' to '清除内容' - Button now calls _clearContent() instead of _clearHistory() The app now focuses purely on real-time speech recognition with editable text input, without maintaining any recognition history. This simplifies the codebase and improves performance by removing unnecessary data storage and UI rendering.
This commit is contained in:
parent
aba8b44ab8
commit
e961996ec6
|
|
@ -40,14 +40,10 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
|
|||
bool _isListening = false;
|
||||
String _currentText = '';
|
||||
String _errorMessage = '';
|
||||
List<String> _recognitionHistory = [];
|
||||
|
||||
/// 本次录音开始前的文本内容(用于实时追加)
|
||||
String _baseText = '';
|
||||
|
||||
// 录音相关
|
||||
final List<String> _realtimeResults = []; // 存储实时识别片段
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
|
@ -152,11 +148,9 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
|
|||
);
|
||||
}
|
||||
|
||||
/// 清除历史记录
|
||||
void _clearHistory() {
|
||||
/// 清除内容
|
||||
void _clearContent() {
|
||||
setState(() {
|
||||
_recognitionHistory.clear();
|
||||
_realtimeResults.clear();
|
||||
_currentText = '';
|
||||
_baseText = ''; // 也清空基础文本
|
||||
_textController.clear();
|
||||
|
|
@ -173,8 +167,8 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
|
|||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear_all),
|
||||
onPressed: _clearHistory,
|
||||
tooltip: '清除历史',
|
||||
onPressed: _clearContent,
|
||||
tooltip: '清除内容',
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
@ -189,9 +183,6 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
|
|||
// 识别结果卡片
|
||||
_buildRecognitionCard(),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 历史记录
|
||||
Expanded(child: _buildHistoryCard()),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
@ -396,66 +387,6 @@ class _SpeechRecognitionPageState extends State<SpeechRecognitionPage> {
|
|||
);
|
||||
}
|
||||
|
||||
/// 构建历史记录卡片
|
||||
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<SpeechRecognitionPage> {
|
|||
});
|
||||
|
||||
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<SpeechRecognitionPage> {
|
|||
// 开始录音时记录当前文本作为基础,清空当前识别文本
|
||||
setState(() {
|
||||
_baseText = _textController.text; // 记录录音开始前的文本
|
||||
_realtimeResults.clear();
|
||||
_currentText = ''; // 清空当前识别文本
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue