mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
six scene
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart';
|
||||
@ -12,9 +11,11 @@ import 'package:syncrow_app/features/devices/model/scene_switch_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/sex_scene_question_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/six_scene_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';
|
||||
import 'package:syncrow_app/utils/helpers/snack_bar.dart';
|
||||
@ -28,7 +29,6 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
on<ToggleNotificationEvent>(_toggleNotification);
|
||||
on<ChangeNameEvent>(_changeName);
|
||||
on<SearchFaqEvent>(_onSearchFaq);
|
||||
on<FetchRoomsEvent>(_fetchRoomsAndDevices);
|
||||
on<ChangeSwitchStatusEvent>(changeSwitchStatus);
|
||||
on<LoadScenes>(_onLoadScenes);
|
||||
on<SearchScenesEvent>(searchScene);
|
||||
@ -42,6 +42,9 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
on<SelectSceneEvent>(_selectScene);
|
||||
on<SixSceneInitialInfo>(fetchDeviceInfo);
|
||||
on<ControlDeviceScene>(_controlDevice);
|
||||
on<SaveNameEvent>(saveName);
|
||||
on<AssignRoomEvent>(_assignDevice);
|
||||
on<FetchRoomsEvent>(_fetchRoomsAndDevices);
|
||||
}
|
||||
|
||||
final TextEditingController nameController =
|
||||
@ -96,6 +99,64 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
),
|
||||
);
|
||||
|
||||
List<SubSpaceModel> roomsList = [];
|
||||
|
||||
void _fetchRoomsAndDevices(
|
||||
FetchRoomsEvent event, Emitter<SixSceneState> emit) async {
|
||||
try {
|
||||
emit(SixSceneLoadingState());
|
||||
roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _assignDevice(AssignRoomEvent event, Emitter<SixSceneState> emit) async {
|
||||
try {
|
||||
emit(SixSceneLoadingState());
|
||||
if (_hasSelectionChanged) {
|
||||
await HomeManagementAPI.assignDeviceToRoom(
|
||||
event.unit.community.uuid, event.unit.id, event.roomId, sixSceneId);
|
||||
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!);
|
||||
});
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
|
||||
emit(SaveSelectionSuccessState());
|
||||
}
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> saveName(
|
||||
SaveNameEvent event, Emitter<SixSceneState> emit) async {
|
||||
if (_validateInputs()) return;
|
||||
try {
|
||||
add(const ChangeNameEvent(value: false));
|
||||
isSaving = true;
|
||||
emit(SixSceneLoadingState());
|
||||
var response = await DevicesAPI.putDeviceName(
|
||||
deviceId: sixSceneId, deviceName: nameController.text);
|
||||
add(const SixSceneInitialInfo());
|
||||
CustomSnackBar.displaySnackBar('Save Successfully');
|
||||
emit(SaveState());
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
} finally {
|
||||
isSaving = false;
|
||||
}
|
||||
}
|
||||
|
||||
Future fetchDeviceInfo(
|
||||
SixSceneInitialInfo event, Emitter<SixSceneState> emit) async {
|
||||
try {
|
||||
@ -122,7 +183,7 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
statusModelList,
|
||||
);
|
||||
add(const SexSceneSwitchInitial());
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
@ -138,7 +199,7 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
final response = await DevicesAPI.getSceneBySwitchName(
|
||||
deviceId: sixSceneId, switchName: event.switchName);
|
||||
selectedFormApiSceneId = response['scene']['uuid'];
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
@ -182,7 +243,7 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '',
|
||||
);
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
return;
|
||||
@ -231,10 +292,10 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
|
||||
void _toggleNotification(
|
||||
ToggleNotificationEvent event, Emitter<SixSceneState> emit) async {
|
||||
emit(LoadingNewSate(sosSensor: deviceStatus));
|
||||
emit(LoadingNewSate(device: deviceStatus));
|
||||
try {
|
||||
closingReminder = event.isClosingEnabled;
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(SixSceneFailedState(errorMessage: e.toString()));
|
||||
}
|
||||
@ -283,19 +344,6 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
|
||||
List<DeviceModel> allDevices = [];
|
||||
|
||||
void _fetchRoomsAndDevices(
|
||||
FetchRoomsEvent event, Emitter<SixSceneState> emit) async {
|
||||
try {
|
||||
emit(SixSceneLoadingState());
|
||||
final roomsList = await SpacesAPI.getSubSpaceBySpaceId(
|
||||
event.unit.community.uuid, event.unit.id);
|
||||
emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList));
|
||||
} catch (e) {
|
||||
emit(const SixSceneFailedState(errorMessage: 'Something went wrong'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool switchStatus = true;
|
||||
Future<void> changeSwitchStatus(
|
||||
ChangeSwitchStatusEvent event, Emitter<SixSceneState> emit) async {
|
||||
@ -412,7 +460,7 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
emit(SixSceneLoadingState());
|
||||
try {
|
||||
deviceStatus.switch_backlight = !event.backLight!;
|
||||
emit(UpdateState(sensor: deviceStatus));
|
||||
emit(UpdateState(device: deviceStatus));
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: sixSceneId,
|
||||
@ -427,4 +475,25 @@ class SixSceneBloc extends Bloc<SixSceneEvent, SixSceneState> {
|
||||
// add(InitialEvent(groupScreen: oneTouchGroup));
|
||||
}
|
||||
}
|
||||
|
||||
bool _validateInputs() {
|
||||
final nameError = fullNameValidator(nameController.text);
|
||||
if (nameError != null) {
|
||||
CustomSnackBar.displaySnackBar(nameError);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
String? fullNameValidator(String? value) {
|
||||
if (value == null) return 'name is required';
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r"\s+"), ' ').trim();
|
||||
if (withoutExtraSpaces.length < 2 || withoutExtraSpaces.length > 30) {
|
||||
return 'name must be between 2 and 30 characters long';
|
||||
}
|
||||
if (RegExp(r"/[^ a-zA-Z0-9-\']/").hasMatch(withoutExtraSpaces)) {
|
||||
return 'Only alphanumeric characters, space, dash and single quote are allowed';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/group_devices_model.dart';
|
||||
|
||||
@ -34,6 +35,10 @@ class SixSceneInitial extends SixSceneEvent {
|
||||
const SixSceneInitial();
|
||||
}
|
||||
|
||||
class SaveNameEvent extends SixSceneEvent {
|
||||
const SaveNameEvent();
|
||||
}
|
||||
|
||||
class SixSceneInitialInfo extends SixSceneEvent {
|
||||
const SixSceneInitialInfo();
|
||||
}
|
||||
@ -201,3 +206,22 @@ class ControlDeviceScene extends SixSceneEvent {
|
||||
final bool? backLight;
|
||||
const ControlDeviceScene({this.backLight});
|
||||
}
|
||||
|
||||
class AssignRoomEvent extends SixSceneEvent {
|
||||
final String roomId;
|
||||
final SpaceModel unit;
|
||||
final BuildContext context;
|
||||
|
||||
const AssignRoomEvent({
|
||||
required this.roomId,
|
||||
required this.unit,
|
||||
required this.context,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [
|
||||
roomId,
|
||||
unit,
|
||||
context,
|
||||
];
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ class SixSceneState extends Equatable {
|
||||
class SixSceneInitialState extends SixSceneState {}
|
||||
|
||||
class SixSceneLoadingState extends SixSceneState {}
|
||||
class SaveState extends SixSceneState {}
|
||||
|
||||
class SixSceState extends SixSceneState {}
|
||||
|
||||
@ -36,19 +37,19 @@ class SixSceneFailedState extends SixSceneState {
|
||||
}
|
||||
|
||||
class UpdateState extends SixSceneState {
|
||||
final SixSceneModel sensor;
|
||||
const UpdateState({required this.sensor});
|
||||
final SixSceneModel device;
|
||||
const UpdateState({required this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [sensor];
|
||||
List<Object> get props => [device];
|
||||
}
|
||||
|
||||
class LoadingNewSate extends SixSceneState {
|
||||
final SixSceneModel sosSensor;
|
||||
const LoadingNewSate({required this.sosSensor});
|
||||
final SixSceneModel device;
|
||||
const LoadingNewSate({required this.device});
|
||||
|
||||
@override
|
||||
List<Object> get props => [sosSensor];
|
||||
List<Object> get props => [device];
|
||||
}
|
||||
|
||||
class NameEditingState extends SixSceneState {
|
||||
|
@ -5,68 +5,47 @@ import 'package:syncrow_app/features/app_layout/model/space_model.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/model/six_scene_model.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/model/subspace_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_medium.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class LocationSixScenePage extends StatefulWidget {
|
||||
class LocationSixScenePage extends StatelessWidget {
|
||||
final SpaceModel? space;
|
||||
LocationSixScenePage({super.key, this.space});
|
||||
final String? deviceId;
|
||||
|
||||
@override
|
||||
_LocationSixScenePageState createState() => _LocationSixScenePageState();
|
||||
}
|
||||
|
||||
class _LocationSixScenePageState extends State<LocationSixScenePage> {
|
||||
String _selectedOption = 'Conference Room';
|
||||
bool _hasSelectionChanged = false;
|
||||
const LocationSixScenePage({
|
||||
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) => SixSceneBloc(sixSceneId: '')
|
||||
..add(FetchRoomsEvent(unit: widget.space!)),
|
||||
String roomIdSelected = '';
|
||||
|
||||
return Scaffold(
|
||||
body: BlocProvider(
|
||||
create: (context) => SixSceneBloc(sixSceneId: deviceId ?? '')
|
||||
..add(const SixSceneInitial())
|
||||
..add(const SixSceneInitialInfo())
|
||||
..add(FetchRoomsEvent(unit: space!)),
|
||||
child: BlocBuilder<SixSceneBloc, SixSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SixSceneBloc>(context);
|
||||
SixSceneModel model = SixSceneModel(
|
||||
final _bloc = BlocProvider.of<SixSceneBloc>(context);
|
||||
FourSceneModelState model = FourSceneModelState(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
scene_3: '',
|
||||
scene_4: '',
|
||||
scene_5: '',
|
||||
scene_6: '',
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
List<SubSpaceModel>? rooms = [];
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
} else if (state is FetchRoomsState) {
|
||||
rooms = state.roomsList;
|
||||
if (state is SaveSelectionSuccessState) {
|
||||
new Future.delayed(const Duration(microseconds: 500), () {
|
||||
_bloc.add(SixSceneInitialInfo());
|
||||
Navigator.of(context).pop(true);
|
||||
});
|
||||
}
|
||||
return state is SixSceneLoadingState
|
||||
? const Center(
|
||||
@ -76,11 +55,41 @@ class _LocationSixScenePageState extends State<LocationSixScenePage> {
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
)
|
||||
: RefreshIndicator(
|
||||
: DefaultScaffold(
|
||||
actions: [
|
||||
BlocBuilder<SixSceneBloc, SixSceneState>(
|
||||
builder: (context, state) {
|
||||
final bool canSave = state is OptionSelectedState &&
|
||||
state.hasSelectionChanged;
|
||||
return InkWell(
|
||||
onTap: canSave
|
||||
? () {
|
||||
context.read<SixSceneBloc>().add(
|
||||
AssignRoomEvent(
|
||||
context: context,
|
||||
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 SixSceneInitial());
|
||||
// sensor.add(const SosInitial());
|
||||
},
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: const EdgeInsets.symmetric(vertical: 20),
|
||||
children: [
|
||||
const BodyMedium(
|
||||
@ -95,21 +104,31 @@ class _LocationSixScenePageState extends State<LocationSixScenePage> {
|
||||
child: ListView.builder(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: rooms!.length,
|
||||
itemCount: _bloc.roomsList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final room = rooms![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: room.name!,
|
||||
onTap: (v) {
|
||||
setState(() {
|
||||
_selectedOption = v;
|
||||
_hasSelectionChanged = true;
|
||||
});
|
||||
label: fromRoom.name!,
|
||||
isSelected: isSelected,
|
||||
onTap: (label) {
|
||||
context.read<SixSceneBloc>().add(
|
||||
SelectOptionEvent(
|
||||
selectedOption: fromRoom.id!,
|
||||
),
|
||||
);
|
||||
roomIdSelected = fromRoom.id!;
|
||||
},
|
||||
),
|
||||
if (index < rooms.length - 1) ...[
|
||||
if (index < _bloc.roomsList.length - 1) ...[
|
||||
const SizedBox(height: 10),
|
||||
const Divider(
|
||||
color: ColorsManager.dividerColor,
|
||||
@ -123,40 +142,13 @@ class _LocationSixScenePageState extends State<LocationSixScenePage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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 {
|
||||
@ -202,3 +194,33 @@ 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);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//LocationSixScenePage
|
@ -39,9 +39,9 @@ class QuestionPage extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is SixSceneLoadingState
|
||||
? const Center(
|
||||
|
@ -38,9 +38,9 @@ class ShareSixScenePage extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is LoadingNewSate
|
||||
? const Center(
|
||||
|
@ -39,9 +39,9 @@ class SixSceneCreateGroup extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is LoadingNewSate
|
||||
? const Center(
|
||||
|
@ -1,9 +1,9 @@
|
||||
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/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/six_scene_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
@ -24,10 +24,11 @@ class SixSceneInfoPage extends StatelessWidget {
|
||||
title: 'Device Information',
|
||||
child: BlocProvider(
|
||||
create: (context) => SixSceneBloc(sixSceneId: device?.uuid ?? '')
|
||||
..add(const SixSceneInitial()),
|
||||
..add(const SixSceneInitial())
|
||||
..add(const SixSceneInitialInfo()),
|
||||
child: BlocBuilder<SixSceneBloc, SixSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SixSceneBloc>(context);
|
||||
final _bloc = BlocProvider.of<SixSceneBloc>(context);
|
||||
SixSceneModel model = SixSceneModel(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
@ -38,9 +39,9 @@ class SixSceneInfoPage extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is SixSceneLoadingState
|
||||
? const Center(
|
||||
@ -51,11 +52,11 @@ class SixSceneInfoPage extends StatelessWidget {
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
sensor.add(const SixSceneInitial());
|
||||
_bloc.add(const SixSceneInitial());
|
||||
},
|
||||
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,
|
||||
@ -70,12 +71,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(
|
||||
@ -94,18 +107,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,
|
||||
),
|
||||
],
|
||||
@ -113,18 +126,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,
|
||||
),
|
||||
],
|
||||
|
@ -5,10 +5,9 @@ import 'package:syncrow_app/features/app_layout/bloc/home_cubit.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/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/six_scene_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/6_scene_switch/6_scene_setting/location_setting.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/four_scene_switch/four_scene_setting/location_setting_four_scene.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';
|
||||
@ -26,12 +25,18 @@ class SixSceneProfilePage extends StatelessWidget {
|
||||
|
||||
return DefaultScaffold(
|
||||
title: 'Device Settings',
|
||||
leading: IconButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
icon: const Icon(Icons.arrow_back_ios)),
|
||||
child: BlocProvider(
|
||||
create: (context) => SixSceneBloc(sixSceneId: device?.uuid ?? '')
|
||||
..add(const SixSceneInitial()),
|
||||
..add(const SixSceneInitial())
|
||||
..add(const SixSceneInitialInfo()),
|
||||
child: BlocBuilder<SixSceneBloc, SixSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SixSceneBloc>(context);
|
||||
final _bloc = BlocProvider.of<SixSceneBloc>(context);
|
||||
SixSceneModel model = SixSceneModel(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
@ -42,9 +47,9 @@ class SixSceneProfilePage extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is SixSceneLoadingState
|
||||
? const Center(
|
||||
@ -55,7 +60,7 @@ class SixSceneProfilePage extends StatelessWidget {
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
sensor.add(const SixSceneInitial());
|
||||
_bloc.add(const SixSceneInitial());
|
||||
},
|
||||
child: ListView(
|
||||
children: [
|
||||
@ -64,11 +69,13 @@ class SixSceneProfilePage extends StatelessWidget {
|
||||
backgroundColor: Colors.white,
|
||||
child: CircleAvatar(
|
||||
radius: 55,
|
||||
backgroundColor: Colors.grey,
|
||||
backgroundColor: ColorsManager.graysColor,
|
||||
child: ClipOval(
|
||||
child: Center(
|
||||
child: SvgPicture.asset(
|
||||
Assets.sosProfileIcon,
|
||||
fit: BoxFit.fill,
|
||||
Assets.sixSceneIcon,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -91,11 +98,11 @@ class SixSceneProfilePage 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));
|
||||
_bloc.add(const SaveNameEvent());
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Your Name",
|
||||
@ -109,8 +116,7 @@ class SixSceneProfilePage 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),
|
||||
@ -134,29 +140,34 @@ class SixSceneProfilePage extends StatelessWidget {
|
||||
DefaultContainer(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
onTap: () async {
|
||||
bool val = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => LocationSixScenePage(
|
||||
builder: (context) => LocationFourScenePage(
|
||||
space: spaces!.first,
|
||||
deviceId: device?.uuid ?? '',
|
||||
)),
|
||||
);
|
||||
if (val == true) {
|
||||
_bloc.add(const SixSceneInitialInfo());
|
||||
}
|
||||
},
|
||||
child: const Row(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
child: Text('Location'),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
child: BodyMedium(
|
||||
text: 'Syncroom',
|
||||
text: _bloc
|
||||
.deviceInfo.subspace.subspaceName,
|
||||
fontColor: ColorsManager.textGray,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: 15,
|
||||
color: ColorsManager.textGray,
|
||||
|
@ -15,7 +15,6 @@ import 'package:syncrow_app/features/devices/view/widgets/6_scene_switch/6_scene
|
||||
import 'package:syncrow_app/features/devices/view/widgets/6_scene_switch/6_scene_setting/six_scene_profile_page.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/6_scene_switch/6_scene_setting/six_scene_update_dialog.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/6_scene_switch/6_scene_setting/six_scene_update_page.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';
|
||||
@ -34,10 +33,12 @@ class SixSceneSettings extends StatelessWidget {
|
||||
title: 'Device Settings',
|
||||
child: BlocProvider(
|
||||
create: (context) => SixSceneBloc(sixSceneId: device?.uuid ?? '')
|
||||
..add(const SixSceneInitial()),
|
||||
..add(const SixSceneInitial())
|
||||
..add(const SixSceneInitial())
|
||||
..add(SixSceneInitialInfo()),
|
||||
child: BlocBuilder<SixSceneBloc, SixSceneState>(
|
||||
builder: (context, state) {
|
||||
final sensor = BlocProvider.of<SixSceneBloc>(context);
|
||||
final _bloc = BlocProvider.of<SixSceneBloc>(context);
|
||||
SixSceneModel model = SixSceneModel(
|
||||
scene_1: '',
|
||||
scene_2: '',
|
||||
@ -48,9 +49,9 @@ class SixSceneSettings extends StatelessWidget {
|
||||
scene_id_group_id: '',
|
||||
switch_backlight: '');
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is SixSceneLoadingState
|
||||
? const Center(
|
||||
@ -59,28 +60,28 @@ class SixSceneSettings extends StatelessWidget {
|
||||
height: 50,
|
||||
child: CircularProgressIndicator()),
|
||||
)
|
||||
: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
sensor.add(const SixSceneInitial());
|
||||
},
|
||||
child: ListView(
|
||||
: ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
onTap: () async {
|
||||
bool val = await Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const SixSceneProfilePage(),
|
||||
builder: (context) => SixSceneProfilePage(
|
||||
device: device,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (val == true) {
|
||||
_bloc.add(const SixSceneInitialInfo());
|
||||
}
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
const Column(
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
SizedBox(height: 20),
|
||||
@ -100,14 +101,15 @@ class SixSceneSettings extends StatelessWidget {
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
BodyMedium(
|
||||
text: '6 Scene Switch',
|
||||
text: _bloc.deviceInfo.name,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
BodySmall(
|
||||
text: "Room: Syncrow"),
|
||||
text: _bloc.deviceInfo
|
||||
.subspace.subspaceName),
|
||||
],
|
||||
),
|
||||
Icon(Icons.edit_sharp)
|
||||
@ -156,8 +158,9 @@ class SixSceneSettings extends StatelessWidget {
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const SixSceneInfoPage()),
|
||||
builder: (context) => SixSceneInfoPage(
|
||||
device: device,
|
||||
)),
|
||||
);
|
||||
},
|
||||
text: 'Device Information',
|
||||
@ -230,8 +233,7 @@ class SixSceneSettings extends StatelessWidget {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
SixSceneCreateGroup(
|
||||
device: device!)),
|
||||
SixSceneCreateGroup(device: device!)),
|
||||
);
|
||||
},
|
||||
text: 'Create Group',
|
||||
@ -331,8 +333,7 @@ class SixSceneSettings extends StatelessWidget {
|
||||
builder: (context) {
|
||||
return DisconnectDeviceDialog(
|
||||
cancelTab: () {
|
||||
Navigator.of(context)
|
||||
.pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
confirmTab: () {
|
||||
// context
|
||||
@ -345,8 +346,7 @@ class SixSceneSettings extends StatelessWidget {
|
||||
// .selectedSpace!
|
||||
// .id!,
|
||||
// ));
|
||||
Navigator.of(context)
|
||||
.pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
@ -356,8 +356,8 @@ class SixSceneSettings extends StatelessWidget {
|
||||
text: 'Disconnect Device',
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 15,
|
||||
fontColor: ColorsManager
|
||||
.textPrimaryColor,
|
||||
fontColor:
|
||||
ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
@ -378,8 +378,7 @@ class SixSceneSettings extends StatelessWidget {
|
||||
builder: (context) {
|
||||
return DisconnectWipeData(
|
||||
cancelTab: () {
|
||||
Navigator.of(context)
|
||||
.pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
confirmTab: () {
|
||||
// context
|
||||
@ -392,8 +391,7 @@ class SixSceneSettings extends StatelessWidget {
|
||||
// .selectedSpace!
|
||||
// .id!,
|
||||
// ));
|
||||
Navigator.of(context)
|
||||
.pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
);
|
||||
},
|
||||
@ -404,8 +402,8 @@ class SixSceneSettings extends StatelessWidget {
|
||||
'Disconnect Device and Wipe Data',
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 15,
|
||||
fontColor: ColorsManager
|
||||
.textPrimaryColor,
|
||||
fontColor:
|
||||
ColorsManager.textPrimaryColor,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
@ -430,7 +428,6 @@ class SixSceneSettings extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
@ -58,9 +58,9 @@ class SixSceneScreen extends StatelessWidget {
|
||||
switch_backlight: '');
|
||||
|
||||
if (state is LoadingNewSate) {
|
||||
model = state.sosSensor;
|
||||
model = state.device;
|
||||
} else if (state is UpdateState) {
|
||||
model = state.sensor;
|
||||
model = state.device;
|
||||
}
|
||||
return state is SixSceneLoadingState
|
||||
? const Center(
|
||||
|
@ -162,17 +162,13 @@ class FourSceneScreen extends StatelessWidget {
|
||||
cancelTab: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
confirmTab:
|
||||
(switchSelected) async {
|
||||
confirmTab: (switchSelected) async {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
FourSelectSceneFourPage(
|
||||
switchSelected:
|
||||
switchSelected,
|
||||
deviceId:
|
||||
device!
|
||||
.uuid)),
|
||||
switchSelected:switchSelected,
|
||||
deviceId: device!.uuid)),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -25,7 +25,7 @@ class FourSceneInfoPage extends StatelessWidget {
|
||||
child: BlocProvider(
|
||||
create: (context) => FourSceneBloc(fourSceneId: device?.uuid ?? '')
|
||||
..add(const FourSceneInitial())
|
||||
..add(FourSceneInitialInfo()),
|
||||
..add(const FourSceneInitialInfo()),
|
||||
child: BlocBuilder<FourSceneBloc, FourSceneState>(
|
||||
builder: (context, state) {
|
||||
final _bloc = BlocProvider.of<FourSceneBloc>(context);
|
||||
|
@ -189,6 +189,7 @@ class DevicesAPI {
|
||||
path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
print('json==$json');
|
||||
return json;
|
||||
});
|
||||
return response;
|
||||
|
Reference in New Issue
Block a user