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:
Max 2025-09-09 16:22:38 +08:00
parent aba8b44ab8
commit e961996ec6
1 changed files with 4 additions and 84 deletions

View File

@ -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 = ''; //
});
}