feat: align iOS client safety and consent experience

This commit is contained in:
MingNian
2026-07-29 13:30:34 +08:00
parent 3b5cec10a6
commit 01f4955e0e
11 changed files with 290 additions and 374 deletions

View File

@@ -3,6 +3,7 @@ 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/ai_consent_provider.dart';
import '../providers/auth_provider.dart';
import '../pages/settings/ai_consent_details_page.dart';
@@ -21,7 +22,9 @@ class _AiConsentGateState extends ConsumerState<AiConsentGate> {
@override
Widget build(BuildContext context) {
final user = ref.watch(authProvider).user;
if (user == null || user.id.isEmpty) return widget.child;
if (user == null || user.id.isEmpty || user.role != 'User') {
return widget.child;
}
if (_loadedUserId != user.id) {
_loadedUserId = user.id;
@@ -31,17 +34,31 @@ class _AiConsentGateState extends ConsumerState<AiConsentGate> {
}
final consent = ref.watch(aiConsentProvider);
final currentRoute = ref.watch(currentRouteProvider).name;
final isConsentInformationRoute =
currentRoute == 'aiConsentDetails' || currentRoute == 'staticText';
if (consent.userId != user.id || consent.isLoading) {
return const Scaffold(backgroundColor: Colors.white);
return const Scaffold(
body: Center(
child: CircularProgressIndicator(color: AppColors.primary),
),
);
}
if (consent.granted) return widget.child;
if (consent.granted || isConsentInformationRoute) return widget.child;
return Scaffold(
backgroundColor: AppColors.background,
body: Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: _ConsentCard(userId: user.id),
body: DecoratedBox(
decoration: const BoxDecoration(gradient: AppColors.bgGradient),
child: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 20),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: _ConsentCard(userId: user.id),
),
),
),
),
),
);
@@ -53,7 +70,12 @@ class _ConsentCard extends ConsumerWidget {
const _ConsentCard({required this.userId});
Future<void> _grant(BuildContext context, WidgetRef ref) async {
await ref.read(aiConsentProvider.notifier).grant(userId);
final succeeded = await ref.read(aiConsentProvider.notifier).grant(userId);
if (!succeeded && context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Authorization could not be saved.')),
);
}
}
Future<void> _decline(BuildContext context, WidgetRef ref) async {
@@ -62,64 +84,108 @@ class _ConsentCard extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
return Card(
elevation: 0,
color: Colors.white,
shape: RoundedRectangleBorder(borderRadius: AppRadius.xlBorder),
child: Padding(
padding: const EdgeInsets.fromLTRB(22, 24, 22, 20),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Icon(Icons.auto_awesome, size: 40, color: AppColors.primary),
const SizedBox(height: 14),
const Text(
'AI 健康服务授权',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w700),
final consent = ref.watch(aiConsentProvider);
return Container(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 20),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.96),
borderRadius: AppRadius.cardBorder,
border: Border.all(color: AppColors.primaryLight, width: 1),
boxShadow: AppShadows.panel,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Align(
child: Image.asset(
'assets/branding/health_login_character_transparent.png',
height: 112,
fit: BoxFit.contain,
),
const SizedBox(height: 14),
const Text(
'小脉健康的核心功能使用第三方 AI 服务。经你同意后,你主动输入的健康信息、对话内容、图片和报告可能会发送给相关 AI 服务,用于健康记录、饮食识别、报告整理和 AI 回复。',
style: TextStyle(
fontSize: 15,
height: 1.6,
color: AppColors.textSecondary,
),
const SizedBox(height: 2),
Align(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: AppColors.primarySoft,
borderRadius: AppRadius.pillBorder,
),
child: const Text(
'AI Service',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: AppColors.primaryDark,
),
),
),
const SizedBox(height: 10),
const Text(
'AI 生成内容仅供健康管理参考,不能替代医生诊断或治疗。',
style: TextStyle(
fontSize: 14,
height: 1.5,
color: AppColors.textSecondary,
),
),
const SizedBox(height: 10),
TextButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const AiConsentDetailsPage(),
),
const SizedBox(height: 14),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Icon(
Icons.auto_awesome,
size: 40,
color: AppColors.primary,
),
const SizedBox(height: 14),
const Text(
'AI 健康服务授权',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 21, fontWeight: FontWeight.w700),
),
const SizedBox(height: 14),
const Text(
'小脉健康的核心功能使用第三方 AI 服务。经你同意后,你主动输入的健康信息、对话内容、图片和报告可能会发送给相关 AI 服务,用于健康记录、饮食识别、报告整理和 AI 回复。',
style: TextStyle(
fontSize: 15,
height: 1.6,
color: AppColors.textSecondary,
),
);
},
child: const Text('查看《AI 数据处理说明》'),
),
const SizedBox(height: 10),
const Text(
'AI 生成内容仅供健康管理参考,不能替代医生诊断或治疗。',
style: TextStyle(
fontSize: 14,
height: 1.5,
color: AppColors.textSecondary,
),
),
const SizedBox(height: 10),
TextButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => const AiConsentDetailsPage(),
),
);
},
child: const Text('查看《AI 数据处理说明》'),
),
const SizedBox(height: 8),
FilledButton(
onPressed: consent.isSaving
? null
: () => _grant(context, ref),
child: const Text('同意并继续'),
),
const SizedBox(height: 8),
OutlinedButton(
onPressed: consent.isSaving
? null
: () => _decline(context, ref),
child: const Text('不同意并退出'),
),
],
),
const SizedBox(height: 8),
FilledButton(
onPressed: () => _grant(context, ref),
child: const Text('同意并继续'),
),
const SizedBox(height: 8),
OutlinedButton(
onPressed: () => _decline(context, ref),
child: const Text('不同意并退出'),
),
],
),
),
],
),
);
}