feat: 长辈模式(大字大按钮 + 偏好按账号隔离)+ 语音输入(按住说话 + 实时转写 + 后端代理 DashScope ASR + 患者端专用)+ 健康仪表盘背景渐变

This commit is contained in:
MingNian
2026-07-21 10:53:16 +08:00
parent 0cb5b8e85a
commit 28f704c98e
25 changed files with 2214 additions and 131 deletions

View File

@@ -7,11 +7,15 @@ import 'package:file_picker/file_picker.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import '../../core/app_colors.dart';
import '../../core/app_design_tokens.dart';
import '../../core/elder_mode_scope.dart';
import '../../core/app_module_visuals.dart';
import '../../core/navigation_provider.dart';
import '../../providers/auth_provider.dart';
import '../../providers/chat_provider.dart';
import '../../providers/data_providers.dart';
import '../../providers/elder_mode_provider.dart';
import '../../services/realtime_speech_service.dart';
import '../../widgets/app_toast.dart';
import '../../widgets/health_drawer.dart';
import '../../widgets/keyboard_lift.dart';
import '../diet/diet_capture_page.dart';
@@ -32,6 +36,15 @@ class _HomePageState extends ConsumerState<HomePage>
String? _pickedImagePath;
Timer? _notificationTimer;
double _conversationDragDistance = 0;
bool _voiceMode = false;
_SpeechPhase _speechPhase = _SpeechPhase.idle;
RealtimeSpeechSession? _speechSession;
StreamSubscription<SpeechRecognitionEvent>? _speechEventSubscription;
String _speechText = '';
bool _voicePressActive = false;
bool _cancelVoiceOnRelease = false;
bool _finishVoiceWhenReady = false;
double? _voicePressStartY;
void _startConversationDrawerDrag(DragStartDetails details) {
_conversationDragDistance = 0;
@@ -55,6 +68,8 @@ class _HomePageState extends ConsumerState<HomePage>
@override
void initState() {
super.initState();
final elderPreferences = ref.read(elderModeProvider).preferences;
_voiceMode = elderPreferences.enabled && elderPreferences.voiceInputEnabled;
WidgetsBinding.instance.addObserver(this);
_scheduleScrollToLatest();
WidgetsBinding.instance.addPostFrameCallback((_) {
@@ -72,6 +87,10 @@ class _HomePageState extends ConsumerState<HomePage>
if (state == AppLifecycleState.resumed) {
_checkDueNotifications();
}
if (state == AppLifecycleState.paused &&
_speechPhase != _SpeechPhase.idle) {
unawaited(_cancelVoiceRecording());
}
}
@override
@@ -81,6 +100,8 @@ class _HomePageState extends ConsumerState<HomePage>
_textCtrl.dispose();
_scrollCtrl.dispose();
_focusNode.dispose();
unawaited(_speechEventSubscription?.cancel());
unawaited(_speechSession?.cancel());
super.dispose();
}
@@ -124,6 +145,19 @@ class _HomePageState extends ConsumerState<HomePage>
final auth = ref.watch(authProvider);
final user = auth.user;
ref.listen<bool>(
elderModeProvider.select(
(state) => state.isEnabled && state.preferences.voiceInputEnabled,
),
(previous, current) {
if (previous == current || !mounted) return;
if (_speechPhase != _SpeechPhase.idle) {
unawaited(_cancelVoiceRecording());
}
setState(() => _voiceMode = current);
},
);
ref.listen(cameraActionProvider, (prev, next) {
if (next == 'camera') {
_pickImage(ImageSource.camera);
@@ -202,12 +236,13 @@ class _HomePageState extends ConsumerState<HomePage>
}
Widget _buildHeader(dynamic user) {
final elderMode = ElderModeScope.enabledOf(context);
final name = (user?.name != null && user!.name!.isNotEmpty)
? user.name
: '用户';
final unreadCount = ref.watch(notificationUnreadCountProvider).value ?? 0;
return Container(
padding: const EdgeInsets.fromLTRB(14, 8, 14, 6),
padding: EdgeInsets.fromLTRB(14, elderMode ? 10 : 8, 14, 6),
child: Row(
children: [
Builder(
@@ -234,8 +269,8 @@ class _HomePageState extends ConsumerState<HomePage>
const SizedBox(height: 2),
Text(
'${_getGreeting()}$name',
style: const TextStyle(
fontSize: 18,
style: TextStyle(
fontSize: elderMode ? 20 : 18,
fontWeight: FontWeight.w600,
color: AppColors.textPrimary,
),
@@ -271,11 +306,12 @@ class _HomePageState extends ConsumerState<HomePage>
];
Widget _buildAgentBar() {
final elderMode = ElderModeScope.enabledOf(context);
final activeAgent = ref.watch(
chatProvider.select((state) => state.activeAgent),
);
return SizedBox(
height: 46,
height: elderMode ? 58 : 46,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2),
@@ -297,9 +333,9 @@ class _HomePageState extends ConsumerState<HomePage>
),
padding: const EdgeInsets.all(1.2),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 11.8,
vertical: 7.8,
padding: EdgeInsets.symmetric(
horizontal: elderMode ? 15 : 11.8,
vertical: elderMode ? 10 : 7.8,
),
decoration: BoxDecoration(
color: Colors.white,
@@ -309,23 +345,23 @@ class _HomePageState extends ConsumerState<HomePage>
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 18,
height: 18,
width: elderMode ? 24 : 18,
height: elderMode ? 24 : 18,
decoration: BoxDecoration(
gradient: visual.gradient,
borderRadius: BorderRadius.circular(6),
),
child: Icon(
visual.icon,
size: 13,
size: elderMode ? 17 : 13,
color: visual.iconColor,
),
),
const SizedBox(width: 6),
Text(
visual.label,
style: const TextStyle(
fontSize: 15,
style: TextStyle(
fontSize: elderMode ? 17 : 15,
fontWeight: FontWeight.w700,
color: AppColors.textPrimary,
),
@@ -438,98 +474,315 @@ class _HomePageState extends ConsumerState<HomePage>
}
Widget _buildInputBar() {
final elderMode = ElderModeScope.enabledOf(context);
final isStreaming = ref.watch(
chatProvider.select((state) => state.isStreaming),
);
return Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 10),
child: Container(
padding: const EdgeInsets.fromLTRB(6, 5, 6, 5),
padding: EdgeInsets.fromLTRB(
6,
elderMode ? 7 : 5,
6,
elderMode ? 7 : 5,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: AppRadius.pillBorder,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Material(
color: Colors.transparent,
child: InkWell(
customBorder: const CircleBorder(),
onTap: () => _showAttachmentPicker(context),
child: Ink(
width: 38,
height: 38,
decoration: const BoxDecoration(
gradient: AppColors.primaryGradient,
shape: BoxShape.circle,
),
child: const Icon(
LucideIcons.plus,
size: 21,
color: Colors.white,
),
),
),
),
const SizedBox(width: 6),
Expanded(
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 112),
child: TextField(
controller: _textCtrl,
focusNode: _focusNode,
style: const TextStyle(
fontSize: 15,
color: AppColors.textPrimary,
),
maxLines: null,
textInputAction: TextInputAction.newline,
decoration: const InputDecoration(
hintText: '输入你想说的...',
filled: false,
isDense: true,
contentPadding: EdgeInsets.symmetric(
horizontal: 4,
vertical: 12,
),
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
),
onSubmitted: (_) => _sendMessage(),
),
),
),
const SizedBox(width: 6),
Material(
color: Colors.transparent,
child: InkWell(
customBorder: const CircleBorder(),
onTap: isStreaming
? () => ref.read(chatProvider.notifier).stopGenerating()
: _sendMessage,
child: Ink(
width: 38,
height: 38,
decoration: const BoxDecoration(
gradient: AppColors.primaryGradient,
shape: BoxShape.circle,
),
child: Icon(
isStreaming ? Icons.stop_rounded : LucideIcons.send,
size: 18,
color: Colors.white,
),
),
),
),
],
children: _voiceMode
? _buildVoiceInputContents(elderMode, isStreaming)
: _buildTextInputContents(elderMode, isStreaming),
),
),
);
}
List<Widget> _buildTextInputContents(bool elderMode, bool isStreaming) {
return [
_InputCircleButton(
icon: LucideIcons.plus,
elderMode: elderMode,
gradient: AppColors.primaryGradient,
iconColor: Colors.white,
onTap: () => _showAttachmentPicker(context),
),
const SizedBox(width: 6),
Expanded(
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 112),
child: TextField(
controller: _textCtrl,
focusNode: _focusNode,
style: TextStyle(
fontSize: elderMode ? 18 : 15,
color: AppColors.textPrimary,
),
maxLines: null,
textInputAction: TextInputAction.newline,
decoration: InputDecoration(
hintText: '输入你想说的...',
filled: false,
isDense: true,
contentPadding: EdgeInsets.symmetric(
horizontal: 4,
vertical: elderMode ? 15 : 12,
),
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
),
onSubmitted: (_) => _sendMessage(),
),
),
),
const SizedBox(width: 4),
_InputCircleButton(
icon: LucideIcons.mic,
elderMode: elderMode,
gradient: AppColors.primaryGradient,
iconColor: Colors.white,
onTap: isStreaming ? null : _switchToVoiceMode,
),
const SizedBox(width: 4),
_InputCircleButton(
icon: isStreaming ? Icons.stop_rounded : LucideIcons.send,
elderMode: elderMode,
gradient: AppColors.primaryGradient,
iconColor: Colors.white,
onTap: isStreaming
? () => ref.read(chatProvider.notifier).stopGenerating()
: _sendMessage,
),
];
}
List<Widget> _buildVoiceInputContents(bool elderMode, bool isStreaming) {
return [
_InputCircleButton(
icon: LucideIcons.plus,
elderMode: elderMode,
gradient: AppColors.primaryGradient,
iconColor: Colors.white,
onTap: _speechPhase == _SpeechPhase.idle
? () => _showAttachmentPicker(context)
: null,
),
const SizedBox(width: 6),
Expanded(
child: isStreaming
? InkWell(
onTap: () => ref.read(chatProvider.notifier).stopGenerating(),
borderRadius: AppRadius.pillBorder,
child: _VoiceHoldSurface(
elderMode: elderMode,
label: '停止生成',
color: AppColors.primary,
),
)
: Listener(
behavior: HitTestBehavior.opaque,
onPointerDown: _onVoicePointerDown,
onPointerMove: _onVoicePointerMove,
onPointerUp: _onVoicePointerUp,
onPointerCancel: _onVoicePointerCancel,
child: _VoiceHoldSurface(
elderMode: elderMode,
label: _voiceInputLabel,
color: _voiceLabelColor,
),
),
),
const SizedBox(width: 4),
_InputCircleButton(
icon: LucideIcons.keyboard,
elderMode: elderMode,
gradient: AppColors.primaryGradient,
iconColor: Colors.white,
onTap: _speechPhase == _SpeechPhase.idle ? _switchToTextMode : null,
),
];
}
String get _voiceInputLabel {
if (_cancelVoiceOnRelease) return '松开取消';
return switch (_speechPhase) {
_SpeechPhase.connecting => '正在连接…',
_SpeechPhase.listening =>
_speechText.trim().isEmpty ? '松开发送' : _speechText.trim(),
_SpeechPhase.finishing => '正在识别…',
_SpeechPhase.idle => '按住说话',
};
}
Color get _voiceLabelColor {
if (_cancelVoiceOnRelease) return AppColors.error;
if (_speechPhase == _SpeechPhase.listening ||
_speechPhase == _SpeechPhase.connecting ||
_speechPhase == _SpeechPhase.finishing) {
return AppColors.primary;
}
return AppColors.textSecondary;
}
Future<void> _switchToVoiceMode() async {
_dismissKeyboard();
final allowed = await ref
.read(realtimeSpeechServiceProvider)
.requestPermission();
if (!mounted) return;
if (!allowed) {
AppToast.show(context, '需要麦克风权限才能使用语音输入', type: AppToastType.error);
return;
}
setState(() => _voiceMode = true);
}
void _switchToTextMode() {
if (_speechPhase != _SpeechPhase.idle) return;
setState(() => _voiceMode = false);
}
void _onVoicePointerDown(PointerDownEvent event) {
if (_speechPhase != _SpeechPhase.idle) return;
_voicePressActive = true;
_cancelVoiceOnRelease = false;
_finishVoiceWhenReady = false;
_voicePressStartY = event.position.dy;
unawaited(_startVoiceRecording());
}
void _onVoicePointerMove(PointerMoveEvent event) {
if (!_voicePressActive || _voicePressStartY == null) return;
final shouldCancel = _voicePressStartY! - event.position.dy >= 60;
if (shouldCancel != _cancelVoiceOnRelease && mounted) {
setState(() => _cancelVoiceOnRelease = shouldCancel);
}
}
void _onVoicePointerUp(PointerUpEvent event) {
if (!_voicePressActive) return;
_voicePressActive = false;
if (_speechPhase == _SpeechPhase.connecting) {
_finishVoiceWhenReady = true;
return;
}
if (_cancelVoiceOnRelease) {
unawaited(_cancelVoiceRecording());
} else if (_speechPhase == _SpeechPhase.listening) {
unawaited(_finishVoiceRecording());
}
}
void _onVoicePointerCancel(PointerCancelEvent event) {
if (!_voicePressActive) return;
_voicePressActive = false;
_cancelVoiceOnRelease = true;
unawaited(_cancelVoiceRecording());
}
Future<void> _startVoiceRecording() async {
setState(() {
_speechPhase = _SpeechPhase.connecting;
_speechText = '';
});
try {
final session = await ref.read(realtimeSpeechServiceProvider).start();
if (!mounted) {
await session.cancel();
return;
}
_speechSession = session;
_speechEventSubscription = session.events.listen((event) {
if (!mounted) return;
if (event.type == SpeechRecognitionEventType.error) {
_handleSpeechFailure(event.text);
return;
}
setState(() => _speechText = event.text);
});
setState(() => _speechPhase = _SpeechPhase.listening);
if (_finishVoiceWhenReady || !_voicePressActive) {
if (_cancelVoiceOnRelease) {
await _cancelVoiceRecording();
} else {
await _finishVoiceRecording();
}
}
} on SpeechRecognitionException catch (error) {
_handleSpeechFailure(error.message);
} catch (_) {
_handleSpeechFailure('语音输入启动失败,请稍后重试');
}
}
Future<void> _finishVoiceRecording() async {
final session = _speechSession;
if (session == null || _speechPhase == _SpeechPhase.finishing) return;
setState(() => _speechPhase = _SpeechPhase.finishing);
try {
final text = (await session.finish()).trim();
if (!mounted) return;
await _releaseSpeechSession();
if (!mounted) return;
_resetSpeechState();
if (text.isEmpty) {
AppToast.show(context, '没有听清,请再说一次');
return;
}
_textCtrl.text = text;
_sendMessage();
} on SpeechRecognitionException catch (error) {
_handleSpeechFailure(error.message);
} catch (_) {
_handleSpeechFailure('语音识别失败,请重试');
}
}
Future<void> _cancelVoiceRecording() async {
try {
await _speechSession?.cancel();
} finally {
await _releaseSpeechSession();
if (mounted) _resetSpeechState();
}
}
Future<void> _releaseSpeechSession() async {
await _speechEventSubscription?.cancel();
_speechEventSubscription = null;
await _speechSession?.dispose();
_speechSession = null;
}
void _handleSpeechFailure(String message) {
if (_speechPhase == _SpeechPhase.idle) return;
final partialText = _speechText.trim();
unawaited(_releaseSpeechSession());
if (!mounted) return;
_resetSpeechState();
if (partialText.isNotEmpty) {
_textCtrl.text = partialText;
setState(() => _voiceMode = false);
}
AppToast.show(context, message, type: AppToastType.error);
}
void _resetSpeechState() {
if (!mounted) return;
setState(() {
_speechPhase = _SpeechPhase.idle;
_speechText = '';
_voicePressActive = false;
_cancelVoiceOnRelease = false;
_finishVoiceWhenReady = false;
_voicePressStartY = null;
});
}
void _showAttachmentPicker(BuildContext context) {
_dismissKeyboard();
showModalBottomSheet(
@@ -649,6 +902,82 @@ class _HomePageState extends ConsumerState<HomePage>
}
}
enum _SpeechPhase { idle, connecting, listening, finishing }
class _InputCircleButton extends StatelessWidget {
final IconData icon;
final bool elderMode;
final Gradient? gradient;
final Color iconColor;
final VoidCallback? onTap;
const _InputCircleButton({
required this.icon,
required this.elderMode,
this.gradient,
required this.iconColor,
required this.onTap,
});
@override
Widget build(BuildContext context) {
final size = elderMode ? 52.0 : 38.0;
return Opacity(
opacity: onTap == null ? 0.45 : 1,
child: Material(
color: Colors.transparent,
child: InkWell(
customBorder: const CircleBorder(),
onTap: onTap,
child: Ink(
width: size,
height: size,
decoration: BoxDecoration(
gradient: gradient,
shape: BoxShape.circle,
),
child: Icon(icon, size: elderMode ? 25 : 20, color: iconColor),
),
),
),
);
}
}
class _VoiceHoldSurface extends StatelessWidget {
final bool elderMode;
final String label;
final Color color;
const _VoiceHoldSurface({
required this.elderMode,
required this.label,
required this.color,
});
@override
Widget build(BuildContext context) {
return Container(
padding: EdgeInsets.symmetric(
horizontal: 4,
vertical: elderMode ? 14 : 11,
),
alignment: Alignment.center,
child: Text(
label,
maxLines: 1,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: elderMode ? 20 : 17,
fontWeight: FontWeight.w700,
color: color,
),
),
);
}
}
class _HomeMessages extends ConsumerWidget {
final ScrollController scrollCtrl;
@@ -673,21 +1002,26 @@ class _HeaderIconButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final elderMode = ElderModeScope.enabledOf(context);
return GestureDetector(
onTap: onTap,
child: Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 44,
height: 44,
width: elderMode ? 54 : 44,
height: elderMode ? 54 : 44,
decoration: BoxDecoration(
gradient: AppColors.surfaceGradient,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: AppColors.borderLight),
boxShadow: AppColors.cardShadowLight,
),
child: Icon(icon, size: 20, color: AppColors.textPrimary),
child: Icon(
icon,
size: elderMode ? 27 : 20,
color: AppColors.textPrimary,
),
),
if (badgeCount > 0)
Positioned(

View File

@@ -0,0 +1,420 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/app_colors.dart';
import '../../core/app_design_tokens.dart';
import '../../core/navigation_provider.dart';
import '../../providers/elder_mode_provider.dart';
import '../../widgets/app_toast.dart';
class ElderModePage extends ConsumerWidget {
const ElderModePage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final state = ref.watch(elderModeProvider);
final enabled = state.isEnabled;
ref.listen<String?>(elderModeProvider.select((value) => value.error), (
previous,
next,
) {
if (next != null && next != previous) {
AppToast.show(context, next, type: AppToastType.error);
}
});
return Scaffold(
backgroundColor: const Color(0xFFF0F1FF),
appBar: AppBar(
backgroundColor: Colors.transparent,
leading: IconButton(
onPressed: () => popRoute(ref),
icon: const Icon(Icons.arrow_back_rounded),
),
title: const Text('长辈模式'),
),
body: DecoratedBox(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Color(0xFFE7ECFF), Color(0xFFF2F1FF)],
),
),
child: SafeArea(
top: false,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.fromLTRB(20, 18, 20, 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const _ElderHero(),
const SizedBox(height: 18),
if (enabled)
_EnabledPanel(
largeTextEnabled: state.preferences.largeTextEnabled,
voiceInputEnabled:
state.preferences.voiceInputEnabled,
saving: state.isSaving,
onLargeTextChanged: (value) => ref
.read(elderModeProvider.notifier)
.setLargeTextEnabled(value),
onVoiceInputChanged: (value) => ref
.read(elderModeProvider.notifier)
.setVoiceInputEnabled(value),
)
else
const _DisabledPanel(),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 18),
child: SizedBox(
height: 58,
width: double.infinity,
child: enabled
? OutlinedButton(
onPressed: state.isSaving
? null
: () => ref
.read(elderModeProvider.notifier)
.disable(),
style: OutlinedButton.styleFrom(
backgroundColor: Colors.white.withValues(
alpha: 0.72,
),
foregroundColor: AppColors.textSecondary,
side: const BorderSide(color: Color(0xFFD9DDF2)),
shape: RoundedRectangleBorder(
borderRadius: AppRadius.pillBorder,
),
),
child: const Text('关闭长辈模式'),
)
: ElevatedButton(
onPressed: state.isSaving
? null
: () => ref
.read(elderModeProvider.notifier)
.enable(),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF5B55E7),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: AppRadius.pillBorder,
),
),
child: const Text('立即开启'),
),
),
),
],
),
),
),
);
}
}
class _ElderHero extends StatelessWidget {
const _ElderHero();
@override
Widget build(BuildContext context) {
return Column(
children: [
const Text(
'暖心护长辈\n便捷新体验',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 34,
height: 1.25,
fontWeight: FontWeight.w800,
color: Color(0xFF252470),
),
),
const SizedBox(height: 8),
SizedBox(
height: 190,
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: 190,
height: 150,
decoration: BoxDecoration(
color: const Color(0xFFB8B9FF).withValues(alpha: 0.24),
shape: BoxShape.circle,
),
),
Image.asset(
'assets/branding/health_login_character_transparent.png',
height: 182,
fit: BoxFit.contain,
),
const Positioned(left: 4, top: 92, child: _HeroTag(label: '字更大')),
const Positioned(
right: 0,
top: 118,
child: _HeroTag(label: '更清楚'),
),
],
),
),
],
);
}
}
class _HeroTag extends StatelessWidget {
final String label;
const _HeroTag({required this.label});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 9),
decoration: BoxDecoration(
color: const Color(0xFF7B78E8).withValues(alpha: 0.72),
borderRadius: AppRadius.pillBorder,
border: Border.all(color: Colors.white.withValues(alpha: 0.72)),
),
child: Text(
label,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
);
}
}
class _DisabledPanel extends StatelessWidget {
const _DisabledPanel();
@override
Widget build(BuildContext context) {
return _ModePanel(
title: '开启长辈模式,操作更清晰',
child: const Column(
children: [
_FeatureRow(
icon: Icons.text_fields_rounded,
title: '大字体',
subtitle: '正文和按钮文字更大',
),
_PanelDivider(),
_FeatureRow(
icon: Icons.touch_app_rounded,
title: '大按钮',
subtitle: '点击区域更大,不易点错',
),
_PanelDivider(),
_FeatureRow(
icon: Icons.grid_view_rounded,
title: '大图标',
subtitle: '常用功能更醒目',
),
_PanelDivider(),
_FeatureRow(
icon: Icons.mic_rounded,
title: '语音输入',
subtitle: '首页默认使用按住说话',
),
],
),
);
}
}
class _EnabledPanel extends StatelessWidget {
final bool largeTextEnabled;
final bool voiceInputEnabled;
final bool saving;
final ValueChanged<bool> onLargeTextChanged;
final ValueChanged<bool> onVoiceInputChanged;
const _EnabledPanel({
required this.largeTextEnabled,
required this.voiceInputEnabled,
required this.saving,
required this.onLargeTextChanged,
required this.onVoiceInputChanged,
});
@override
Widget build(BuildContext context) {
return _ModePanel(
title: '长辈模式已开启',
subtitle: '大图标和大按钮已启用',
child: Column(
children: [
_FeatureRow(
icon: Icons.text_fields_rounded,
title: '大字体',
subtitle: '文字更大,阅读更轻松',
trailing: Switch(
value: largeTextEnabled,
onChanged: saving ? null : onLargeTextChanged,
activeTrackColor: const Color(0xFF5B55E7),
),
),
const _PanelDivider(),
_FeatureRow(
icon: Icons.mic_rounded,
title: '语音输入',
subtitle: '进入首页默认按住说话',
trailing: Switch(
value: voiceInputEnabled,
onChanged: saving ? null : onVoiceInputChanged,
activeTrackColor: const Color(0xFF5B55E7),
),
),
const _PanelDivider(),
const _FeatureRow(
icon: Icons.touch_app_rounded,
title: '大按钮大图标',
subtitle: '操作区域更大、更清楚',
trailing: Icon(
Icons.check_circle_rounded,
color: Color(0xFF5B55E7),
size: 30,
),
),
],
),
);
}
}
class _ModePanel extends StatelessWidget {
final String title;
final String? subtitle;
final Widget child;
const _ModePanel({required this.title, this.subtitle, required this.child});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.72),
borderRadius: AppRadius.cardBorder,
border: Border.all(color: Colors.white),
boxShadow: AppShadows.soft,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.w700,
color: Color(0xFF25244F),
),
),
if (subtitle != null) ...[
const SizedBox(height: 4),
Text(
subtitle!,
style: const TextStyle(
fontSize: 15,
color: AppColors.textSecondary,
),
),
],
const SizedBox(height: 14),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: AppRadius.xlBorder,
),
child: child,
),
],
),
);
}
}
class _FeatureRow extends StatelessWidget {
final IconData icon;
final String title;
final String subtitle;
final Widget? trailing;
const _FeatureRow({
required this.icon,
required this.title,
required this.subtitle,
this.trailing,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 17),
child: Row(
children: [
Container(
width: 46,
height: 46,
decoration: BoxDecoration(
color: const Color(0xFFE8E7FF),
borderRadius: AppRadius.mdBorder,
),
child: Icon(icon, size: 26, color: const Color(0xFF5B55E7)),
),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700,
color: AppColors.textPrimary,
),
),
const SizedBox(height: 3),
Text(
subtitle,
style: const TextStyle(
fontSize: 15,
color: AppColors.textSecondary,
),
),
],
),
),
if (trailing != null) ...[const SizedBox(width: 8), trailing!],
],
),
);
}
}
class _PanelDivider extends StatelessWidget {
const _PanelDivider();
@override
Widget build(BuildContext context) {
return const Padding(
padding: EdgeInsets.only(left: 76),
child: Divider(height: 1, color: Color(0xFFE9EAF3)),
);
}
}

View File

@@ -44,6 +44,11 @@ class SettingsPage extends ConsumerWidget {
children: [
_SettingsGroup(
children: [
_SettingsTile(
icon: Icons.elderly_rounded,
title: '长辈模式',
onTap: () => pushRoute(ref, 'elderMode'),
),
_SettingsTile(
icon: LucideIcons.bluetooth,
title: '蓝牙设备',
@@ -272,6 +277,7 @@ class _SettingsTile extends StatelessWidget {
),
),
),
const SizedBox(width: 6),
const Icon(
Icons.arrow_forward_ios_rounded,
size: 15,