perf: optimization des rebuilds (ValueNotifier pour calendrier/container_form, Selector pour pages de gestion et mon compte)
This commit is contained in:
@@ -35,7 +35,7 @@ class _ContainerFormPageState extends State<ContainerFormPage> {
|
||||
// Form fields
|
||||
ContainerType _selectedType = ContainerType.flightCase;
|
||||
EquipmentStatus _selectedStatus = EquipmentStatus.available;
|
||||
bool _autoGenerateId = true;
|
||||
final ValueNotifier<bool> _autoGenerateIdNotifier = ValueNotifier<bool>(true);
|
||||
final Set<String> _selectedEquipmentIds = {};
|
||||
|
||||
bool _isEditing = false;
|
||||
@@ -61,11 +61,11 @@ class _ContainerFormPageState extends State<ContainerFormPage> {
|
||||
_heightController.text = container.height?.toString() ?? '';
|
||||
_notesController.text = container.notes ?? '';
|
||||
_selectedEquipmentIds.addAll(container.equipmentIds);
|
||||
_autoGenerateId = false;
|
||||
_autoGenerateIdNotifier.value = false;
|
||||
}
|
||||
|
||||
void _updateIdFromName() {
|
||||
if (_autoGenerateId && !_isEditing) {
|
||||
if (_autoGenerateIdNotifier.value && !_isEditing) {
|
||||
final name = _nameController.text;
|
||||
if (name.isNotEmpty) {
|
||||
final baseId = IdGenerator.generateContainerId(
|
||||
@@ -78,7 +78,7 @@ class _ContainerFormPageState extends State<ContainerFormPage> {
|
||||
}
|
||||
|
||||
void _updateIdFromType() {
|
||||
if (_autoGenerateId && !_isEditing) {
|
||||
if (_autoGenerateIdNotifier.value && !_isEditing) {
|
||||
final name = _nameController.text;
|
||||
if (name.isNotEmpty) {
|
||||
final baseId = IdGenerator.generateContainerId(
|
||||
@@ -123,49 +123,52 @@ class _ContainerFormPageState extends State<ContainerFormPage> {
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// ID
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _idController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Identifiant *',
|
||||
hintText: 'ex: FLIGHTCASE_BEAM',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.qr_code),
|
||||
ValueListenableBuilder<bool>(
|
||||
valueListenable: _autoGenerateIdNotifier,
|
||||
builder: (context, autoGenerateId, child) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: _idController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Identifiant *',
|
||||
hintText: 'ex: FLIGHTCASE_BEAM',
|
||||
border: OutlineInputBorder(),
|
||||
prefixIcon: Icon(Icons.qr_code),
|
||||
),
|
||||
enabled: !autoGenerateId || _isEditing,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Veuillez entrer un identifiant';
|
||||
}
|
||||
final validation = IdGenerator.validateContainerId(value);
|
||||
return validation;
|
||||
},
|
||||
),
|
||||
),
|
||||
enabled: !_autoGenerateId || _isEditing,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Veuillez entrer un identifiant';
|
||||
}
|
||||
final validation = IdGenerator.validateContainerId(value);
|
||||
return validation;
|
||||
},
|
||||
),
|
||||
),
|
||||
if (!_isEditing) ...[
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
_autoGenerateId ? Icons.lock : Icons.lock_open,
|
||||
color: _autoGenerateId ? AppColors.rouge : Colors.grey,
|
||||
),
|
||||
tooltip: _autoGenerateId
|
||||
? 'Génération automatique'
|
||||
: 'Saisie manuelle',
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_autoGenerateId = !_autoGenerateId;
|
||||
if (_autoGenerateId) {
|
||||
_updateIdFromName();
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
if (!_isEditing) ...[
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
icon: Icon(
|
||||
autoGenerateId ? Icons.lock : Icons.lock_open,
|
||||
color: autoGenerateId ? AppColors.rouge : Colors.grey,
|
||||
),
|
||||
tooltip: autoGenerateId
|
||||
? 'Génération automatique'
|
||||
: 'Saisie manuelle',
|
||||
onPressed: () {
|
||||
_autoGenerateIdNotifier.value = !autoGenerateId;
|
||||
if (_autoGenerateIdNotifier.value) {
|
||||
_updateIdFromName();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
@@ -632,6 +635,7 @@ class _ContainerFormPageState extends State<ContainerFormPage> {
|
||||
_widthController.dispose();
|
||||
_heightController.dispose();
|
||||
_notesController.dispose();
|
||||
_autoGenerateIdNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user