mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-16 01:56:24 +00:00
Refactor sub-space dialog to use Bloc for state management and simplify confirmation handling
This commit is contained in:
@ -9,13 +9,11 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||
class SubSpaceDialog extends StatefulWidget {
|
||||
final List<SubSpaceModel> subSpaces;
|
||||
final String? selected;
|
||||
final void Function(SubSpaceModel?) onConfirmed;
|
||||
|
||||
const SubSpaceDialog({
|
||||
Key? key,
|
||||
required this.subSpaces,
|
||||
this.selected,
|
||||
required this.onConfirmed,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -25,6 +23,17 @@ class SubSpaceDialog extends StatefulWidget {
|
||||
class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
||||
String? _selectedId;
|
||||
|
||||
// @override
|
||||
// void didUpdateWidget(SubSpaceDialog oldWidget) {
|
||||
// super.didUpdateWidget(oldWidget);
|
||||
// // Update internal state when external value changes
|
||||
// if (widget.selected != _selectedId) {
|
||||
// setState(() {
|
||||
// _selectedId = widget.selected;
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@ -86,30 +95,21 @@ class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
||||
}
|
||||
}
|
||||
|
||||
void showSubSpaceDialog(
|
||||
Future<SubSpaceModel?> showSubSpaceDialog(
|
||||
BuildContext context, {
|
||||
required List<SubSpaceModel> subSpaces,
|
||||
String? selected,
|
||||
required String communityUuid,
|
||||
required String spaceUuid,
|
||||
}) {
|
||||
showDialog(
|
||||
return showDialog<SubSpaceModel>(
|
||||
context: context,
|
||||
barrierDismissible: true,
|
||||
builder: (ctx) => SubSpaceDialog(
|
||||
subSpaces: subSpaces,
|
||||
selected: selected,
|
||||
onConfirmed: (selectedModel) {
|
||||
if (selectedModel != null) {
|
||||
context.read<SettingDeviceBloc>().add(
|
||||
SettingBlocAssignRoom(
|
||||
communityUuid: communityUuid,
|
||||
spaceUuid: spaceUuid,
|
||||
subSpaceUuid: selectedModel.id ?? '',
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (ctx) => BlocProvider.value(
|
||||
value: BlocProvider.of<SettingDeviceBloc>(context),
|
||||
child: SubSpaceDialog(
|
||||
subSpaces: subSpaces,
|
||||
selected: selected,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user