runable
This commit is contained in:
482
lib/features/settings/presentation/pages/settings_page.dart
Normal file
482
lib/features/settings/presentation/pages/settings_page.dart
Normal file
@@ -0,0 +1,482 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../providers/settings_provider.dart';
|
||||
import '../../../../core/constants/app_constants.dart';
|
||||
|
||||
/// Settings page
|
||||
class SettingsPage extends ConsumerWidget {
|
||||
const SettingsPage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final settingsAsync = ref.watch(settingsProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Settings'),
|
||||
),
|
||||
body: settingsAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stack) => Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline,
|
||||
size: 64,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('Error: $error'),
|
||||
const SizedBox(height: 16),
|
||||
ElevatedButton(
|
||||
onPressed: () => ref.invalidate(settingsProvider),
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
data: (settings) {
|
||||
return ListView(
|
||||
children: [
|
||||
// Appearance Section
|
||||
_buildSectionHeader(context, 'Appearance'),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.palette_outlined),
|
||||
title: const Text('Theme'),
|
||||
subtitle: Text(_getThemeModeName(settings.themeMode)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showThemeDialog(context, ref, settings.themeMode);
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
// Localization Section
|
||||
_buildSectionHeader(context, 'Localization'),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.language),
|
||||
title: const Text('Language'),
|
||||
subtitle: Text(_getLanguageName(settings.language)),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showLanguageDialog(context, ref, settings.language);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.attach_money),
|
||||
title: const Text('Currency'),
|
||||
subtitle: Text(settings.currency),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showCurrencyDialog(context, ref, settings.currency);
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
// Business Settings Section
|
||||
_buildSectionHeader(context, 'Business Settings'),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.store),
|
||||
title: const Text('Store Name'),
|
||||
subtitle: Text(settings.storeName),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showStoreNameDialog(context, ref, settings.storeName);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.percent),
|
||||
title: const Text('Tax Rate'),
|
||||
subtitle: Text('${(settings.taxRate * 100).toStringAsFixed(1)}%'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
_showTaxRateDialog(context, ref, settings.taxRate);
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
// Data Management Section
|
||||
_buildSectionHeader(context, 'Data Management'),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.sync),
|
||||
title: const Text('Sync Data'),
|
||||
subtitle: settings.lastSyncAt != null
|
||||
? Text('Last synced: ${_formatDateTime(settings.lastSyncAt!)}')
|
||||
: const Text('Never synced'),
|
||||
trailing: const Icon(Icons.cloud_upload),
|
||||
onTap: () => _performSync(context, ref),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.delete_sweep),
|
||||
title: const Text('Clear Cache'),
|
||||
subtitle: const Text('Remove cached images and data'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showClearCacheDialog(context),
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
// About Section
|
||||
_buildSectionHeader(context, 'About'),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.info_outline),
|
||||
title: const Text('App Version'),
|
||||
subtitle: Text(AppConstants.appVersion),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.business),
|
||||
title: const Text('About ${AppConstants.appName}'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showAboutDialog(context),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(BuildContext context, String title) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _getThemeModeName(ThemeMode mode) {
|
||||
switch (mode) {
|
||||
case ThemeMode.light:
|
||||
return 'Light';
|
||||
case ThemeMode.dark:
|
||||
return 'Dark';
|
||||
case ThemeMode.system:
|
||||
return 'System';
|
||||
}
|
||||
}
|
||||
|
||||
String _getLanguageName(String code) {
|
||||
switch (code) {
|
||||
case 'en':
|
||||
return 'English';
|
||||
case 'es':
|
||||
return 'Spanish';
|
||||
case 'fr':
|
||||
return 'French';
|
||||
default:
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime dateTime) {
|
||||
return '${dateTime.day}/${dateTime.month}/${dateTime.year} ${dateTime.hour}:${dateTime.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
void _showThemeDialog(BuildContext context, WidgetRef ref, ThemeMode currentMode) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Select Theme'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
RadioListTile<ThemeMode>(
|
||||
title: const Text('Light'),
|
||||
value: ThemeMode.light,
|
||||
groupValue: currentMode,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(settingsProvider.notifier).updateTheme(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
RadioListTile<ThemeMode>(
|
||||
title: const Text('Dark'),
|
||||
value: ThemeMode.dark,
|
||||
groupValue: currentMode,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(settingsProvider.notifier).updateTheme(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
RadioListTile<ThemeMode>(
|
||||
title: const Text('System'),
|
||||
value: ThemeMode.system,
|
||||
groupValue: currentMode,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(settingsProvider.notifier).updateTheme(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showLanguageDialog(BuildContext context, WidgetRef ref, String currentLanguage) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Select Language'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
RadioListTile<String>(
|
||||
title: const Text('English'),
|
||||
value: 'en',
|
||||
groupValue: currentLanguage,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(settingsProvider.notifier).updateLanguage(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: const Text('Spanish'),
|
||||
value: 'es',
|
||||
groupValue: currentLanguage,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(settingsProvider.notifier).updateLanguage(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: const Text('French'),
|
||||
value: 'fr',
|
||||
groupValue: currentLanguage,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ref.read(settingsProvider.notifier).updateLanguage(value);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showCurrencyDialog(BuildContext context, WidgetRef ref, String currentCurrency) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Select Currency'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
RadioListTile<String>(
|
||||
title: const Text('USD - US Dollar'),
|
||||
value: 'USD',
|
||||
groupValue: currentCurrency,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
// TODO: Implement currency update
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: const Text('EUR - Euro'),
|
||||
value: 'EUR',
|
||||
groupValue: currentCurrency,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
// TODO: Implement currency update
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
RadioListTile<String>(
|
||||
title: const Text('GBP - British Pound'),
|
||||
value: 'GBP',
|
||||
groupValue: currentCurrency,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
// TODO: Implement currency update
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showStoreNameDialog(BuildContext context, WidgetRef ref, String currentName) {
|
||||
final controller = TextEditingController(text: currentName);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Store Name'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Store Name',
|
||||
hintText: 'Enter store name',
|
||||
),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
// TODO: Implement store name update
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Store name updated')),
|
||||
);
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showTaxRateDialog(BuildContext context, WidgetRef ref, double currentRate) {
|
||||
final controller = TextEditingController(
|
||||
text: (currentRate * 100).toStringAsFixed(1),
|
||||
);
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Tax Rate'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Tax Rate (%)',
|
||||
hintText: 'Enter tax rate',
|
||||
suffixText: '%',
|
||||
),
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
autofocus: true,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
// TODO: Implement tax rate update
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Tax rate updated')),
|
||||
);
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _performSync(BuildContext context, WidgetRef ref) async {
|
||||
// Show loading dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const Center(
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text('Syncing data...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Perform sync
|
||||
await Future.delayed(const Duration(seconds: 2)); // Simulated delay
|
||||
|
||||
// Close loading dialog
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Data synced successfully')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _showClearCacheDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Clear Cache'),
|
||||
content: const Text(
|
||||
'This will remove all cached images and data. The app may need to reload content from the server.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Cache cleared')),
|
||||
);
|
||||
},
|
||||
child: const Text('Clear'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAboutDialog(BuildContext context) {
|
||||
showAboutDialog(
|
||||
context: context,
|
||||
applicationName: AppConstants.appName,
|
||||
applicationVersion: AppConstants.appVersion,
|
||||
applicationIcon: const Icon(Icons.store, size: 48),
|
||||
children: [
|
||||
const Text(
|
||||
'A modern Point of Sale application built with Flutter.',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Features:\n'
|
||||
'• Product management\n'
|
||||
'• Category organization\n'
|
||||
'• Shopping cart\n'
|
||||
'• Transaction processing\n'
|
||||
'• Offline-first architecture',
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'settings_provider.dart';
|
||||
|
||||
part 'language_provider.g.dart';
|
||||
|
||||
/// Language/locale provider
|
||||
/// Extracts language from settings for easy access
|
||||
@riverpod
|
||||
String appLanguage(Ref ref) {
|
||||
final settingsAsync = ref.watch(settingsProvider);
|
||||
return settingsAsync.when(
|
||||
data: (settings) => settings.language,
|
||||
loading: () => 'en',
|
||||
error: (_, __) => 'en',
|
||||
);
|
||||
}
|
||||
|
||||
/// Supported languages provider
|
||||
@riverpod
|
||||
List<LanguageOption> supportedLanguages(Ref ref) {
|
||||
return const [
|
||||
LanguageOption(code: 'en', name: 'English', nativeName: 'English'),
|
||||
LanguageOption(code: 'es', name: 'Spanish', nativeName: 'Español'),
|
||||
LanguageOption(code: 'fr', name: 'French', nativeName: 'Français'),
|
||||
LanguageOption(code: 'de', name: 'German', nativeName: 'Deutsch'),
|
||||
LanguageOption(code: 'it', name: 'Italian', nativeName: 'Italiano'),
|
||||
LanguageOption(code: 'pt', name: 'Portuguese', nativeName: 'Português'),
|
||||
LanguageOption(code: 'zh', name: 'Chinese', nativeName: '中文'),
|
||||
LanguageOption(code: 'ja', name: 'Japanese', nativeName: '日本語'),
|
||||
LanguageOption(code: 'ko', name: 'Korean', nativeName: '한국어'),
|
||||
LanguageOption(code: 'ar', name: 'Arabic', nativeName: 'العربية'),
|
||||
];
|
||||
}
|
||||
|
||||
/// Language option model
|
||||
class LanguageOption {
|
||||
final String code;
|
||||
final String name;
|
||||
final String nativeName;
|
||||
|
||||
const LanguageOption({
|
||||
required this.code,
|
||||
required this.name,
|
||||
required this.nativeName,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'language_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Language/locale provider
|
||||
/// Extracts language from settings for easy access
|
||||
|
||||
@ProviderFor(appLanguage)
|
||||
const appLanguageProvider = AppLanguageProvider._();
|
||||
|
||||
/// Language/locale provider
|
||||
/// Extracts language from settings for easy access
|
||||
|
||||
final class AppLanguageProvider
|
||||
extends $FunctionalProvider<String, String, String>
|
||||
with $Provider<String> {
|
||||
/// Language/locale provider
|
||||
/// Extracts language from settings for easy access
|
||||
const AppLanguageProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'appLanguageProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$appLanguageHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<String> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
String create(Ref ref) {
|
||||
return appLanguage(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(String value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<String>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$appLanguageHash() => r'c5bfde42820d2fa742b4c875b91a0081ae235d41';
|
||||
|
||||
/// Supported languages provider
|
||||
|
||||
@ProviderFor(supportedLanguages)
|
||||
const supportedLanguagesProvider = SupportedLanguagesProvider._();
|
||||
|
||||
/// Supported languages provider
|
||||
|
||||
final class SupportedLanguagesProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
List<LanguageOption>,
|
||||
List<LanguageOption>,
|
||||
List<LanguageOption>
|
||||
>
|
||||
with $Provider<List<LanguageOption>> {
|
||||
/// Supported languages provider
|
||||
const SupportedLanguagesProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'supportedLanguagesProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$supportedLanguagesHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<List<LanguageOption>> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
List<LanguageOption> create(Ref ref) {
|
||||
return supportedLanguages(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(List<LanguageOption> value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<List<LanguageOption>>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$supportedLanguagesHash() =>
|
||||
r'c4b8224c1504112ce36de33ca7d3cf34d785a120';
|
||||
@@ -0,0 +1,5 @@
|
||||
/// Export all settings providers
|
||||
export 'settings_datasource_provider.dart';
|
||||
export 'settings_provider.dart';
|
||||
export 'theme_provider.dart';
|
||||
export 'language_provider.dart';
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import '../../data/datasources/settings_local_datasource.dart';
|
||||
import '../../../../core/database/hive_database.dart';
|
||||
import '../../data/models/app_settings_model.dart';
|
||||
|
||||
part 'settings_datasource_provider.g.dart';
|
||||
|
||||
/// Provider for settings local data source
|
||||
/// This is kept alive as it's a dependency injection provider
|
||||
@Riverpod(keepAlive: true)
|
||||
SettingsLocalDataSource settingsLocalDataSource(Ref ref) {
|
||||
final box = HiveDatabase.instance.getBox<AppSettingsModel>('settings');
|
||||
return SettingsLocalDataSourceImpl(box);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'settings_datasource_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Provider for settings local data source
|
||||
/// This is kept alive as it's a dependency injection provider
|
||||
|
||||
@ProviderFor(settingsLocalDataSource)
|
||||
const settingsLocalDataSourceProvider = SettingsLocalDataSourceProvider._();
|
||||
|
||||
/// Provider for settings local data source
|
||||
/// This is kept alive as it's a dependency injection provider
|
||||
|
||||
final class SettingsLocalDataSourceProvider
|
||||
extends
|
||||
$FunctionalProvider<
|
||||
SettingsLocalDataSource,
|
||||
SettingsLocalDataSource,
|
||||
SettingsLocalDataSource
|
||||
>
|
||||
with $Provider<SettingsLocalDataSource> {
|
||||
/// Provider for settings local data source
|
||||
/// This is kept alive as it's a dependency injection provider
|
||||
const SettingsLocalDataSourceProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'settingsLocalDataSourceProvider',
|
||||
isAutoDispose: false,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$settingsLocalDataSourceHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<SettingsLocalDataSource> $createElement(
|
||||
$ProviderPointer pointer,
|
||||
) => $ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
SettingsLocalDataSource create(Ref ref) {
|
||||
return settingsLocalDataSource(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(SettingsLocalDataSource value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<SettingsLocalDataSource>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$settingsLocalDataSourceHash() =>
|
||||
r'fe7c05c34da176079f5bb95cc3a410d5fb5f3f68';
|
||||
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import '../../domain/entities/app_settings.dart';
|
||||
import '../../../../core/constants/app_constants.dart';
|
||||
|
||||
part 'settings_provider.g.dart';
|
||||
|
||||
/// Provider for app settings
|
||||
@riverpod
|
||||
class Settings extends _$Settings {
|
||||
@override
|
||||
Future<AppSettings> build() async {
|
||||
// TODO: Implement with repository
|
||||
// Return default settings for now
|
||||
return const AppSettings(
|
||||
themeMode: ThemeMode.system,
|
||||
language: AppConstants.defaultLanguage,
|
||||
currency: AppConstants.defaultCurrency,
|
||||
taxRate: AppConstants.defaultTaxRate,
|
||||
storeName: AppConstants.appName,
|
||||
enableSync: true,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> updateTheme(ThemeMode mode) async {
|
||||
final current = state.value;
|
||||
if (current != null) {
|
||||
final updated = current.copyWith(themeMode: mode);
|
||||
state = AsyncValue.data(updated);
|
||||
// TODO: Persist to repository
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateLanguage(String language) async {
|
||||
final current = state.value;
|
||||
if (current != null) {
|
||||
final updated = current.copyWith(language: language);
|
||||
state = AsyncValue.data(updated);
|
||||
// TODO: Persist to repository
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateLastSyncTime() async {
|
||||
final current = state.value;
|
||||
if (current != null) {
|
||||
final updated = current.copyWith(lastSyncAt: DateTime.now());
|
||||
state = AsyncValue.data(updated);
|
||||
// TODO: Persist to repository
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'settings_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Provider for app settings
|
||||
|
||||
@ProviderFor(Settings)
|
||||
const settingsProvider = SettingsProvider._();
|
||||
|
||||
/// Provider for app settings
|
||||
final class SettingsProvider
|
||||
extends $AsyncNotifierProvider<Settings, AppSettings> {
|
||||
/// Provider for app settings
|
||||
const SettingsProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'settingsProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$settingsHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
Settings create() => Settings();
|
||||
}
|
||||
|
||||
String _$settingsHash() => r'17065d5a6818ea746a031f33ff7f4fb9ab111075';
|
||||
|
||||
/// Provider for app settings
|
||||
|
||||
abstract class _$Settings extends $AsyncNotifier<AppSettings> {
|
||||
FutureOr<AppSettings> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref = this.ref as $Ref<AsyncValue<AppSettings>, AppSettings>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<AppSettings>, AppSettings>,
|
||||
AsyncValue<AppSettings>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'settings_provider.dart';
|
||||
|
||||
part 'theme_provider.g.dart';
|
||||
|
||||
/// Theme mode provider from theme_provider
|
||||
/// Extracts theme mode from settings for easy access
|
||||
@riverpod
|
||||
ThemeMode themeModeFromTheme(Ref ref) {
|
||||
final settingsAsync = ref.watch(settingsProvider);
|
||||
return settingsAsync.when(
|
||||
data: (settings) => settings.themeMode,
|
||||
loading: () => ThemeMode.system,
|
||||
error: (_, __) => ThemeMode.system,
|
||||
);
|
||||
}
|
||||
|
||||
/// Provider to check if dark mode is active
|
||||
@riverpod
|
||||
bool isDarkMode(Ref ref) {
|
||||
final mode = ref.watch(themeModeFromThemeProvider);
|
||||
return mode == ThemeMode.dark;
|
||||
}
|
||||
|
||||
/// Provider to check if light mode is active
|
||||
@riverpod
|
||||
bool isLightMode(Ref ref) {
|
||||
final mode = ref.watch(themeModeFromThemeProvider);
|
||||
return mode == ThemeMode.light;
|
||||
}
|
||||
|
||||
/// Provider to check if system theme is active
|
||||
@riverpod
|
||||
bool isSystemTheme(Ref ref) {
|
||||
final mode = ref.watch(themeModeFromThemeProvider);
|
||||
return mode == ThemeMode.system;
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'theme_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Theme mode provider from theme_provider
|
||||
/// Extracts theme mode from settings for easy access
|
||||
|
||||
@ProviderFor(themeModeFromTheme)
|
||||
const themeModeFromThemeProvider = ThemeModeFromThemeProvider._();
|
||||
|
||||
/// Theme mode provider from theme_provider
|
||||
/// Extracts theme mode from settings for easy access
|
||||
|
||||
final class ThemeModeFromThemeProvider
|
||||
extends $FunctionalProvider<ThemeMode, ThemeMode, ThemeMode>
|
||||
with $Provider<ThemeMode> {
|
||||
/// Theme mode provider from theme_provider
|
||||
/// Extracts theme mode from settings for easy access
|
||||
const ThemeModeFromThemeProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'themeModeFromThemeProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$themeModeFromThemeHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<ThemeMode> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
ThemeMode create(Ref ref) {
|
||||
return themeModeFromTheme(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(ThemeMode value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<ThemeMode>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$themeModeFromThemeHash() =>
|
||||
r'a906c8a301f2ac5e4b83009b239eb3a6f049a1b1';
|
||||
|
||||
/// Provider to check if dark mode is active
|
||||
|
||||
@ProviderFor(isDarkMode)
|
||||
const isDarkModeProvider = IsDarkModeProvider._();
|
||||
|
||||
/// Provider to check if dark mode is active
|
||||
|
||||
final class IsDarkModeProvider extends $FunctionalProvider<bool, bool, bool>
|
||||
with $Provider<bool> {
|
||||
/// Provider to check if dark mode is active
|
||||
const IsDarkModeProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'isDarkModeProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$isDarkModeHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<bool> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
bool create(Ref ref) {
|
||||
return isDarkMode(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(bool value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<bool>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$isDarkModeHash() => r'f8c2497b2bae2519f51da2543e4fc7e99a4f5b8c';
|
||||
|
||||
/// Provider to check if light mode is active
|
||||
|
||||
@ProviderFor(isLightMode)
|
||||
const isLightModeProvider = IsLightModeProvider._();
|
||||
|
||||
/// Provider to check if light mode is active
|
||||
|
||||
final class IsLightModeProvider extends $FunctionalProvider<bool, bool, bool>
|
||||
with $Provider<bool> {
|
||||
/// Provider to check if light mode is active
|
||||
const IsLightModeProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'isLightModeProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$isLightModeHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<bool> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
bool create(Ref ref) {
|
||||
return isLightMode(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(bool value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<bool>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$isLightModeHash() => r'0aac9dd8e1cb428913b5d463635dcc7b9315f031';
|
||||
|
||||
/// Provider to check if system theme is active
|
||||
|
||||
@ProviderFor(isSystemTheme)
|
||||
const isSystemThemeProvider = IsSystemThemeProvider._();
|
||||
|
||||
/// Provider to check if system theme is active
|
||||
|
||||
final class IsSystemThemeProvider extends $FunctionalProvider<bool, bool, bool>
|
||||
with $Provider<bool> {
|
||||
/// Provider to check if system theme is active
|
||||
const IsSystemThemeProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'isSystemThemeProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$isSystemThemeHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
$ProviderElement<bool> $createElement($ProviderPointer pointer) =>
|
||||
$ProviderElement(pointer);
|
||||
|
||||
@override
|
||||
bool create(Ref ref) {
|
||||
return isSystemTheme(ref);
|
||||
}
|
||||
|
||||
/// {@macro riverpod.override_with_value}
|
||||
Override overrideWithValue(bool value) {
|
||||
return $ProviderOverride(
|
||||
origin: this,
|
||||
providerOverride: $SyncValueProvider<bool>(value),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _$isSystemThemeHash() => r'80e8bef39cde0b6f1b3e074483ea30d5a64aeade';
|
||||
Reference in New Issue
Block a user