86 lines
3.0 KiB
Dart
86 lines
3.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../../../ui/theme/app_design_tokens.dart';
|
|
import '../../speech/speech.dart';
|
|
|
|
const chatSpeakingStopLabel = 'Stop speaking';
|
|
|
|
/// "Speaking · Chat name" and Stop for the reply the app is reading, from any
|
|
/// chat: the reader is the app's, so a reply keeps reading after its chat is
|
|
/// left, and this is the one place to stop it without going back. Nothing
|
|
/// while no reply reads (the Settings voice sample included).
|
|
class ChatSpeakingControl extends StatelessWidget {
|
|
const ChatSpeakingControl({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ValueListenableBuilder(
|
|
valueListenable: speechReading,
|
|
builder: (context, reading, _) {
|
|
final speech = speechControllerIfCreated;
|
|
if (reading == null || speech == null) return const SizedBox.shrink();
|
|
return ListenableBuilder(
|
|
listenable: speech,
|
|
builder: (context, _) => _pill(context, speech, reading),
|
|
);
|
|
},
|
|
);
|
|
|
|
Widget _pill(
|
|
BuildContext context,
|
|
SpeechController speech,
|
|
SpeechReading reading,
|
|
) {
|
|
final scheme = Theme.of(context).colorScheme;
|
|
final tokens = AppDesignTokens.of(context);
|
|
final state = speech.state == SpeechState.paused ? 'Paused' : 'Speaking';
|
|
final title = reading.title.isEmpty ? 'a chat' : reading.title;
|
|
final label = '$state · $title';
|
|
final text = Theme.of(context).textTheme.labelMedium;
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.only(bottom: 8),
|
|
child: Align(
|
|
alignment: AlignmentDirectional.centerStart,
|
|
child: Material(
|
|
key: const Key('chat-speaking-control'),
|
|
color: tokens.panelFill(scheme, scheme.surfaceContainerHigh),
|
|
shape: tokens
|
|
.shape(const StadiumBorder())
|
|
.copyWith(side: tokens.frameSide),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Padding(
|
|
padding: const EdgeInsetsDirectional.only(start: 12),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.graphic_eq, size: 16, color: scheme.primary),
|
|
const SizedBox(width: 8),
|
|
Flexible(
|
|
child: Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
label,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: text?.copyWith(color: scheme.onSurfaceVariant),
|
|
),
|
|
),
|
|
),
|
|
IconButton(
|
|
key: const Key('chat-speaking-stop'),
|
|
tooltip: chatSpeakingStopLabel,
|
|
visualDensity: VisualDensity.compact,
|
|
iconSize: 18,
|
|
onPressed: () => unawaited(speech.stop()),
|
|
icon: const Icon(Icons.stop),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|