-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: transcribe button in speech modal
- Loading branch information
Showing
4 changed files
with
70 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
lib/features/speech/ui/widgets/speech_modal/transcribe_button.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:lotti/classes/journal_entities.dart'; | ||
import 'package:lotti/features/journal/state/entry_controller.dart'; | ||
import 'package:lotti/features/speech/state/asr_service.dart'; | ||
import 'package:lotti/features/speech/ui/widgets/transcription_progress_modal.dart'; | ||
import 'package:lotti/get_it.dart'; | ||
import 'package:lotti/l10n/app_localizations_context.dart'; | ||
|
||
class TranscribeButton extends ConsumerWidget { | ||
const TranscribeButton({ | ||
required this.entryId, | ||
super.key, | ||
}); | ||
|
||
final String entryId; | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
if (!(Platform.isMacOS || Platform.isIOS)) { | ||
return const SizedBox.shrink(); | ||
} | ||
|
||
final provider = entryControllerProvider(id: entryId); | ||
|
||
final notifier = ref.read(provider.notifier); | ||
|
||
final entryState = ref.watch(provider).value; | ||
|
||
final item = entryState?.entry; | ||
if (item == null || item is! JournalAudio) { | ||
return const SizedBox.shrink(); | ||
} | ||
|
||
return TextButton( | ||
onPressed: () async { | ||
final isQueueEmpty = getIt<AsrService>().enqueue(entry: item); | ||
|
||
if (await isQueueEmpty) { | ||
if (!context.mounted) return; | ||
await TranscriptionProgressModal.show(context); | ||
} | ||
|
||
await Future<void>.delayed( | ||
const Duration(milliseconds: 100), | ||
); | ||
notifier | ||
..setController() | ||
..emitState(); | ||
}, | ||
child: Padding( | ||
padding: const EdgeInsets.all(10), | ||
child: Row( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
const Icon(Icons.transcribe_rounded), | ||
const SizedBox(width: 10), | ||
Text(context.messages.speechModalAddTranscription), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters