mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 14:19:40 +00:00
- Updated the onSave callback in SpaceSubSpacesDialog to accept product allocations, allowing for better management of subspace data.
This commit is contained in:
@ -34,7 +34,7 @@ class SpaceDetailsActionButtons extends StatelessWidget {
|
|||||||
|
|
||||||
Widget _buildCancelButton(BuildContext context) {
|
Widget _buildCancelButton(BuildContext context) {
|
||||||
return ElevatedButton(
|
return ElevatedButton(
|
||||||
onPressed: onSave,
|
onPressed: onCancel,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
backgroundColor: ColorsManager.boxColor,
|
backgroundColor: ColorsManager.boxColor,
|
||||||
|
@ -65,10 +65,16 @@ class SpaceSubSpacesBox extends StatelessWidget {
|
|||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
builder: (_) => SpaceSubSpacesDialog(
|
builder: (_) => SpaceSubSpacesDialog(
|
||||||
subspaces: subspaces,
|
subspaces: subspaces,
|
||||||
onSave: (subspaces) {
|
onSave: (subspaces, productAllocationsToBeAssignedToMainSpace) {
|
||||||
context.read<SpaceDetailsModelBloc>().add(
|
context.read<SpaceDetailsModelBloc>().add(
|
||||||
UpdateSpaceDetailsSubspaces(subspaces),
|
UpdateSpaceDetailsSubspaces(subspaces),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
context.read<SpaceDetailsModelBloc>().add(
|
||||||
|
UpdateSpaceDetailsProductAllocations(
|
||||||
|
productAllocationsToBeAssignedToMainSpace,
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/product_allocation.dart';
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/subspace.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/subspace.dart';
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/widgets/space_details_action_buttons.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/widgets/space_details_action_buttons.dart';
|
||||||
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/widgets/sub_spaces_input.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/presentation/widgets/sub_spaces_input.dart';
|
||||||
@ -14,7 +15,10 @@ class SpaceSubSpacesDialog extends StatefulWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final List<Subspace> subspaces;
|
final List<Subspace> subspaces;
|
||||||
final void Function(List<Subspace> subspaces) onSave;
|
final void Function(
|
||||||
|
List<Subspace> subspaces,
|
||||||
|
List<ProductAllocation> productAllocations,
|
||||||
|
) onSave;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SpaceSubSpacesDialog> createState() => _SpaceSubSpacesDialogState();
|
State<SpaceSubSpacesDialog> createState() => _SpaceSubSpacesDialogState();
|
||||||
@ -23,6 +27,7 @@ class SpaceSubSpacesDialog extends StatefulWidget {
|
|||||||
class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
||||||
late final TextEditingController _subspaceNameController;
|
late final TextEditingController _subspaceNameController;
|
||||||
late List<Subspace> _subspaces;
|
late List<Subspace> _subspaces;
|
||||||
|
final _productAllocationsToBeAssignedToMainSpace = <ProductAllocation>[];
|
||||||
|
|
||||||
bool get _hasDuplicateNames =>
|
bool get _hasDuplicateNames =>
|
||||||
_subspaces.map((subspace) => subspace.name.toLowerCase()).toSet().length !=
|
_subspaces.map((subspace) => subspace.name.toLowerCase()).toSet().length !=
|
||||||
@ -54,16 +59,22 @@ class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleSubspaceDeleted(String uuid) => setState(
|
void _handleSubspaceDeleted(String uuid) {
|
||||||
() => _subspaces = _subspaces.where((s) => s.uuid != uuid).toList(),
|
setState(() {
|
||||||
|
final subspaceToDelete = _subspaces.firstWhere((s) => s.uuid == uuid);
|
||||||
|
_productAllocationsToBeAssignedToMainSpace.addAll(
|
||||||
|
subspaceToDelete.productAllocations,
|
||||||
);
|
);
|
||||||
|
_subspaces = _subspaces.where((s) => s.uuid != uuid).toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void _handleSave() {
|
void _handleSave() {
|
||||||
final name = _subspaceNameController.text.trim();
|
final name = _subspaceNameController.text.trim();
|
||||||
if (name.isNotEmpty) {
|
if (name.isNotEmpty) {
|
||||||
_handleSubspaceAdded(name);
|
_handleSubspaceAdded(name);
|
||||||
}
|
}
|
||||||
widget.onSave(_subspaces);
|
widget.onSave(_subspaces, _productAllocationsToBeAssignedToMainSpace);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user