mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-16 01:56:24 +00:00
@ -2,13 +2,12 @@ import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||
|
||||
part 'setting_bloc_event.dart';
|
||||
|
||||
class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
@ -38,7 +37,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
|
||||
String? _fullNameValidator(String? value) {
|
||||
if (value == null) return 'name is required';
|
||||
final withoutExtraSpaces = value.replaceAll(RegExp(r'\s+'), ' ').trim();
|
||||
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';
|
||||
}
|
||||
@ -67,8 +66,8 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
DeviceSettingInitialInfo event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
final response = await DevicesManagementApi.getDeviceInfo(deviceId);
|
||||
final deviceInfo = DeviceInfoModel.fromJson(response);
|
||||
var response = await DevicesManagementApi.getDeviceInfo(deviceId);
|
||||
DeviceInfoModel deviceInfo = DeviceInfoModel.fromJson(response);
|
||||
nameController.text = deviceInfo.name;
|
||||
emit(DeviceSettingsUpdate(
|
||||
deviceName: nameController.text,
|
||||
@ -93,7 +92,9 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
));
|
||||
editName = event.value!;
|
||||
if (editName) {
|
||||
Future.delayed(const Duration(milliseconds: 500), focusNode.requestFocus);
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
focusNode.requestFocus();
|
||||
});
|
||||
} else {
|
||||
add(const SettingBlocSaveName());
|
||||
focusNode.unfocus();
|
||||
@ -105,7 +106,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> _deleteDevice(
|
||||
void _deleteDevice(
|
||||
SettingBlocDeleteDevice event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
@ -122,7 +123,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onAssignDevice(
|
||||
void _onAssignDevice(
|
||||
SettingBlocAssignRoom event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
@ -142,7 +143,7 @@ class SettingDeviceBloc extends Bloc<DeviceSettingEvent, DeviceSettingsState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _fetchRooms(
|
||||
void _fetchRooms(
|
||||
SettingBlocFetchRooms event, Emitter<DeviceSettingsState> emit) async {
|
||||
try {
|
||||
emit(DeviceSettingsLoading());
|
||||
|
@ -2,12 +2,12 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/device_icon_type_helper.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/device_management_content.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/remove_device_widget.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/device_info_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/bloc/setting_bloc_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/device_setting/settings_model/sub_space_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
@ -38,7 +38,7 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
builder: (context) {
|
||||
return BlocBuilder<SettingDeviceBloc, DeviceSettingsState>(
|
||||
builder: (context, state) {
|
||||
final bloc = context.read<SettingDeviceBloc>();
|
||||
final _bloc = context.read<SettingDeviceBloc>();
|
||||
final iconPath = DeviceIconTypeHelper.getDeviceIconByTypeCode(
|
||||
device.productType);
|
||||
final deviceInfo = state is DeviceSettingsUpdate
|
||||
@ -73,7 +73,7 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: ColorsManager.vividBlue
|
||||
.withValues(alpha: 0.7),
|
||||
.withOpacity(0.7),
|
||||
fontSize: 24),
|
||||
),
|
||||
],
|
||||
@ -87,8 +87,8 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
child: CircleAvatar(
|
||||
radius: 38,
|
||||
backgroundColor: ColorsManager.grayBorder
|
||||
.withValues(alpha: 0.5),
|
||||
backgroundColor:
|
||||
ColorsManager.grayBorder.withOpacity(0.5),
|
||||
child: CircleAvatar(
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
radius: 36,
|
||||
@ -128,14 +128,14 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
fontSize: 16,
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
focusNode: bloc.focusNode,
|
||||
controller: bloc.nameController,
|
||||
enabled: bloc.editName,
|
||||
focusNode: _bloc.focusNode,
|
||||
controller: _bloc.nameController,
|
||||
enabled: _bloc.editName,
|
||||
onFieldSubmitted: (value) {
|
||||
bloc.add(const ChangeNameEvent(
|
||||
_bloc.add(const ChangeNameEvent(
|
||||
value: false));
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
decoration: InputDecoration(
|
||||
isDense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
border: InputBorder.none,
|
||||
@ -151,11 +151,11 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
height: 25,
|
||||
child: Visibility(
|
||||
visible:
|
||||
bloc.editName != true,
|
||||
_bloc.editName != true,
|
||||
replacement: const SizedBox(),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
bloc.add(
|
||||
_bloc.add(
|
||||
const ChangeNameEvent(
|
||||
value: true));
|
||||
},
|
||||
@ -192,14 +192,14 @@ class DeviceSettingsPanel extends StatelessWidget {
|
||||
deviceInfo: deviceInfo,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
RemoveDeviceWidget(bloc: bloc),
|
||||
RemoveDeviceWidget(bloc: _bloc),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (state is DeviceSettingsLoading)
|
||||
Positioned.fill(
|
||||
child: ColoredBox(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
child: Container(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: ColorsManager.primaryColor,
|
||||
|
@ -20,9 +20,9 @@ class SubSpaceModel {
|
||||
}
|
||||
|
||||
factory SubSpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
final devices = <DeviceModel>[];
|
||||
List<DeviceModel> devices = [];
|
||||
if (json['devices'] != null) {
|
||||
for (final device in json['devices']) {
|
||||
for (var device in json['devices']) {
|
||||
devices.add(DeviceModel.fromJson(device));
|
||||
}
|
||||
}
|
||||
|
@ -12,11 +12,11 @@ class SubSpaceDialog extends StatefulWidget {
|
||||
final void Function(SubSpaceModel?) onConfirmed;
|
||||
|
||||
const SubSpaceDialog({
|
||||
super.key,
|
||||
Key? key,
|
||||
required this.subSpaces,
|
||||
this.selected,
|
||||
required this.onConfirmed,
|
||||
});
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<SubSpaceDialog> createState() => _SubSpaceDialogState();
|
||||
@ -63,7 +63,7 @@ class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
||||
_selectedId = value;
|
||||
});
|
||||
},
|
||||
activeColor: const Color(0xFF2962FF),
|
||||
activeColor: Color(0xFF2962FF),
|
||||
title: Text(
|
||||
space.name ?? 'Unnamed Sub-Space',
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
@ -75,7 +75,7 @@ class _SubSpaceDialogState extends State<SubSpaceDialog> {
|
||||
controlAffinity: ListTileControlAffinity.trailing,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
);
|
||||
}),
|
||||
}).toList(),
|
||||
const SizedBox(height: 12),
|
||||
const Divider(height: 1, thickness: 1),
|
||||
SubSpaceDialogButtons(selectedId: _selectedId, widget: widget),
|
||||
|
Reference in New Issue
Block a user