rework-onboarding #7
@@ -1,5 +1,6 @@
|
|||||||
// lib/ui/common/flux_text_field.dart
|
// lib/ui/common/flux_text_field.dart
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flux/core/theme/theme.dart';
|
import 'package:flux/core/theme/theme.dart';
|
||||||
|
|
||||||
class FluxTextField extends StatefulWidget {
|
class FluxTextField extends StatefulWidget {
|
||||||
@@ -16,6 +17,8 @@ class FluxTextField extends StatefulWidget {
|
|||||||
final Function(String)? onChanged;
|
final Function(String)? onChanged;
|
||||||
final int? maxLength;
|
final int? maxLength;
|
||||||
final String? Function(String?)? validator;
|
final String? Function(String?)? validator;
|
||||||
|
final List<TextInputFormatter>? inputFormatters;
|
||||||
|
final TextCapitalization? textCapitalization;
|
||||||
|
|
||||||
const FluxTextField({
|
const FluxTextField({
|
||||||
super.key, // Usiamo super.key per Flutter moderno
|
super.key, // Usiamo super.key per Flutter moderno
|
||||||
@@ -32,6 +35,8 @@ class FluxTextField extends StatefulWidget {
|
|||||||
this.onChanged,
|
this.onChanged,
|
||||||
this.maxLength,
|
this.maxLength,
|
||||||
this.validator,
|
this.validator,
|
||||||
|
this.inputFormatters,
|
||||||
|
this.textCapitalization,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -104,6 +109,8 @@ class _FluxTextFieldState extends State<FluxTextField> {
|
|||||||
onFieldSubmitted: widget.onSubmitted,
|
onFieldSubmitted: widget.onSubmitted,
|
||||||
onChanged: widget.onChanged,
|
onChanged: widget.onChanged,
|
||||||
maxLength: widget.maxLength,
|
maxLength: widget.maxLength,
|
||||||
|
inputFormatters: widget.inputFormatters,
|
||||||
|
textCapitalization: widget.textCapitalization ?? TextCapitalization.none,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart'; // <-- IMPORTANTE per i formatter
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flux/core/widgets/flux_text_field.dart';
|
import 'package:flux/core/widgets/flux_text_field.dart';
|
||||||
import 'package:flux/features/master_data/store/models/store_model.dart';
|
import 'package:flux/features/master_data/store/models/store_model.dart';
|
||||||
@@ -50,111 +51,62 @@ class _StoreOnboardingFormState extends State<StoreOnboardingForm> {
|
|||||||
"Dove si trova il tuo punto vendita principale? (Potrai aggiungerne altri in seguito).",
|
"Dove si trova il tuo punto vendita principale? (Potrai aggiungerne altri in seguito).",
|
||||||
style: TextStyle(fontSize: 16),
|
style: TextStyle(fontSize: 16),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 32),
|
||||||
|
|
||||||
FluxTextField(
|
FluxTextField(
|
||||||
controller: _nameCtrl,
|
controller: _nameCtrl,
|
||||||
label: "Nome del Negozio",
|
label: "Nome del Negozio",
|
||||||
validator: (value) {
|
validator: (value) =>
|
||||||
if (value == null || value.isEmpty) {
|
value == null || value.isEmpty ? "Obbligatorio" : null,
|
||||||
return "Il nome del negozio è obbligatorio";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
FluxTextField(
|
FluxTextField(
|
||||||
controller: _addressCtrl,
|
controller: _addressCtrl,
|
||||||
label: "Indirizzo",
|
label: "Indirizzo",
|
||||||
validator: (value) {
|
validator: (value) =>
|
||||||
if (value == null || value.isEmpty) {
|
value == null || value.isEmpty ? "Obbligatorio" : null,
|
||||||
return "L'indirizzo è obbligatorio";
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
|
|
||||||
|
// IL LAYOUT RESPONSIVO PREMIUM
|
||||||
LayoutBuilder(
|
LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
if (constraints.maxWidth < 600) {
|
final isDesktop = constraints.maxWidth >= 600;
|
||||||
return Column(
|
|
||||||
|
if (isDesktop) {
|
||||||
|
// --- DESKTOP: Tutti su una riga ---
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment
|
||||||
|
.start, // Allinea in alto se ci sono errori
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
Expanded(flex: 2, child: _buildZipField()),
|
||||||
width: constraints.maxWidth,
|
|
||||||
child: FluxTextField(
|
|
||||||
label: 'Comune',
|
|
||||||
controller: _cityCtrl,
|
|
||||||
keyboardType: TextInputType.name,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
||||||
children: [
|
|
||||||
SizedBox(
|
|
||||||
width: constraints.maxWidth * 0.4,
|
|
||||||
child: FluxTextField(
|
|
||||||
label: 'CAP',
|
|
||||||
controller: _zipCodeCtrl,
|
|
||||||
maxLength: 5,
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
SizedBox(
|
Expanded(flex: 5, child: _buildCityField()),
|
||||||
width: constraints.maxWidth * 0.2,
|
const SizedBox(width: 16),
|
||||||
child: FluxTextField(
|
Expanded(flex: 2, child: _buildProvField()),
|
||||||
label: 'Prov.',
|
|
||||||
controller: _provinceCtrl,
|
|
||||||
keyboardType: TextInputType.text,
|
|
||||||
onChanged: (value) =>
|
|
||||||
_provinceCtrl.text = value.toUpperCase(),
|
|
||||||
maxLength: 2,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Row(
|
// --- MOBILE: Comune sopra, CAP e Provincia sotto ---
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
return Column(
|
||||||
|
children: [
|
||||||
|
_buildCityField(),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
Expanded(flex: 3, child: _buildZipField()),
|
||||||
width: 160,
|
const SizedBox(width: 16),
|
||||||
child: FluxTextField(
|
Expanded(flex: 2, child: _buildProvField()),
|
||||||
label: 'CAP',
|
],
|
||||||
controller: _zipCodeCtrl,
|
|
||||||
maxLength: 5,
|
|
||||||
keyboardType: TextInputType.number,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
SizedBox(
|
|
||||||
width: constraints.maxWidth * 0.5,
|
|
||||||
child: FluxTextField(
|
|
||||||
label: 'Comune',
|
|
||||||
controller: _cityCtrl,
|
|
||||||
keyboardType: TextInputType.name,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
SizedBox(
|
|
||||||
width: 120,
|
|
||||||
child: FluxTextField(
|
|
||||||
label: 'Prov.',
|
|
||||||
controller: _provinceCtrl,
|
|
||||||
keyboardType: TextInputType.text,
|
|
||||||
onChanged: (value) =>
|
|
||||||
_provinceCtrl.text = value.toUpperCase(),
|
|
||||||
maxLength: 2,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
@@ -165,12 +117,14 @@ class _StoreOnboardingFormState extends State<StoreOnboardingForm> {
|
|||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_formKey.currentState!.validate()) {
|
if (_formKey.currentState!.validate()) {
|
||||||
|
// MIRACOLO DELLA FACTORY EMPTY!
|
||||||
final newStore = StoreModel.empty().copyWith(
|
final newStore = StoreModel.empty().copyWith(
|
||||||
nome: _nameCtrl.text.trim(),
|
nome: _nameCtrl.text.trim(),
|
||||||
indirizzo: _addressCtrl.text.trim(),
|
indirizzo: _addressCtrl.text.trim(),
|
||||||
comune: _cityCtrl.text.trim(),
|
comune: _cityCtrl.text.trim(),
|
||||||
cap: _zipCodeCtrl.text.trim(),
|
cap: _zipCodeCtrl.text.trim(),
|
||||||
provincia: _provinceCtrl.text.trim(),
|
// Formattiamo in maiuscolo qui, al momento del salvataggio!
|
||||||
|
provincia: _provinceCtrl.text.trim().toUpperCase(),
|
||||||
);
|
);
|
||||||
context.read<OnboardingCubit>().saveStore(newStore);
|
context.read<OnboardingCubit>().saveStore(newStore);
|
||||||
}
|
}
|
||||||
@@ -186,4 +140,35 @@ class _StoreOnboardingFormState extends State<StoreOnboardingForm> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- WIDGET ESTRATTI PER PULIZIA ---
|
||||||
|
|
||||||
|
Widget _buildCityField() {
|
||||||
|
return FluxTextField(
|
||||||
|
label: 'Comune',
|
||||||
|
controller: _cityCtrl,
|
||||||
|
keyboardType: TextInputType.name,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildZipField() {
|
||||||
|
return FluxTextField(
|
||||||
|
label: 'CAP',
|
||||||
|
controller: _zipCodeCtrl,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
// Trucchetto Premium: Limita i caratteri ma NASCONDE il contatore UI
|
||||||
|
inputFormatters: [LengthLimitingTextInputFormatter(5)],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildProvField() {
|
||||||
|
return FluxTextField(
|
||||||
|
label: 'Prov.',
|
||||||
|
controller: _provinceCtrl,
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
// Rende la tastiera del telefono automaticamente maiuscola
|
||||||
|
textCapitalization: TextCapitalization.characters,
|
||||||
|
inputFormatters: [LengthLimitingTextInputFormatter(2)],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user