190 lines
6.9 KiB
Dart
190 lines
6.9 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import 'package:flutter_bloc/flutter_bloc.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/onboarding/blocs/onboarding_cubit.dart';
|
||
|
|
import 'package:flux/features/onboarding/blocs/onboarding_state.dart';
|
||
|
|
|
||
|
|
class StoreOnboardingForm extends StatefulWidget {
|
||
|
|
final OnboardingState state;
|
||
|
|
const StoreOnboardingForm({super.key, required this.state});
|
||
|
|
|
||
|
|
@override
|
||
|
|
State<StoreOnboardingForm> createState() => _StoreOnboardingFormState();
|
||
|
|
}
|
||
|
|
|
||
|
|
class _StoreOnboardingFormState extends State<StoreOnboardingForm> {
|
||
|
|
final _formKey = GlobalKey<FormState>();
|
||
|
|
final _nameCtrl = TextEditingController();
|
||
|
|
final _addressCtrl = TextEditingController();
|
||
|
|
final _cityCtrl = TextEditingController();
|
||
|
|
final _zipCodeCtrl = TextEditingController();
|
||
|
|
final _provinceCtrl = TextEditingController();
|
||
|
|
|
||
|
|
@override
|
||
|
|
void dispose() {
|
||
|
|
_nameCtrl.dispose();
|
||
|
|
_addressCtrl.dispose();
|
||
|
|
_cityCtrl.dispose();
|
||
|
|
_zipCodeCtrl.dispose();
|
||
|
|
_provinceCtrl.dispose();
|
||
|
|
super.dispose();
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
return Padding(
|
||
|
|
padding: const EdgeInsets.all(32.0),
|
||
|
|
child: Form(
|
||
|
|
key: _formKey,
|
||
|
|
child: Column(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
|
|
children: [
|
||
|
|
const Text(
|
||
|
|
"Il tuo Negozio 🏪",
|
||
|
|
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
|
||
|
|
),
|
||
|
|
const SizedBox(height: 8),
|
||
|
|
const Text(
|
||
|
|
"Dove si trova il tuo punto vendita principale? (Potrai aggiungerne altri in seguito).",
|
||
|
|
style: TextStyle(fontSize: 16),
|
||
|
|
),
|
||
|
|
const SizedBox(height: 16),
|
||
|
|
FluxTextField(
|
||
|
|
controller: _nameCtrl,
|
||
|
|
label: "Nome del Negozio",
|
||
|
|
validator: (value) {
|
||
|
|
if (value == null || value.isEmpty) {
|
||
|
|
return "Il nome del negozio è obbligatorio";
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
const SizedBox(height: 16),
|
||
|
|
FluxTextField(
|
||
|
|
controller: _addressCtrl,
|
||
|
|
label: "Indirizzo",
|
||
|
|
validator: (value) {
|
||
|
|
if (value == null || value.isEmpty) {
|
||
|
|
return "L'indirizzo è obbligatorio";
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
},
|
||
|
|
),
|
||
|
|
const SizedBox(height: 16),
|
||
|
|
LayoutBuilder(
|
||
|
|
builder: (context, constraints) {
|
||
|
|
if (constraints.maxWidth < 600) {
|
||
|
|
return Column(
|
||
|
|
children: [
|
||
|
|
SizedBox(
|
||
|
|
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),
|
||
|
|
SizedBox(
|
||
|
|
width: constraints.maxWidth * 0.2,
|
||
|
|
child: FluxTextField(
|
||
|
|
label: 'Prov.',
|
||
|
|
controller: _provinceCtrl,
|
||
|
|
keyboardType: TextInputType.text,
|
||
|
|
onChanged: (value) =>
|
||
|
|
_provinceCtrl.text = value.toUpperCase(),
|
||
|
|
maxLength: 2,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
],
|
||
|
|
);
|
||
|
|
} else {
|
||
|
|
return Row(
|
||
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
|
children: [
|
||
|
|
SizedBox(
|
||
|
|
width: 160,
|
||
|
|
child: FluxTextField(
|
||
|
|
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(),
|
||
|
|
ElevatedButton(
|
||
|
|
style: ElevatedButton.styleFrom(
|
||
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||
|
|
shape: RoundedRectangleBorder(
|
||
|
|
borderRadius: BorderRadius.circular(12),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
onPressed: () {
|
||
|
|
if (_formKey.currentState!.validate()) {
|
||
|
|
final newStore = StoreModel.empty().copyWith(
|
||
|
|
nome: _nameCtrl.text.trim(),
|
||
|
|
indirizzo: _addressCtrl.text.trim(),
|
||
|
|
comune: _cityCtrl.text.trim(),
|
||
|
|
cap: _zipCodeCtrl.text.trim(),
|
||
|
|
provincia: _provinceCtrl.text.trim(),
|
||
|
|
);
|
||
|
|
context.read<OnboardingCubit>().saveStore(newStore);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
child: const Text(
|
||
|
|
"Salva Negozio",
|
||
|
|
style: TextStyle(fontSize: 16),
|
||
|
|
),
|
||
|
|
),
|
||
|
|
const SizedBox(height: 16),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|