mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
four_scene
This commit is contained in:
@ -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<FourSceneEvent, FourSceneState> {
|
||||
on<LoadScenes>(_onLoadScenes);
|
||||
on<SelectSceneEvent>(_selectScene);
|
||||
on<SearchScenesEvent>(searchScene);
|
||||
on<SaveSelectionEvent>(_onSaveSelection);
|
||||
on<AssignRoomEvent>(_assignDevice);
|
||||
on<SelectOptionEvent>(_onOptionSelected);
|
||||
on<AddDeviceToGroup>(_addDeviceToGroup); // Register handler here
|
||||
on<AddDeviceToGroup>(_addDeviceToGroup);
|
||||
on<RemoveDeviceFromGroup>(_removeDeviceFromGroup);
|
||||
on<FourSceneInitialQuestion>(_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<FourSceneEvent, FourSceneState> {
|
||||
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<FourSceneEvent, FourSceneState> {
|
||||
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<FourSceneEvent, FourSceneState> {
|
||||
statusModelList,
|
||||
);
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 500));
|
||||
// _listenToChanges();
|
||||
} catch (e) {
|
||||
@ -115,13 +118,9 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
FourSceneInitialInfo event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
var response = await DevicesAPI.getDeviceInfo(fourSceneId);
|
||||
if (response.statusCode == 200) {
|
||||
Map<String, dynamic> 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<FourSceneState> emit) {
|
||||
@ -131,8 +130,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
.toLowerCase()
|
||||
.contains(event.query.toLowerCase());
|
||||
}).toList();
|
||||
|
||||
print(_faqQuestions);
|
||||
emit(FaqSearchState(filteredFaqQuestions: _faqQuestions));
|
||||
}
|
||||
|
||||
@ -155,7 +152,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
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<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
|
||||
List<DeviceModel> allDevices = [];
|
||||
List<SubSpaceModel> roomsList = [];
|
||||
|
||||
void _fetchRoomsAndDevices(
|
||||
FetchRoomsEvent event, Emitter<FourSceneState> 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<FourSceneEvent, FourSceneState> {
|
||||
emit(ChangeSwitchState(isEnable: switchStatus));
|
||||
}
|
||||
|
||||
// List<ScenesModel> allScenes = [];
|
||||
|
||||
Future<void> _onLoadScenes(
|
||||
LoadScenes event, Emitter<FourSceneState> emit) async {
|
||||
emit(FourSceneLoadingState());
|
||||
@ -314,16 +310,6 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
hasSelectionChanged: _hasSelectionChanged));
|
||||
}
|
||||
|
||||
void _onSaveSelection(
|
||||
SaveSelectionEvent event, Emitter<FourSceneState> emit) {
|
||||
if (_hasSelectionChanged) {
|
||||
print('Save button clicked with selected option: $_selectedOption');
|
||||
_hasSelectionChanged = false;
|
||||
emit(SaveSelectionSuccessState());
|
||||
}
|
||||
}
|
||||
|
||||
//addDevicesIcon
|
||||
List<GroupDevicesModel> groupDevices = [
|
||||
GroupDevicesModel(
|
||||
dec: 'Syncroom', icon: Assets.minusIcon, name: '6 Scene Switch')
|
||||
@ -367,4 +353,28 @@ class FourSceneBloc extends Bloc<FourSceneEvent, FourSceneState> {
|
||||
}
|
||||
emit(UpdateStateList(groupDevices: groupDevices, devices: devices));
|
||||
}
|
||||
|
||||
void _assignDevice(
|
||||
AssignRoomEvent event, Emitter<FourSceneState> 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<String> allDevicesIds = [];
|
||||
allDevices.forEach((element) {
|
||||
allDevicesIds.add(element.uuid!);
|
||||
});
|
||||
emit(SaveSelectionSuccessState());
|
||||
}
|
||||
} catch (e) {
|
||||
emit(const FourSceneFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<Object> get props => [
|
||||
roomId,
|
||||
unit,
|
||||
];
|
||||
}
|
||||
|
@ -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<Object> get props => [sosSensor];
|
||||
List<Object> get props => [deviceInfo];
|
||||
}
|
@ -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<SixSceneBloc, SixSceneState>(
|
||||
create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
|
||||
..add(const FourSceneInitial())
|
||||
..add(FourSceneInitialInfo()),
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SixSceneBloc>(context);
|
||||
SixSceneModel model = SixSceneModel(
|
||||
batteryPercentage: 0, waterContactState: 'normal');
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(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,
|
||||
),
|
||||
],
|
||||
|
@ -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<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<FourSceneBloc>(context);
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(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,
|
||||
),
|
||||
),
|
||||
|
@ -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<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<FourSceneBloc>(context);
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(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,
|
||||
|
@ -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<LocationFourScenePage> {
|
||||
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<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<FourSceneBloc>(context);
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
FourSceneModel model = FourSceneModel(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
@ -60,12 +41,6 @@ class _LocationFourScenePageState extends State<LocationFourScenePage> {
|
||||
scene_4: '',
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
List<SubSpaceModel>? 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<LocationFourScenePage> {
|
||||
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<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final bool canSave = state is OptionSelectedState &&
|
||||
state.hasSelectionChanged;
|
||||
return InkWell(
|
||||
onTap: canSave
|
||||
? () {
|
||||
context.read<FourSceneBloc>().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<FourSceneBloc>().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<LocationFourScenePage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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<CircularCheckbox> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class FourSelectSceneFourPage extends StatelessWidget {
|
||||
onTap: canSave
|
||||
? () {
|
||||
print('object');
|
||||
context.read<FourSceneBloc>().add(SaveSelectionEvent());
|
||||
// context.read<FourSceneBloc>().add(SaveSelectionEvent());
|
||||
}
|
||||
: null,
|
||||
child: BodyMedium(
|
||||
|
@ -127,6 +127,7 @@ class DevicesAPI {
|
||||
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
print('object-=-=-$json');
|
||||
return json;
|
||||
});
|
||||
return response;
|
||||
|
Reference in New Issue
Block a user