b
This commit is contained in:
269
lib/features/settings/ui/reminder_settings_screen.dart
Normal file
269
lib/features/settings/ui/reminder_settings_screen.dart
Normal file
@@ -0,0 +1,269 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/features/settings/blocs/reminder_defaults_cubit.dart';
|
||||
|
||||
class ReminderSettingsScreen extends StatefulWidget {
|
||||
const ReminderSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ReminderSettingsScreen> createState() => _ReminderSettingsScreenState();
|
||||
}
|
||||
|
||||
class _ReminderSettingsScreenState extends State<ReminderSettingsScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Carichiamo i dati all'avvio
|
||||
context.read<ReminderDefaultsCubit>().loadReminders();
|
||||
}
|
||||
|
||||
void _showAddReminderBottomSheet(BuildContext context) {
|
||||
// Valori preselezionati
|
||||
int selectedMinutes = 15;
|
||||
String selectedChannel = 'push';
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
builder: (bottomSheetContext) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setModalState) {
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text(
|
||||
'Nuova Regola di Avviso',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// --- SELEZIONE TEMPO ---
|
||||
DropdownButtonFormField<int>(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Quando vuoi essere avvisato?',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
initialValue: selectedMinutes,
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: 5,
|
||||
child: Text('5 minuti prima'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 15,
|
||||
child: Text('15 minuti prima'),
|
||||
),
|
||||
DropdownMenuItem(value: 60, child: Text('1 ora prima')),
|
||||
DropdownMenuItem(
|
||||
value: 120,
|
||||
child: Text('2 ore prima'),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 1440,
|
||||
child: Text('1 giorno prima'),
|
||||
),
|
||||
],
|
||||
onChanged: (val) {
|
||||
if (val != null)
|
||||
setModalState(() => selectedMinutes = val);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// --- SELEZIONE CANALE ---
|
||||
DropdownButtonFormField<String>(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Come vuoi essere avvisato?',
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
initialValue: selectedChannel,
|
||||
items: const [
|
||||
DropdownMenuItem(
|
||||
value: 'push',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.notifications_active,
|
||||
size: 20,
|
||||
color: Colors.orange,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Text('Notifica App (Push)'),
|
||||
],
|
||||
),
|
||||
),
|
||||
DropdownMenuItem(
|
||||
value: 'email',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.email, size: 20, color: Colors.blue),
|
||||
SizedBox(width: 8),
|
||||
Text('Email'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (val) {
|
||||
if (val != null)
|
||||
setModalState(() => selectedChannel = val);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// --- SALVATAGGIO ---
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
onPressed: () {
|
||||
context.read<ReminderDefaultsCubit>().addReminder(
|
||||
minutesBefore: selectedMinutes,
|
||||
channel: selectedChannel,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Aggiungi Regola'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Preferenze Promemoria')),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => _showAddReminderBottomSheet(context),
|
||||
icon: const Icon(Icons.add_alert),
|
||||
label: const Text('Aggiungi'),
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
body: BlocConsumer<ReminderDefaultsCubit, ReminderDefaultsState>(
|
||||
listener: (context, state) {
|
||||
if (state.status == ReminderDefaultsStatus.failure &&
|
||||
state.errorMessage != null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.errorMessage!),
|
||||
backgroundColor: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state.status == ReminderDefaultsStatus.loading &&
|
||||
state.reminders.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
if (state.reminders.isEmpty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.notifications_off_outlined,
|
||||
size: 64,
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Nessun promemoria predefinito.',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Aggiungi una regola per ricevere in automatico le notifiche quando ti viene assegnato un task.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 16,
|
||||
bottom: 80,
|
||||
left: 16,
|
||||
right: 16,
|
||||
),
|
||||
itemCount: state.reminders.length,
|
||||
itemBuilder: (context, index) {
|
||||
final reminder = state.reminders[index];
|
||||
final isPush = reminder.channel == 'push';
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: BorderSide(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).dividerColor.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
child: ListTile(
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 8,
|
||||
),
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: isPush
|
||||
? Colors.orange.withValues(alpha: 0.1)
|
||||
: Colors.blue.withValues(alpha: 0.1),
|
||||
child: Icon(
|
||||
isPush ? Icons.notifications_active : Icons.email,
|
||||
color: isPush ? Colors.orange : Colors.blue,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
reminder.friendlyTime, // Usiamo l'helper del Model!
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
subtitle: Text(
|
||||
isPush ? 'Tramite Notifica App' : 'Tramite Email',
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.delete_outline,
|
||||
color: Colors.redAccent,
|
||||
),
|
||||
onPressed: () {
|
||||
context.read<ReminderDefaultsCubit>().deleteReminder(
|
||||
reminder.id!,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
28
lib/features/settings/ui/settings.dart
Normal file
28
lib/features/settings/ui/settings.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flux/core/enums_and_consts/enums.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class AppSettings {
|
||||
late String _themeModeSetting;
|
||||
late SharedPreferences _prefs;
|
||||
|
||||
// Singleton
|
||||
|
||||
static final AppSettings _instance = AppSettings._internal();
|
||||
|
||||
factory AppSettings() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
AppSettings._internal() {
|
||||
_prefs = GetIt.I.get<SharedPreferences>();
|
||||
_themeModeSetting = _prefs.getString('theme') ?? 'light';
|
||||
}
|
||||
|
||||
String get themeModeSetting => _themeModeSetting;
|
||||
|
||||
void setThemeModeSetting(String value) {
|
||||
_themeModeSetting = value;
|
||||
_prefs.setString(PrefKeys.theme.value, value);
|
||||
}
|
||||
}
|
||||
143
lib/features/settings/ui/settings_screen.dart
Normal file
143
lib/features/settings/ui/settings_screen.dart
Normal file
@@ -0,0 +1,143 @@
|
||||
// lib/ui/impostazioni/impostazioni_view.dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/features/settings/blocs/settings_cubit.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Impostazioni')),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_settingsSection('Utente', [
|
||||
_settingsTile(
|
||||
title: 'Impostazioni Promemoria',
|
||||
icon: Icons.notifications,
|
||||
subtitle: 'Notifiche predefinite',
|
||||
context: context,
|
||||
onTap: () => context.pushNamed(Routes.reminderSettings),
|
||||
),
|
||||
]),
|
||||
_settingsSection('Azienda', [
|
||||
_settingsTile(
|
||||
title: 'Impostazioni Azienda',
|
||||
icon: Icons.business,
|
||||
subtitle: 'Configura i dati aziendali',
|
||||
context: context,
|
||||
onTap: () => context.pushNamed(Routes.companySettings),
|
||||
),
|
||||
const Divider(height: 30),
|
||||
_settingsTile(
|
||||
title: 'Impostazione Negozi',
|
||||
icon: Icons.store,
|
||||
subtitle: 'Crea o configura i negozi',
|
||||
context: context,
|
||||
onTap: () => context.pushNamed(Routes.stores),
|
||||
),
|
||||
const Divider(height: 30),
|
||||
_settingsTile(
|
||||
title: 'Impostazione Staff / Utenti',
|
||||
icon: Icons.group,
|
||||
subtitle:
|
||||
'Configura i membri dei negozi o invita nuovi utenti in azienda',
|
||||
context: context,
|
||||
onTap: () => context.pushNamed(Routes.staff),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 20),
|
||||
_settingsSection('Applicazione', [
|
||||
BlocBuilder<SettingsCubit, SettingsState>(
|
||||
builder: (context, state) => CheckboxListTile(
|
||||
value: state.isSingleUserMode,
|
||||
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.person, color: FluxColors.primaryBlue),
|
||||
const SizedBox(width: 12),
|
||||
Flexible(
|
||||
child: Text(
|
||||
'Modalità utente singolo (dispositivo personale)',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
subtitle: Padding(
|
||||
padding: const EdgeInsets.only(left: 36),
|
||||
child: Text(
|
||||
'Utente ${GetIt.I.get<SessionCubit>().state.currentStaffMember?.name ?? 'Nessuno'} selezionato automaticamente',
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
context.read<SessionCubit>().setIsSingleUserMode(value!);
|
||||
context.read<SettingsCubit>().toggleSingleUserMode();
|
||||
},
|
||||
),
|
||||
),
|
||||
const Divider(height: 30),
|
||||
_settingsTile(
|
||||
icon: Icons.dark_mode,
|
||||
title: 'Tema (FLUX Dark)',
|
||||
subtitle: 'Configurazione visiva',
|
||||
context: context,
|
||||
onTap: () => context.pushNamed(Routes.themeSettings),
|
||||
),
|
||||
]),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
TextButton.icon(
|
||||
onPressed: () => context.read<SessionCubit>().signOut(),
|
||||
icon: const Icon(Icons.exit_to_app, color: Colors.red),
|
||||
label: const Text('Logout', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _settingsSection(String title, List<Widget> tiles) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title.toUpperCase(),
|
||||
style: const TextStyle(
|
||||
color: FluxColors.accentTurquoise,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 1,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Card(child: Column(children: tiles)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _settingsTile({
|
||||
required BuildContext context,
|
||||
required IconData icon,
|
||||
required String title,
|
||||
String? subtitle,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return ListTile(
|
||||
leading: Icon(icon, color: FluxColors.primaryBlue),
|
||||
title: Text(title, style: Theme.of(context).textTheme.titleLarge),
|
||||
subtitle: Text(subtitle ?? ''),
|
||||
trailing: Icon(
|
||||
Icons.chevron_right,
|
||||
color: Theme.of(context).textTheme.bodyMedium?.color,
|
||||
),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
}
|
||||
35
lib/features/settings/ui/theme_settings_view.dart
Normal file
35
lib/features/settings/ui/theme_settings_view.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/enums_and_consts/enums.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/theme/bloc/theme_bloc.dart';
|
||||
|
||||
class ThemeSettingsView extends StatelessWidget {
|
||||
const ThemeSettingsView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Impostazioni Tema')),
|
||||
body: BlocBuilder<ThemeBloc, ThemeState>(
|
||||
builder: (context, state) => RadioGroup<AppThemeMode>(
|
||||
groupValue: state.currentTheme,
|
||||
onChanged: (newTheme) {
|
||||
if (newTheme != null) {
|
||||
context.read<ThemeBloc>().add(ChangeThemeEvent(newTheme));
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
children: AppThemeMode.values.map((theme) {
|
||||
return RadioListTile<AppThemeMode>(
|
||||
title: Text(theme.label),
|
||||
secondary: Icon(theme.icon, color: context.accent),
|
||||
value: theme,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user