Files
eryao/apps/lib/features/settings/presentation/screens/general_settings_screen.dart
T
ZL-Q 87f92987b2 feat: 实现 iOS Apple Pay 内购支付功能
前端:
- 集成 in_app_purchase 插件,实现 IAP 支付流程
- 添加支付模块 (payments/) 处理产品获取、购买、验证
- 积分中心页面集成 Apple Pay 购买入口
- 设置页面重构: 关于/隐私/协议直接展示,删除 legal_center 子页面
- 修复欢迎引导页滚动检测阈值问题
- 修复解卦结果页 iOS 侧滑返回手势被阻止的问题
- 邀请码绑定按钮临时禁用(待后端实现)

后端:
- 新增 apple_iap_transactions 表记录交易
- 实现 Apple 服务器端验证 (App Store Server API)
- 支付成功后自动发放积分
- 支持 Sandbox/Production 环境切换
- 添加退款处理和交易状态机

协议:
- 更新积分流水协议,支持 purchase/refund 类型
- 新增 PAYMENT_* 错误码
2026-04-28 10:45:29 +08:00

181 lines
6.0 KiB
Dart

import 'package:flutter/material.dart';
import '../../../../l10n/app_localizations.dart';
import '../../../../shared/theme/design_tokens.dart';
import '../../data/models/profile_settings.dart';
import '../widgets/settings_section_widgets.dart';
import 'language_settings_screen.dart';
class GeneralSettingsScreen extends StatefulWidget {
const GeneralSettingsScreen({
super.key,
required this.settings,
required this.onSettingsChanged,
});
final ProfileSettingsV1 settings;
final Future<void> Function(ProfileSettingsV1 settings) onSettingsChanged;
@override
State<GeneralSettingsScreen> createState() => _GeneralSettingsScreenState();
}
class _GeneralSettingsScreenState extends State<GeneralSettingsScreen> {
late ProfileSettingsV1 _settings;
@override
void initState() {
super.initState();
_settings = widget.settings;
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: colors.surfaceContainerLow,
appBar: AppBar(
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.arrow_back_ios_new_rounded),
),
title: Text(l10n.settingsGeneralTitle),
centerTitle: true,
backgroundColor: colors.surfaceContainerLow,
surfaceTintColor: colors.surfaceContainerLow,
),
body: ListView(
padding: const EdgeInsets.all(AppSpacing.lg),
children: [
SectionLabel(text: l10n.settingsSectionGeneral),
SettingsGroupCard(
children: [
SettingsMenuTile(
icon: Icons.language_rounded,
title: l10n.settingsInterfaceLanguage,
subtitle: displayLanguageLabel(
l10n,
_settings.preferences.interfaceLanguage,
),
tint: colors.primary,
background: colors.surfaceContainerHighest,
onTap: () => _selectLanguage(
_settings.preferences.interfaceLanguage,
(lang) => setState(() {
_settings = _settings.copyWith(
preferences: _settings.preferences.copyWith(
interfaceLanguage: lang,
),
);
}),
),
),
SettingsMenuTile(
icon: Icons.smart_toy_rounded,
title: l10n.settingsAiLanguage,
subtitle: displayLanguageLabel(
l10n,
_settings.preferences.aiLanguage,
),
tint: colors.primary,
background: colors.surfaceContainerHighest,
showDivider: false,
onTap: () => _selectLanguage(
_settings.preferences.aiLanguage,
(lang) => setState(() {
_settings = _settings.copyWith(
preferences: _settings.preferences.copyWith(
aiLanguage: lang,
),
);
}),
),
),
],
),
const SizedBox(height: AppSpacing.lg),
SectionLabel(text: l10n.settingsSectionPrivacy),
SettingsGroupCard(
children: [
SettingsSwitchTile(
icon: Icons.security_rounded,
title: l10n.settingsDoNotSellTitle,
value: _settings.privacy.canSell,
tint: colors.primary,
background: colors.surfaceContainerHighest,
showDivider: false,
onChanged: (value) => _updatePrivacy(canSell: value),
),
],
),
const SizedBox(height: AppSpacing.lg),
SectionLabel(text: l10n.settingsSectionNotification),
SettingsGroupCard(
children: [
SettingsSwitchTile(
icon: Icons.notifications_rounded,
title: l10n.settingsNotificationAllow,
value: _settings.notification.allowNotifications,
tint: colors.primary,
background: colors.surfaceContainerHighest,
onChanged: (value) =>
_updateNotification(allowNotifications: value),
),
SettingsSwitchTile(
icon: Icons.vibration_rounded,
title: l10n.settingsNotificationVibration,
value: _settings.notification.allowVibration,
tint: colors.primary,
background: colors.surfaceContainerHighest,
showDivider: false,
onChanged: (value) =>
_updateNotification(allowVibration: value),
),
],
),
],
),
);
}
Future<void> _selectLanguage(
String currentLanguage,
void Function(String) onChanged,
) async {
final result = await Navigator.of(context).push<String>(
MaterialPageRoute<String>(
builder: (_) =>
LanguageSettingsScreen(selectedLanguageTag: currentLanguage),
),
);
if (result == null || result == currentLanguage) {
return;
}
onChanged(result);
await widget.onSettingsChanged(_settings);
}
void _updatePrivacy({bool? canSell}) {
final newPrivacy = _settings.privacy.copyWith(canSell: canSell);
final newSettings = _settings.copyWith(privacy: newPrivacy);
setState(() {
_settings = newSettings;
});
widget.onSettingsChanged(newSettings);
}
void _updateNotification({bool? allowNotifications, bool? allowVibration}) {
final newNotification = _settings.notification.copyWith(
allowNotifications: allowNotifications,
allowVibration: allowVibration,
);
final newSettings = _settings.copyWith(notification: newNotification);
setState(() {
_settings = newSettings;
});
widget.onSettingsChanged(newSettings);
}
}