creazione nuovo negozio

This commit is contained in:
2026-04-09 16:01:57 +02:00
parent c8c9dbc1f8
commit e6b8c9854e
6 changed files with 78 additions and 51 deletions

View File

@@ -48,7 +48,7 @@ class _CreateCompanyScreenState extends State<CreateCompanyScreen> {
void _onSave() {
if (_formKey.currentState!.validate()) {
// Recuperiamo l'ID utente attuale da Supabase o dal SessionBloc
final userId = GetIt.I.get<AppSettings>().currentUserId!;
final userId = context.read<SessionBloc>().state.userId!;
final company = CompanyModel(
userId: userId,
@@ -91,7 +91,7 @@ class _CreateCompanyScreenState extends State<CreateCompanyScreen> {
listener: (context, state) {
if (state.status == CompanyStatus.success && state.company != null) {
// 1. Aggiorniamo la singleton con i dati reali (ID incluso)
GetIt.I.get<AppSettings>().setCurrentCompany(state.company);
//GetIt.I.get<AppSettings>().setCurrentCompany(state.company);
// 2. Notifichiamo il SessionBloc per cambiare pagina
context.read<SessionBloc>().add(AppStarted());

View File

@@ -1,12 +1,10 @@
import 'package:flux/features/company/models/company_model.dart';
import 'package:flux/core/enums/enums.dart';
import 'package:get_it/get_it.dart';
import 'package:shared_preferences/shared_preferences.dart';
class AppSettings {
late String _themeModeSetting;
late String? _currentUserId;
late SharedPreferences _prefs;
late CompanyModel? _currentCompany;
// Singleton
@@ -25,18 +23,6 @@ class AppSettings {
void setThemeModeSetting(String value) {
_themeModeSetting = value;
_prefs.setString('theme', value);
}
String? get currentUserId => _currentUserId;
void setCurrentUserId(String? value) {
_currentUserId = value;
}
CompanyModel? get currentCompany => _currentCompany;
void setCurrentCompany(CompanyModel? value) {
_currentCompany = value;
_prefs.setString(PrefKeys.theme.value, value);
}
}

View File

@@ -37,7 +37,7 @@ class _CreateStoreScreenState extends State<CreateStoreScreen> {
/// Funzione magica per copiare i dati dall'azienda salvata in GetIt
void _useCompanyAddress() {
final company = _settings.currentCompany;
final company = context.read<SessionBloc>().state.company;
if (company != null) {
setState(() {
_indirizzoController.text = company.indirizzo;
@@ -61,18 +61,18 @@ class _CreateStoreScreenState extends State<CreateStoreScreen> {
void _onSave() {
if (_formKey.currentState!.validate()) {
final settings = GetIt.I<AppSettings>();
final company = context.read<SessionBloc>().state.company;
if (_settings.currentCompany?.id == null) {
if (company == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Errore: ID Azienda non trovato')),
const SnackBar(content: Text('Errore: Azienda non trovata')),
);
return;
}
final store = StoreModel(
nome: _nomeController.text.trim(),
companyId: _settings.currentCompany!.id,
companyId: company.id,
indirizzo: _indirizzoController.text.trim(),
cap: _capController.text.trim(),
comune: _comuneController.text.trim(),