From f1bb4544291f4b06805011da889c0147404fe89c Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 18 Nov 2024 16:19:01 +0300 Subject: [PATCH] four_scene --- .../bloc/four_scene_bloc/four_scene_bloc.dart | 76 +++--- .../four_scene_bloc/four_scene_event.dart | 19 +- .../four_scene_bloc/four_scene_state.dart | 6 +- .../four_scene_info_page.dart | 68 +++-- .../four_scene_profile_page.dart | 22 +- .../four_scene_settings.dart | 46 ++-- .../location_setting_four_scene.dart | 244 +++++++++--------- .../four_select_scene_page.dart | 2 +- lib/services/api/devices_api.dart | 1 + 9 files changed, 276 insertions(+), 208 deletions(-) diff --git a/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart b/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart index c74b990..97c335c 100644 --- a/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart +++ b/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -12,9 +11,11 @@ import 'package:syncrow_app/features/devices/model/four_scene_question_model.dar import 'package:syncrow_app/features/devices/model/group_devices_model.dart'; import 'package:syncrow_app/features/devices/model/scene_switch_model.dart'; import 'package:syncrow_app/features/devices/model/status_model.dart'; +import 'package:syncrow_app/features/devices/model/subspace_model.dart'; import 'package:syncrow_app/features/scene/model/scenes_model.dart'; import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/services/api/devices_api.dart'; +import 'package:syncrow_app/services/api/home_management_api.dart'; import 'package:syncrow_app/services/api/scene_api.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; @@ -34,19 +35,22 @@ class FourSceneBloc extends Bloc { on(_onLoadScenes); on(_selectScene); on(searchScene); - on(_onSaveSelection); + on(_assignDevice); on(_onOptionSelected); - on(_addDeviceToGroup); // Register handler here + on(_addDeviceToGroup); on(_removeDeviceFromGroup); + on(_onFourSceneInitial); } final TextEditingController nameController = - TextEditingController(text: '${'firstName'}'); + TextEditingController(text: deviceName); bool isSaving = false; bool editName = false; final FocusNode focusNode = FocusNode(); bool closingReminder = false; bool waterAlarm = false; + static String deviceName = ''; + static String selectedRoomId = ''; FourSceneModel deviceStatus = FourSceneModel( scene_1: '', @@ -56,11 +60,11 @@ class FourSceneBloc extends Bloc { scene_id_group_id: '', switch_backlight: false); - SceneSwitch sceneInfo = SceneSwitch( - activeTime: 1728118263, + SceneSwitch deviceInfo = SceneSwitch( + activeTime: 0, category: "", categoryName: "", - createTime: 1728118263, + createTime: 0, gatewayId: "", icon: "", ip: "", @@ -70,10 +74,10 @@ class FourSceneBloc extends Bloc { model: "", name: "", nodeId: "", - online: true, + online: false, ownerId: "", productName: "", - sub: true, + sub: false, timeZone: "", updateTime: 0, uuid: "", @@ -102,7 +106,6 @@ class FourSceneBloc extends Bloc { statusModelList, ); emit(UpdateState(sensor: deviceStatus)); - Future.delayed(const Duration(milliseconds: 500)); // _listenToChanges(); } catch (e) { @@ -115,13 +118,9 @@ class FourSceneBloc extends Bloc { FourSceneInitialInfo event, Emitter emit) async { emit(FourSceneLoadingState()); var response = await DevicesAPI.getDeviceInfo(fourSceneId); - if (response.statusCode == 200) { - Map jsonData = jsonDecode(response.body); - sceneInfo = SceneSwitch.fromJson(jsonData); - emit(LoadingDeviceInfo(sosSensor: sceneInfo)); - } else { - throw Exception('Failed to load device data: ${response.reasonPhrase}'); - } + deviceInfo = SceneSwitch.fromJson(response); + deviceName = deviceInfo.name; + emit(LoadingDeviceInfo(deviceInfo: deviceInfo)); } void _onSearchFaq(SearchFaqEvent event, Emitter emit) { @@ -131,8 +130,6 @@ class FourSceneBloc extends Bloc { .toLowerCase() .contains(event.query.toLowerCase()); }).toList(); - - print(_faqQuestions); emit(FaqSearchState(filteredFaqQuestions: _faqQuestions)); } @@ -155,7 +152,6 @@ class FourSceneBloc extends Bloc { try { closingReminder = event.isClosingEnabled; emit(UpdateState(sensor: deviceStatus)); - // API call to update the state, if necessary // await DevicesAPI.controlDevice( // DeviceControlModel( @@ -235,13 +231,15 @@ class FourSceneBloc extends Bloc { } List allDevices = []; + List roomsList = []; void _fetchRoomsAndDevices( FetchRoomsEvent event, Emitter emit) async { try { emit(FourSceneLoadingState()); - final roomsList = await SpacesAPI.getSubSpaceBySpaceId( + roomsList = await SpacesAPI.getSubSpaceBySpaceId( event.unit.community.uuid, event.unit.id); + print(roomsList); emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList)); } catch (e) { emit(const FourSceneFailedState(errorMessage: 'Something went wrong')); @@ -257,8 +255,6 @@ class FourSceneBloc extends Bloc { emit(ChangeSwitchState(isEnable: switchStatus)); } - // List allScenes = []; - Future _onLoadScenes( LoadScenes event, Emitter emit) async { emit(FourSceneLoadingState()); @@ -314,16 +310,6 @@ class FourSceneBloc extends Bloc { hasSelectionChanged: _hasSelectionChanged)); } - void _onSaveSelection( - SaveSelectionEvent event, Emitter emit) { - if (_hasSelectionChanged) { - print('Save button clicked with selected option: $_selectedOption'); - _hasSelectionChanged = false; - emit(SaveSelectionSuccessState()); - } - } - -//addDevicesIcon List groupDevices = [ GroupDevicesModel( dec: 'Syncroom', icon: Assets.minusIcon, name: '6 Scene Switch') @@ -367,4 +353,28 @@ class FourSceneBloc extends Bloc { } emit(UpdateStateList(groupDevices: groupDevices, devices: devices)); } + + void _assignDevice( + AssignRoomEvent event, Emitter emit) async { + try { + emit(FourSceneLoadingState()); + if (_hasSelectionChanged) { + await HomeManagementAPI.assignDeviceToRoom(event.unit.community.uuid, + event.unit.id, event.roomId, fourSceneId); + final devicesList = await DevicesAPI.getDevicesByRoomId( + communityUuid: event.unit.community.uuid, + spaceUuid: event.unit.id, + roomId: event.roomId); + List allDevicesIds = []; + allDevices.forEach((element) { + allDevicesIds.add(element.uuid!); + }); + emit(SaveSelectionSuccessState()); + } + } catch (e) { + emit(const FourSceneFailedState(errorMessage: 'Something went wrong')); + return; + } + } + } diff --git a/lib/features/devices/bloc/four_scene_bloc/four_scene_event.dart b/lib/features/devices/bloc/four_scene_bloc/four_scene_event.dart index 39a13be..ae89a6a 100644 --- a/lib/features/devices/bloc/four_scene_bloc/four_scene_event.dart +++ b/lib/features/devices/bloc/four_scene_bloc/four_scene_event.dart @@ -151,7 +151,7 @@ class SearchScenesEvent extends FourSceneEvent { }); } -class SaveSelectionEvent extends FourSceneEvent {} +class SaveLocationSelectionEvent extends FourSceneEvent {} class SelectOptionEvent extends FourSceneEvent { dynamic selectedOption; @@ -172,3 +172,20 @@ class RemoveDeviceFromGroup extends FourSceneEvent { RemoveDeviceFromGroup(this.device, this.icon); } + + +class AssignRoomEvent extends FourSceneEvent { + final String roomId; + final SpaceModel unit; + + const AssignRoomEvent({ + required this.roomId, + required this.unit, + }); + + @override + List get props => [ + roomId, + unit, + ]; +} diff --git a/lib/features/devices/bloc/four_scene_bloc/four_scene_state.dart b/lib/features/devices/bloc/four_scene_bloc/four_scene_state.dart index b407837..9645459 100644 --- a/lib/features/devices/bloc/four_scene_bloc/four_scene_state.dart +++ b/lib/features/devices/bloc/four_scene_bloc/four_scene_state.dart @@ -115,9 +115,9 @@ class OptionSelectedState extends FourSceneState { class LoadingDeviceInfo extends FourSceneState { - final SceneSwitch sosSensor; - const LoadingDeviceInfo({required this.sosSensor}); + final SceneSwitch deviceInfo; + const LoadingDeviceInfo({required this.deviceInfo}); @override - List get props => [sosSensor]; + List get props => [deviceInfo]; } \ No newline at end of file diff --git a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_info_page.dart b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_info_page.dart index 0caed76..1798750 100644 --- a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_info_page.dart +++ b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_info_page.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart'; -import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart'; -import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart'; - +import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart'; +import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart'; +import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; -import 'package:syncrow_app/features/devices/model/six_scene_model.dart'; +import 'package:syncrow_app/features/devices/model/four_scene_model.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; @@ -13,29 +13,35 @@ import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dar import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; -class SixSceneInfoPage extends StatelessWidget { +class FourSceneInfoPage extends StatelessWidget { final DeviceModel? device; - const SixSceneInfoPage({super.key, this.device}); + const FourSceneInfoPage({super.key, this.device}); @override Widget build(BuildContext context) { return DefaultScaffold( title: 'Device Information', child: BlocProvider( - create: (context) => SixSceneBloc(sixSceneId: device?.uuid ?? '') - ..add(const SixSceneInitial()), - child: BlocBuilder( + create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '') + ..add(const FourSceneInitial()) + ..add(FourSceneInitialInfo()), + child: BlocBuilder( builder: (context, state) { - final sensor = BlocProvider.of(context); - SixSceneModel model = SixSceneModel( - batteryPercentage: 0, waterContactState: 'normal'); + final _bloc = BlocProvider.of(context); + FourSceneModel model = FourSceneModel( + scene_1: '', + scene_2: '', + scene_3: '', + scene_4: '', + scene_id_group_id: '', + switch_backlight: ''); if (state is LoadingNewSate) { model = state.sosSensor; } else if (state is UpdateState) { model = state.sensor; } - return state is SixSceneLoadingState + return state is FourSceneLoadingState ? const Center( child: DefaultContainer( width: 50, @@ -44,11 +50,11 @@ class SixSceneInfoPage extends StatelessWidget { ) : RefreshIndicator( onRefresh: () async { - sensor.add(const SixSceneInitial()); + _bloc.add(const FourSceneInitial()); }, child: DefaultContainer( child: Padding( - padding: const EdgeInsets.only(left: 10, right: 10), + padding: const EdgeInsets.only(left: 5, right: 5), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, @@ -63,12 +69,24 @@ class SixSceneInfoPage extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - const BodySmall( - text: 'bf3575d0e0c8b6e0a6hybl', + BodySmall( + text: _bloc.deviceInfo.productUuid, fontColor: ColorsManager.primaryTextColor, ), InkWell( - onTap: () {}, + onTap: () { + Clipboard.setData( + ClipboardData( + text: _bloc.deviceInfo.productUuid, + ), + ); + + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar( + content: Text("Copied to Clipboard"), + ), + ); + }, child: const Row( children: [ Icon( @@ -87,18 +105,18 @@ class SixSceneInfoPage extends StatelessWidget { const Divider( color: ColorsManager.dividerColor, ), - const Column( + Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - BodyLarge( + const BodyLarge( text: 'MAC', fontSize: 15, fontWeight: FontWeight.w400, fontColor: ColorsManager.blackColor, ), BodySmall( - text: 'bf3575d0e0c8b6e0a6hybl', + text: _bloc.deviceInfo.macAddress, fontColor: ColorsManager.primaryTextColor, ), ], @@ -106,18 +124,18 @@ class SixSceneInfoPage extends StatelessWidget { const Divider( color: ColorsManager.dividerColor, ), - const Column( + Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - BodyLarge( + const BodyLarge( text: 'Time Zone', fontSize: 15, fontWeight: FontWeight.w400, fontColor: ColorsManager.blackColor, ), BodySmall( - text: 'Asia/Dubai', + text: _bloc.deviceInfo.timeZone, fontColor: ColorsManager.primaryTextColor, ), ], diff --git a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_profile_page.dart b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_profile_page.dart index d363321..aa05cfe 100644 --- a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_profile_page.dart +++ b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_profile_page.dart @@ -27,10 +27,11 @@ class FourSceneProfilePage extends StatelessWidget { title: 'Device Settings', child: BlocProvider( create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '') - ..add(const FourSceneInitial()), + ..add(const FourSceneInitial()) + ..add(FourSceneInitialInfo()), child: BlocBuilder( builder: (context, state) { - final sensor = BlocProvider.of(context); + final _bloc = BlocProvider.of(context); FourSceneModel model = FourSceneModel( scene_1: '', scene_2: '', @@ -52,7 +53,7 @@ class FourSceneProfilePage extends StatelessWidget { ) : RefreshIndicator( onRefresh: () async { - sensor.add(const FourSceneInitial()); + _bloc.add(const FourSceneInitial()); }, child: ListView( children: [ @@ -88,9 +89,9 @@ class FourSceneProfilePage extends StatelessWidget { color: Colors.black, ), textAlign: TextAlign.center, - focusNode: sensor.focusNode, - controller: sensor.nameController, - enabled: sensor.editName, + focusNode: _bloc.focusNode, + controller: _bloc.nameController, + enabled: _bloc.editName, onEditingComplete: () { // sensor.add(SaveNameEvent(context: context)); }, @@ -106,8 +107,7 @@ class FourSceneProfilePage extends StatelessWidget { const SizedBox(width: 5), InkWell( onTap: () { - sensor - .add(const ChangeNameEvent(value: true)); + _bloc.add(const ChangeNameEvent(value: true)); }, child: const Padding( padding: EdgeInsets.symmetric(horizontal: 10), @@ -136,10 +136,11 @@ class FourSceneProfilePage extends StatelessWidget { MaterialPageRoute( builder: (context) => LocationFourScenePage( space: spaces!.first, + deviceId: device?.uuid ?? '', )), ); }, - child: const Row( + child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SizedBox( @@ -149,7 +150,8 @@ class FourSceneProfilePage extends StatelessWidget { children: [ SizedBox( child: BodyMedium( - text: 'Syncroom', + text: _bloc + .deviceInfo.subspace.subspaceName, fontColor: ColorsManager.textGray, ), ), diff --git a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_settings.dart b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_settings.dart index 1b1451f..007a42f 100644 --- a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_settings.dart +++ b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_settings.dart @@ -10,6 +10,7 @@ import 'package:syncrow_app/features/devices/model/four_scene_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/faq_four_scene_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_create_group.dart'; import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_delete_dialog.dart'; +import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_info_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_profile_page.dart'; import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_update_dialog.dart'; import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/four_scene_update_page.dart'; @@ -33,10 +34,11 @@ class FourSceneSettings extends StatelessWidget { title: 'Device Settings', child: BlocProvider( create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '') - ..add(const FourSceneInitial()), + ..add(const FourSceneInitial()) + ..add(FourSceneInitialInfo()), child: BlocBuilder( builder: (context, state) { - final sensor = BlocProvider.of(context); + final _bloc = BlocProvider.of(context); FourSceneModel model = FourSceneModel( scene_1: '', scene_2: '', @@ -58,7 +60,7 @@ class FourSceneSettings extends StatelessWidget { ) : RefreshIndicator( onRefresh: () async { - sensor.add(const FourSceneInitial()); + _bloc.add(const FourSceneInitial()); }, child: ListView( children: [ @@ -70,25 +72,27 @@ class FourSceneSettings extends StatelessWidget { onTap: () { Navigator.of(context).push( MaterialPageRoute( - builder: (context) => - const FourSceneProfilePage(), + builder: (context) => FourSceneProfilePage( + device: device, + ), ), ); }, child: Stack( children: [ - const Column( + Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - SizedBox(height: 20), + const SizedBox(height: 20), DefaultContainer( - borderRadius: - BorderRadius.all(Radius.circular(30)), + borderRadius: const BorderRadius.all( + Radius.circular(30)), child: Padding( - padding: EdgeInsets.all(10.0), + padding: const EdgeInsets.all(10.0), child: Padding( - padding: EdgeInsets.only(left: 90), + padding: + const EdgeInsets.only(left: 90), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -98,17 +102,20 @@ class FourSceneSettings extends StatelessWidget { CrossAxisAlignment.start, children: [ BodyMedium( - text: '4 Scene Switch', + text: _bloc.deviceInfo.name, fontWeight: FontWeight.bold, ), - SizedBox( + const SizedBox( height: 5, ), BodySmall( - text: "Room: Syncrow"), + text: _bloc + .deviceInfo + .subspace + .subspaceName), ], ), - Icon(Icons.edit_sharp) + const Icon(Icons.edit_sharp) ], ), ), @@ -152,11 +159,10 @@ class FourSceneSettings extends StatelessWidget { children: [ SettingWidget( onTap: () { - // Navigator.of(context).push( - // MaterialPageRoute( - // builder: (context) => - // const FourSceneInfoPage()), - // ); + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => FourSceneInfoPage( device: device!,)), + ); }, text: 'Device Information', icon: Assets.infoIcon, diff --git a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/location_setting_four_scene.dart b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/location_setting_four_scene.dart index aa6a80b..71de7e3 100644 --- a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/location_setting_four_scene.dart +++ b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/location_setting_four_scene.dart @@ -3,56 +3,37 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/model/space_model.dart'; import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart'; +import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart'; import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart'; import 'package:syncrow_app/features/devices/model/four_scene_model.dart'; -import 'package:syncrow_app/features/devices/model/subspace_model.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; -import '../../../../bloc/four_scene_bloc/four_scene_event.dart'; - -class LocationFourScenePage extends StatefulWidget { +class LocationFourScenePage extends StatelessWidget { final SpaceModel? space; - LocationFourScenePage({super.key, this.space}); + final String? deviceId; - @override - _LocationFourScenePageState createState() => _LocationFourScenePageState(); -} - -class _LocationFourScenePageState extends State { - String _selectedOption = 'Conference Room'; - bool _hasSelectionChanged = false; + const LocationFourScenePage({ + super.key, + this.space, + this.deviceId, + }); @override Widget build(BuildContext context) { - return DefaultScaffold( - title: 'Device Location', - actions: [ - InkWell( - onTap: _hasSelectionChanged - ? () { - print('Save button clicked'); - } - : null, - child: BodyMedium( - text: 'Save', - fontWeight: FontWeight.w700, - fontSize: 16, - fontColor: _hasSelectionChanged - ? ColorsManager.slidingBlueColor - : ColorsManager.primaryTextColor, - ), - ), - const SizedBox(width: 20), - ], - child: BlocProvider( - create: (context) => FourSceneBloc(fourSceneId: '') - ..add(FetchRoomsEvent(unit: widget.space!)), + String roomIdSelected = ''; + + return Scaffold( + body: BlocProvider( + create: (context) => FourSceneBloc(fourSceneId: deviceId ?? '') + ..add(const FourSceneInitial()) + ..add(FourSceneInitialInfo()) + ..add(FetchRoomsEvent(unit: space!)), child: BlocBuilder( builder: (context, state) { - final sensor = BlocProvider.of(context); + final _bloc = BlocProvider.of(context); FourSceneModel model = FourSceneModel( scene_1: '', scene_2: '', @@ -60,12 +41,6 @@ class _LocationFourScenePageState extends State { scene_4: '', scene_id_group_id: '', switch_backlight: ''); - List? rooms = []; - if (state is LoadingNewSate) { - model = state.sosSensor; - } else if (state is FetchRoomsState) { - rooms = state.roomsList; - } return state is FourSceneLoadingState ? const Center( child: DefaultContainer( @@ -74,52 +49,92 @@ class _LocationFourScenePageState extends State { child: CircularProgressIndicator(), ), ) - : RefreshIndicator( - onRefresh: () async { - sensor.add(const FourSceneInitial()); - }, - child: ListView( - padding: const EdgeInsets.symmetric(vertical: 20), - children: [ - const BodyMedium( - text: 'Smart Device Location', - fontWeight: FontWeight.w700, - fontSize: 12, - fontColor: ColorsManager.grayColor, - ), - const SizedBox(height: 5), - DefaultContainer( - padding: const EdgeInsets.all(20), - child: ListView.builder( - physics: const NeverScrollableScrollPhysics(), - shrinkWrap: true, - itemCount: rooms!.length, - itemBuilder: (context, index) { - final room = rooms![index]; - return Column( - children: [ - _buildCheckboxOption( - label: room.name!, - onTap: (v) { - setState(() { - _selectedOption = v; - _hasSelectionChanged = true; - }); - }, - ), - if (index < rooms.length - 1) ...[ - const SizedBox(height: 10), - const Divider( - color: ColorsManager.dividerColor, - ), - const SizedBox(height: 10), - ], - ], - ); - }, + : DefaultScaffold( + actions: [ + BlocBuilder( + builder: (context, state) { + final bool canSave = state is OptionSelectedState && + state.hasSelectionChanged; + return InkWell( + onTap: canSave + ? () { + context.read().add( + AssignRoomEvent( + roomId: roomIdSelected, + unit: space!)); + } + : null, + child: BodyMedium( + text: 'Save', + fontWeight: FontWeight.w700, + fontSize: 16, + fontColor: canSave + ? ColorsManager.slidingBlueColor + : ColorsManager.primaryTextColor, + ), + ); + }, + ), + const SizedBox(width: 20), + ], + child: RefreshIndicator( + onRefresh: () async { + // sensor.add(const SosInitial()); + }, + child: ListView( + shrinkWrap: true, + padding: const EdgeInsets.symmetric(vertical: 20), + children: [ + const BodyMedium( + text: 'Smart Device Location', + fontWeight: FontWeight.w700, + fontSize: 12, + fontColor: ColorsManager.grayColor, ), - ), - ], + const SizedBox(height: 5), + DefaultContainer( + padding: const EdgeInsets.all(20), + child: ListView.builder( + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + itemCount: _bloc.roomsList.length, + itemBuilder: (context, index) { + final fromRoom = _bloc.roomsList[index]; + final isSelected = (state + is OptionSelectedState && + state.selectedOption == fromRoom.id) || + (state is! OptionSelectedState && + fromRoom.id == + _bloc.deviceInfo.subspace.uuid); + + return Column( + children: [ + _buildCheckboxOption( + label: fromRoom.name!, + isSelected: isSelected, + onTap: (label) { + context.read().add( + SelectOptionEvent( + selectedOption: fromRoom.id!, + ), + ); + roomIdSelected = fromRoom.id!; + }, + ), + if (index < _bloc.roomsList.length - 1) ...[ + const SizedBox(height: 10), + const Divider( + color: ColorsManager.dividerColor, + ), + const SizedBox(height: 10), + ], + ], + ); + }, + ), + ), + ], + ), ), ); }, @@ -127,34 +142,6 @@ class _LocationFourScenePageState extends State { ), ); } - - Widget _buildCheckboxOption( - {required String label, required Function(String) onTap}) { - return Padding( - padding: const EdgeInsets.only(bottom: 10, top: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - BodyMedium( - text: label, - style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w400), - ), - CircularCheckbox( - value: _selectedOption == label, - onChanged: (bool? value) { - if (value == true) { - setState(() { - _selectedOption = label; - _hasSelectionChanged = true; - }); - onTap(label); - } - }, - ), - ], - ), - ); - } } class CircularCheckbox extends StatefulWidget { @@ -200,3 +187,30 @@ class _CircularCheckboxState extends State { ); } } + +Widget _buildCheckboxOption({ + required String label, + required bool isSelected, + required Function(String) onTap, +}) { + return Padding( + padding: const EdgeInsets.only(bottom: 10, top: 10), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + BodyMedium( + text: label, + style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w400), + ), + CircularCheckbox( + value: isSelected, + onChanged: (bool? value) { + if (value == true) { + onTap(label); + } + }, + ), + ], + ), + ); +} diff --git a/lib/features/devices/view/widgets/four_scene_switch/four_select_scene_page.dart b/lib/features/devices/view/widgets/four_scene_switch/four_select_scene_page.dart index 7553b7d..4d463b0 100644 --- a/lib/features/devices/view/widgets/four_scene_switch/four_select_scene_page.dart +++ b/lib/features/devices/view/widgets/four_scene_switch/four_select_scene_page.dart @@ -58,7 +58,7 @@ class FourSelectSceneFourPage extends StatelessWidget { onTap: canSave ? () { print('object'); - context.read().add(SaveSelectionEvent()); + // context.read().add(SaveSelectionEvent()); } : null, child: BodyMedium( diff --git a/lib/services/api/devices_api.dart b/lib/services/api/devices_api.dart index 9b6f93a..3298c96 100644 --- a/lib/services/api/devices_api.dart +++ b/lib/services/api/devices_api.dart @@ -127,6 +127,7 @@ class DevicesAPI { path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId), showServerMessage: false, expectedResponseModel: (json) { + print('object-=-=-$json'); return json; }); return response;