cb_prestige_qr/lib/features/settings/presentation/pages/settings_page.dart
2026-04-09 13:17:03 +06:30

133 lines
3.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../manager/settings_ui_state.dart';
import '../manager/settings_view_model.dart';
class SettingsPage extends ConsumerWidget {
const SettingsPage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
final viewModel = ref.read(settingsViewModelProvider.notifier);
final stateAsync = ref.watch(settingsViewModelProvider);
return Scaffold(
backgroundColor: theme.scaffoldBackgroundColor,
appBar: AppBar(
title: const Text('Settings'),
backgroundColor: theme.scaffoldBackgroundColor,
surfaceTintColor: theme.scaffoldBackgroundColor,
elevation: 0,
scrolledUnderElevation: 0,
),
body: stateAsync.when(
data: (state) => _SettingsBody(
state: state,
onNotificationsChanged: viewModel.toggleNotifications,
onHapticsChanged: viewModel.toggleHaptics,
),
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stackTrace) => Center(
child: TextButton(
onPressed: () => ref.invalidate(settingsViewModelProvider),
child: const Text('Retry'),
),
),
),
);
}
}
class _SettingsBody extends StatelessWidget {
const _SettingsBody({
required this.state,
required this.onNotificationsChanged,
required this.onHapticsChanged,
});
final SettingsUiState state;
final ValueChanged<bool> onNotificationsChanged;
final ValueChanged<bool> onHapticsChanged;
@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 24),
children: [
_SectionCard(
title: 'Preferences',
children: [
SwitchListTile.adaptive(
value: state.notificationsEnabled,
onChanged: onNotificationsChanged,
title: const Text('Notifications'),
subtitle: const Text('Get updates about scans'),
),
const Divider(height: 1),
SwitchListTile.adaptive(
value: state.hapticsEnabled,
onChanged: onHapticsChanged,
title: const Text('Haptics'),
subtitle: const Text('Vibration feedback'),
),
],
),
const SizedBox(height: 12),
_SectionCard(
title: 'About',
children: [
ListTile(
title: const Text('Version'),
subtitle: Text(state.appVersionLabel),
),
],
),
],
);
}
}
class _SectionCard extends StatelessWidget {
const _SectionCard({required this.title, required this.children});
final String title;
final List<Widget> children;
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
return Container(
decoration: BoxDecoration(
color: colorScheme.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: colorScheme.outlineVariant.withOpacity(0.5)),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.06),
blurRadius: 14,
offset: const Offset(0, 6),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 8),
child: Text(
title,
style: Theme.of(
context,
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w700),
),
),
...children,
],
),
);
}
}