Files
eryao/apps/lib/features/settings/presentation/widgets/settings_section_widgets.dart
T

499 lines
15 KiB
Dart
Raw Normal View History

2026-04-03 16:56:47 +08:00
import 'package:flutter/material.dart';
import '../../../../l10n/app_localizations.dart';
import '../../../../shared/theme/app_color_palette.dart';
import '../../../../shared/theme/design_tokens.dart';
import '../../../../shared/widgets/toast/toast.dart';
import '../../../../shared/widgets/toast/toast_type.dart';
class SectionLabel extends StatelessWidget {
const SectionLabel({super.key, required this.text});
final String text;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Padding(
padding: const EdgeInsets.only(
left: AppSpacing.sm,
bottom: AppSpacing.sm,
),
child: Text(
text,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: colors.primary,
fontWeight: FontWeight.w700,
),
),
);
}
}
class SettingsGroupCard extends StatelessWidget {
const SettingsGroupCard({super.key, required this.children});
final List<Widget> children;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Card(
margin: EdgeInsets.zero,
elevation: 0,
color: colors.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.xl),
),
child: Column(children: children),
);
}
}
class SettingsMenuTile extends StatelessWidget {
const SettingsMenuTile({
super.key,
required this.icon,
required this.title,
required this.tint,
required this.background,
required this.onTap,
this.showDivider = true,
this.showChevron = true,
this.trailing,
this.subtitle,
2026-04-03 16:56:47 +08:00
});
final IconData icon;
final String title;
final String? subtitle;
2026-04-03 16:56:47 +08:00
final Color tint;
final Color background;
final VoidCallback onTap;
final bool showDivider;
final bool showChevron;
final Widget? trailing;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Column(
children: [
ListTile(
onTap: onTap,
contentPadding: const EdgeInsets.symmetric(
horizontal: AppSpacing.lg,
vertical: AppSpacing.sm,
),
leading: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: background,
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Icon(icon, color: tint),
),
title: Text(title),
subtitle: subtitle == null
? null
: Padding(
padding: const EdgeInsets.only(top: AppSpacing.xs),
child: Text(subtitle!),
),
2026-04-03 16:56:47 +08:00
trailing:
trailing ??
(showChevron
? Icon(Icons.chevron_right_rounded, color: colors.outline)
: null),
),
if (showDivider)
Divider(
height: 1,
indent: 72,
endIndent: AppSpacing.lg,
color: colors.outline,
),
],
);
}
}
class SettingsSwitchTile extends StatelessWidget {
const SettingsSwitchTile({
super.key,
required this.icon,
required this.title,
required this.value,
required this.onChanged,
required this.tint,
required this.background,
this.showDivider = true,
});
final IconData icon;
final String title;
final bool value;
final ValueChanged<bool> onChanged;
final Color tint;
final Color background;
final bool showDivider;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Column(
children: [
ListTile(
contentPadding: const EdgeInsets.symmetric(
horizontal: AppSpacing.lg,
vertical: AppSpacing.sm,
),
leading: Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: background,
borderRadius: BorderRadius.circular(AppRadius.md),
),
child: Icon(icon, color: tint),
),
title: Text(title),
trailing: Switch(
value: value,
onChanged: onChanged,
activeColor: colors.primary,
),
),
if (showDivider)
Divider(
height: 1,
indent: 72,
endIndent: AppSpacing.lg,
color: colors.outline,
),
],
);
}
}
2026-04-03 16:56:47 +08:00
class ProfileHeaderCard extends StatelessWidget {
const ProfileHeaderCard({
super.key,
required this.account,
required this.displayName,
required this.bio,
required this.avatarUrl,
required this.onEditTap,
});
2026-04-03 16:56:47 +08:00
final String account;
final String displayName;
final String bio;
final String? avatarUrl;
final VoidCallback onEditTap;
2026-04-03 16:56:47 +08:00
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Card(
margin: EdgeInsets.zero,
elevation: 0,
color: colors.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.xl),
),
child: Padding(
padding: const EdgeInsets.all(AppSpacing.lg),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
2026-04-03 16:56:47 +08:00
children: [
Container(
width: 56,
height: 56,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(AppRadius.full),
),
alignment: Alignment.center,
child: _AvatarContent(avatarUrl: avatarUrl),
2026-04-03 16:56:47 +08:00
),
const SizedBox(width: AppSpacing.md),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
displayName,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: AppSpacing.xs),
Text(
account,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: colors.onSurfaceVariant,
),
),
if (bio.isNotEmpty) ...[
const SizedBox(height: AppSpacing.sm),
Text(
bio,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.bodyMedium,
),
],
2026-04-03 16:56:47 +08:00
],
),
),
const SizedBox(width: AppSpacing.sm),
Material(
color: colors.surface,
elevation: 2,
shadowColor: colors.shadow.withValues(alpha: 0.35),
borderRadius: BorderRadius.circular(AppRadius.full),
child: InkWell(
onTap: onEditTap,
borderRadius: BorderRadius.circular(AppRadius.full),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.md,
vertical: AppSpacing.sm,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppRadius.full),
border: Border.all(
color: colors.primary.withValues(alpha: 0.24),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.edit_rounded, color: colors.primary, size: 18),
const SizedBox(width: AppSpacing.xs),
Text(
AppLocalizations.of(context)!.settingsEditProfileAction,
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: colors.primary,
fontWeight: FontWeight.w700,
),
),
],
),
),
),
),
2026-04-03 16:56:47 +08:00
],
),
),
);
}
}
class _AvatarContent extends StatelessWidget {
const _AvatarContent({required this.avatarUrl});
final String? avatarUrl;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final url = avatarUrl?.trim() ?? '';
if (url.isNotEmpty) {
return ClipOval(
child: Image.network(
url,
width: 56,
height: 56,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Icon(Icons.person_rounded, color: colors.primary, size: 30);
},
),
);
}
return Icon(Icons.person_rounded, color: colors.primary, size: 30);
}
}
2026-04-03 16:56:47 +08:00
class WalletHeroCard extends StatelessWidget {
const WalletHeroCard({
super.key,
required this.balance,
required this.subtitle,
required this.onTap,
});
final int balance;
final String subtitle;
final VoidCallback onTap;
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final colors = Theme.of(context).colorScheme;
final palette = Theme.of(context).extension<AppColorPalette>()!;
return Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(AppRadius.xl),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppRadius.xl),
gradient: LinearGradient(
colors: [colors.primary, palette.accentPurple],
),
2026-04-03 16:56:47 +08:00
),
padding: const EdgeInsets.all(AppSpacing.xl),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(AppSpacing.md),
decoration: BoxDecoration(
color: colors.onPrimary.withValues(alpha: 0.14),
borderRadius: BorderRadius.circular(AppRadius.lg),
),
child: Icon(
Icons.monetization_on_rounded,
color: colors.onPrimary,
),
),
const SizedBox(width: AppSpacing.lg),
Text(
l10n.settingsCoinBalanceValue(balance),
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: colors.onPrimary,
),
),
2026-04-03 16:56:47 +08:00
const Spacer(),
Icon(
Icons.chevron_right_rounded,
color: colors.onPrimary.withValues(alpha: 0.9),
),
],
),
const SizedBox(height: AppSpacing.md),
Padding(
padding: const EdgeInsets.only(left: 4),
child: Text(
subtitle,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: colors.onPrimary.withValues(alpha: 0.92),
),
2026-04-03 16:56:47 +08:00
),
),
],
),
),
),
);
}
}
class CoinPackageCard extends StatelessWidget {
const CoinPackageCard({
super.key,
required this.title,
required this.price,
required this.amount,
this.badge,
});
final String title;
final String price;
final int amount;
final String? badge;
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final colors = Theme.of(context).colorScheme;
final palette = Theme.of(context).extension<AppColorPalette>()!;
return Card(
margin: EdgeInsets.zero,
elevation: 0,
color: colors.surface,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.xl),
),
child: Padding(
padding: const EdgeInsets.all(AppSpacing.lg),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: AppSpacing.xs),
Text(
l10n.settingsCoinAmount(amount),
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
if (badge != null)
Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.sm,
vertical: AppSpacing.xs,
),
decoration: BoxDecoration(
color: palette.historyGoldBg,
borderRadius: BorderRadius.circular(AppRadius.full),
),
child: Text(
badge!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: palette.historyGoldText,
fontWeight: FontWeight.w700,
),
),
),
],
),
const SizedBox(height: AppSpacing.lg),
Row(
children: [
Text(
price,
style: Theme.of(
context,
).textTheme.headlineMedium?.copyWith(color: colors.primary),
),
const Spacer(),
FilledButton(
onPressed: () {
Toast.show(
context,
l10n.settingsPurchasePending,
type: ToastType.info,
);
},
style: FilledButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.full),
),
),
child: Text(l10n.settingsPurchaseButton),
),
],
),
],
),
),
);
}
}