mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-24 20:32:28 +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) {
|
||||
return ElevatedButton(
|
||||
onPressed: onSave,
|
||||
onPressed: onCancel,
|
||||
style: ElevatedButton.styleFrom(
|
||||
elevation: 4,
|
||||
backgroundColor: ColorsManager.boxColor,
|
||||
|
@ -65,10 +65,16 @@ class SpaceSubSpacesBox extends StatelessWidget {
|
||||
barrierDismissible: false,
|
||||
builder: (_) => SpaceSubSpacesDialog(
|
||||
subspaces: subspaces,
|
||||
onSave: (subspaces) {
|
||||
onSave: (subspaces, productAllocationsToBeAssignedToMainSpace) {
|
||||
context.read<SpaceDetailsModelBloc>().add(
|
||||
UpdateSpaceDetailsSubspaces(subspaces),
|
||||
);
|
||||
|
||||
context.read<SpaceDetailsModelBloc>().add(
|
||||
UpdateSpaceDetailsProductAllocations(
|
||||
productAllocationsToBeAssignedToMainSpace,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -1,4 +1,5 @@
|
||||
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/presentation/widgets/space_details_action_buttons.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 void Function(List<Subspace> subspaces) onSave;
|
||||
final void Function(
|
||||
List<Subspace> subspaces,
|
||||
List<ProductAllocation> productAllocations,
|
||||
) onSave;
|
||||
|
||||
@override
|
||||
State<SpaceSubSpacesDialog> createState() => _SpaceSubSpacesDialogState();
|
||||
@ -23,6 +27,7 @@ class SpaceSubSpacesDialog extends StatefulWidget {
|
||||
class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
||||
late final TextEditingController _subspaceNameController;
|
||||
late List<Subspace> _subspaces;
|
||||
final _productAllocationsToBeAssignedToMainSpace = <ProductAllocation>[];
|
||||
|
||||
bool get _hasDuplicateNames =>
|
||||
_subspaces.map((subspace) => subspace.name.toLowerCase()).toSet().length !=
|
||||
@ -54,16 +59,22 @@ class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
||||
});
|
||||
}
|
||||
|
||||
void _handleSubspaceDeleted(String uuid) => setState(
|
||||
() => _subspaces = _subspaces.where((s) => s.uuid != uuid).toList(),
|
||||
void _handleSubspaceDeleted(String uuid) {
|
||||
setState(() {
|
||||
final subspaceToDelete = _subspaces.firstWhere((s) => s.uuid == uuid);
|
||||
_productAllocationsToBeAssignedToMainSpace.addAll(
|
||||
subspaceToDelete.productAllocations,
|
||||
);
|
||||
_subspaces = _subspaces.where((s) => s.uuid != uuid).toList();
|
||||
});
|
||||
}
|
||||
|
||||
void _handleSave() {
|
||||
final name = _subspaceNameController.text.trim();
|
||||
if (name.isNotEmpty) {
|
||||
_handleSubspaceAdded(name);
|
||||
}
|
||||
widget.onSave(_subspaces);
|
||||
widget.onSave(_subspaces, _productAllocationsToBeAssignedToMainSpace);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user