mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-26 23:14:55 +00:00
Compare commits
8 Commits
SP-1344-FE
...
SP-1440-FE
| Author | SHA1 | Date | |
|---|---|---|---|
| 67a164e6d2 | |||
| cf20bdcd42 | |||
| 84264391d9 | |||
| 2e4f904d3a | |||
| c46cfb48a8 | |||
| a0dd128557 | |||
| 34fa426163 | |||
| 1407c173b0 |
@ -55,12 +55,12 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
|
|||||||
final isSmallScreen = isSmallScreenSize(context);
|
final isSmallScreen = isSmallScreenSize(context);
|
||||||
final isMediumScreen = isMediumScreenSize(context);
|
final isMediumScreen = isMediumScreenSize(context);
|
||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
late ScrollController _scrollController;
|
late ScrollController scrollController;
|
||||||
_scrollController = ScrollController();
|
scrollController = ScrollController();
|
||||||
|
|
||||||
void _scrollToCenter() {
|
void scrollToCenter() {
|
||||||
final double middlePosition = _scrollController.position.maxScrollExtent / 2;
|
final double middlePosition = scrollController.position.maxScrollExtent / 2;
|
||||||
_scrollController.animateTo(
|
scrollController.animateTo(
|
||||||
middlePosition,
|
middlePosition,
|
||||||
duration: const Duration(seconds: 1),
|
duration: const Duration(seconds: 1),
|
||||||
curve: Curves.easeInOut,
|
curve: Curves.easeInOut,
|
||||||
@ -68,7 +68,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
|
|||||||
}
|
}
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_scrollToCenter();
|
scrollToCenter();
|
||||||
});
|
});
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
@ -76,7 +76,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
|
|||||||
FirstLayer(
|
FirstLayer(
|
||||||
second: Center(
|
second: Center(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
controller: _scrollController,
|
controller: scrollController,
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
@ -199,7 +199,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
|
|||||||
width: size.width * 0.9,
|
width: size.width * 0.9,
|
||||||
child: DropdownButtonHideUnderline(
|
child: DropdownButtonHideUnderline(
|
||||||
child: DropdownButton2<String>(
|
child: DropdownButton2<String>(
|
||||||
style: TextStyle(color: Colors.black),
|
style: const TextStyle(color: Colors.black),
|
||||||
isExpanded: true,
|
isExpanded: true,
|
||||||
hint: Text(
|
hint: Text(
|
||||||
'Select your region/country',
|
'Select your region/country',
|
||||||
@ -336,6 +336,16 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
|
|||||||
obscureText: loginBloc.obscureText,
|
obscureText: loginBloc.obscureText,
|
||||||
keyboardType: TextInputType.visiblePassword,
|
keyboardType: TextInputType.visiblePassword,
|
||||||
controller: loginBloc.loginPasswordController,
|
controller: loginBloc.loginPasswordController,
|
||||||
|
onFieldSubmitted: (value) {
|
||||||
|
if (loginBloc.loginFormKey.currentState!.validate()) {
|
||||||
|
loginBloc.add(LoginButtonPressed(
|
||||||
|
username: loginBloc.loginEmailController.text,
|
||||||
|
password: value,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
loginBloc.add(ChangeValidateEvent());
|
||||||
|
}
|
||||||
|
},
|
||||||
decoration: textBoxDecoration()!.copyWith(
|
decoration: textBoxDecoration()!.copyWith(
|
||||||
hintText: 'At least 8 characters',
|
hintText: 'At least 8 characters',
|
||||||
hintStyle: Theme.of(context)
|
hintStyle: Theme.of(context)
|
||||||
@ -393,7 +403,7 @@ class _LoginWebPageState extends State<LoginWebPage> with HelperResponsiveLayout
|
|||||||
Transform.scale(
|
Transform.scale(
|
||||||
scale: 1.2,
|
scale: 1.2,
|
||||||
child: Checkbox(
|
child: Checkbox(
|
||||||
fillColor: MaterialStateProperty.all<Color>(Colors.white),
|
fillColor: WidgetStateProperty.all<Color>(Colors.white),
|
||||||
activeColor: Colors.white,
|
activeColor: Colors.white,
|
||||||
value: loginBloc.isChecked,
|
value: loginBloc.isChecked,
|
||||||
checkColor: Colors.black,
|
checkColor: Colors.black,
|
||||||
|
|||||||
@ -60,15 +60,7 @@ class _CurrentTempState extends State<CurrentTemp> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@override
|
|
||||||
void didUpdateWidget(CurrentTemp oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (oldWidget.tempSet != widget.tempSet) {
|
|
||||||
setState(() {
|
|
||||||
_adjustedValue = _initialAdjustedValue(widget.tempSet);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_debounce?.cancel();
|
_debounce?.cancel();
|
||||||
|
|||||||
@ -16,8 +16,7 @@ import 'package:syncrow_web/pages/device_managment/shared/table/report_table.dar
|
|||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class CeilingSensorControlsView extends StatelessWidget
|
class CeilingSensorControlsView extends StatelessWidget with HelperResponsiveLayout {
|
||||||
with HelperResponsiveLayout {
|
|
||||||
const CeilingSensorControlsView({super.key, required this.device});
|
const CeilingSensorControlsView({super.key, required this.device});
|
||||||
|
|
||||||
final AllDevicesModel device;
|
final AllDevicesModel device;
|
||||||
@ -32,35 +31,29 @@ class CeilingSensorControlsView extends StatelessWidget
|
|||||||
..add(CeilingInitialEvent(device.uuid ?? '')),
|
..add(CeilingInitialEvent(device.uuid ?? '')),
|
||||||
child: BlocBuilder<CeilingSensorBloc, CeilingSensorState>(
|
child: BlocBuilder<CeilingSensorBloc, CeilingSensorState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is CeilingLoadingInitialState ||
|
if (state is CeilingLoadingInitialState || state is CeilingReportsLoadingState) {
|
||||||
state is CeilingReportsLoadingState) {
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
} else if (state is CeilingUpdateState) {
|
} else if (state is CeilingUpdateState) {
|
||||||
return _buildGridView(context, state.ceilingSensorModel,
|
return _buildGridView(
|
||||||
isExtraLarge, isLarge, isMedium);
|
context, state.ceilingSensorModel, isExtraLarge, isLarge, isMedium);
|
||||||
} else if (state is CeilingReportsState) {
|
} else if (state is CeilingReportsState) {
|
||||||
return ReportsTable(
|
return ReportsTable(
|
||||||
report: state.deviceReport,
|
report: state.deviceReport,
|
||||||
onRowTap: (index) {},
|
onRowTap: (index) {},
|
||||||
onClose: () {
|
onClose: () {
|
||||||
context
|
context.read<CeilingSensorBloc>().add(BackToCeilingGridViewEvent());
|
||||||
.read<CeilingSensorBloc>()
|
|
||||||
.add(BackToCeilingGridViewEvent());
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else if (state is ShowCeilingDescriptionState) {
|
} else if (state is ShowCeilingDescriptionState) {
|
||||||
return DescriptionView(
|
return DescriptionView(
|
||||||
description: state.description,
|
description: state.description,
|
||||||
onClose: () {
|
onClose: () {
|
||||||
context
|
context.read<CeilingSensorBloc>().add(BackToCeilingGridViewEvent());
|
||||||
.read<CeilingSensorBloc>()
|
|
||||||
.add(BackToCeilingGridViewEvent());
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else if (state is CeilingReportsFailedState) {
|
} else if (state is CeilingReportsFailedState) {
|
||||||
final model = context.read<CeilingSensorBloc>().deviceStatus;
|
final model = context.read<CeilingSensorBloc>().deviceStatus;
|
||||||
return _buildGridView(
|
return _buildGridView(context, model, isExtraLarge, isLarge, isMedium);
|
||||||
context, model, isExtraLarge, isLarge, isMedium);
|
|
||||||
}
|
}
|
||||||
return const Center(child: Text('Error fetching status'));
|
return const Center(child: Text('Error fetching status'));
|
||||||
},
|
},
|
||||||
@ -68,8 +61,8 @@ class CeilingSensorControlsView extends StatelessWidget
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildGridView(BuildContext context, CeilingSensorModel model,
|
Widget _buildGridView(BuildContext context, CeilingSensorModel model, bool isExtraLarge,
|
||||||
bool isExtraLarge, bool isLarge, bool isMedium) {
|
bool isLarge, bool isMedium) {
|
||||||
return GridView(
|
return GridView(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
@ -150,8 +143,8 @@ class CeilingSensorControlsView extends StatelessWidget
|
|||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.read<CeilingSensorBloc>().add(GetCeilingDeviceReportsEvent(
|
context.read<CeilingSensorBloc>().add(
|
||||||
code: 'presence_state', deviceUuid: device.uuid!));
|
GetCeilingDeviceReportsEvent(code: 'presence_state', deviceUuid: device.uuid!));
|
||||||
},
|
},
|
||||||
child: const PresenceStaticWidget(
|
child: const PresenceStaticWidget(
|
||||||
icon: Assets.illuminanceRecordIcon,
|
icon: Assets.illuminanceRecordIcon,
|
||||||
@ -160,8 +153,9 @@ class CeilingSensorControlsView extends StatelessWidget
|
|||||||
),
|
),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.read<CeilingSensorBloc>().add(GetCeilingDeviceReportsEvent(
|
context
|
||||||
code: '', deviceUuid: device.uuid!));
|
.read<CeilingSensorBloc>()
|
||||||
|
.add(GetCeilingDeviceReportsEvent(code: '', deviceUuid: device.uuid!));
|
||||||
},
|
},
|
||||||
child: const PresenceStaticWidget(
|
child: const PresenceStaticWidget(
|
||||||
icon: Assets.helpDescriptionIcon,
|
icon: Assets.helpDescriptionIcon,
|
||||||
|
|||||||
@ -84,16 +84,6 @@ class _PresenceUpdateDataState extends State<PresenceNoBodyTime> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void didUpdateWidget(PresenceNoBodyTime oldWidget) {
|
|
||||||
super.didUpdateWidget(oldWidget);
|
|
||||||
if (oldWidget.value != widget.value) {
|
|
||||||
setState(() {
|
|
||||||
_currentValue = widget.value;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return DeviceControlsContainer(
|
return DeviceControlsContainer(
|
||||||
|
|||||||
@ -21,7 +21,6 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
on<ShowDescriptionEvent>(_showDescription);
|
on<ShowDescriptionEvent>(_showDescription);
|
||||||
on<BackToGridViewEvent>(_backToGridView);
|
on<BackToGridViewEvent>(_backToGridView);
|
||||||
on<WallSensorFactoryResetEvent>(_onFactoryReset);
|
on<WallSensorFactoryResetEvent>(_onFactoryReset);
|
||||||
on<WallSensorRealtimeUpdateEvent>(_onRealtimeUpdate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchWallSensorStatus(
|
void _fetchWallSensorStatus(
|
||||||
@ -31,7 +30,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
var response = await DevicesManagementApi().getDeviceStatus(deviceId);
|
var response = await DevicesManagementApi().getDeviceStatus(deviceId);
|
||||||
deviceStatus = WallSensorModel.fromJson(response.status);
|
deviceStatus = WallSensorModel.fromJson(response.status);
|
||||||
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
||||||
_listenToChanges(deviceId);
|
_listenToChanges(emit, deviceId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(WallSensorFailedState(error: e.toString()));
|
emit(WallSensorFailedState(error: e.toString()));
|
||||||
return;
|
return;
|
||||||
@ -53,27 +52,28 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _listenToChanges(String deviceId) {
|
_listenToChanges(Emitter<WallSensorState> emit, deviceId) {
|
||||||
DatabaseReference ref =
|
try {
|
||||||
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
DatabaseReference ref =
|
||||||
ref.onValue.listen((DatabaseEvent event) {
|
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||||
final data = event.snapshot.value as Map<dynamic, dynamic>?;
|
Stream<DatabaseEvent> stream = ref.onValue;
|
||||||
if (data == null) return;
|
|
||||||
|
|
||||||
final statusList = (data['status'] as List?)
|
stream.listen((DatabaseEvent event) {
|
||||||
?.map((e) => Status(code: e['code'], value: e['value']))
|
Map<dynamic, dynamic> usersMap =
|
||||||
.toList();
|
event.snapshot.value as Map<dynamic, dynamic>;
|
||||||
|
List<Status> statusList = [];
|
||||||
|
|
||||||
if (statusList != null) {
|
usersMap['status'].forEach((element) {
|
||||||
final updatedDeviceStatus = WallSensorModel.fromJson(statusList);
|
statusList
|
||||||
if (!isClosed) {
|
.add(Status(code: element['code'], value: element['value']));
|
||||||
add(WallSensorRealtimeUpdateEvent(updatedDeviceStatus));
|
});
|
||||||
}
|
|
||||||
}
|
deviceStatus = WallSensorModel.fromJson(statusList);
|
||||||
});
|
emit(WallSensorLoadingNewSate(wallSensorModel: deviceStatus));
|
||||||
|
});
|
||||||
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void _changeValue(
|
void _changeValue(
|
||||||
WallSensorChangeValueEvent event, Emitter<WallSensorState> emit) async {
|
WallSensorChangeValueEvent event, Emitter<WallSensorState> emit) async {
|
||||||
emit(WallSensorLoadingNewSate(wallSensorModel: deviceStatus));
|
emit(WallSensorLoadingNewSate(wallSensorModel: deviceStatus));
|
||||||
@ -195,12 +195,4 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
|||||||
emit(WallSensorFailedState(error: e.toString()));
|
emit(WallSensorFailedState(error: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onRealtimeUpdate(
|
|
||||||
WallSensorRealtimeUpdateEvent event,
|
|
||||||
Emitter<WallSensorState> emit,
|
|
||||||
) {
|
|
||||||
deviceStatus = event.deviceStatus;
|
|
||||||
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/wall_sensor/model/wall_sensor_model.dart';
|
|
||||||
|
|
||||||
abstract class WallSensorEvent extends Equatable {
|
abstract class WallSensorEvent extends Equatable {
|
||||||
const WallSensorEvent();
|
const WallSensorEvent();
|
||||||
@ -71,8 +70,3 @@ class WallSensorFactoryResetEvent extends WallSensorEvent {
|
|||||||
required this.factoryReset,
|
required this.factoryReset,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class WallSensorRealtimeUpdateEvent extends WallSensorEvent {
|
|
||||||
final WallSensorModel deviceStatus;
|
|
||||||
const WallSensorRealtimeUpdateEvent(this.deviceStatus);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
import 'package:flutter_svg/flutter_svg.dart';
|
import 'package:flutter_svg/flutter_svg.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
|
||||||
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
@ -15,13 +14,18 @@ class SaveRoutineHelper {
|
|||||||
static Future<void> showSaveRoutineDialog(BuildContext context) async {
|
static Future<void> showSaveRoutineDialog(BuildContext context) async {
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
final selectedConditionLabel = state.selectedAutomationOperator == 'and'
|
||||||
|
? 'All Conditions are met'
|
||||||
|
: 'Any Condition is met';
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
content: Container(
|
content: Container(
|
||||||
width: MediaQuery.sizeOf(context).width * 0.5,
|
width: context.screenWidth * 0.5,
|
||||||
|
height: 500,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
@ -29,99 +33,42 @@ class SaveRoutineHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
DialogHeader('Create a scene: ${state.routineName ?? ""}'),
|
const SizedBox(height: 18),
|
||||||
Padding(
|
Text(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
'Create a scene: ${state.routineName ?? ""}',
|
||||||
child: Row(
|
textAlign: TextAlign.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
|
||||||
children: [
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
// Left side - IF
|
fontWeight: FontWeight.bold,
|
||||||
Expanded(
|
|
||||||
child: ListView(
|
|
||||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
shrinkWrap: true,
|
|
||||||
children: [
|
|
||||||
const Text(
|
|
||||||
'IF:',
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
if (state.isTabToRun)
|
|
||||||
ListTile(
|
|
||||||
leading: SvgPicture.asset(
|
|
||||||
Assets.tabToRun,
|
|
||||||
width: 24,
|
|
||||||
height: 24,
|
|
||||||
),
|
|
||||||
title: const Text('Tab to run'),
|
|
||||||
),
|
|
||||||
if (state.isAutomation)
|
|
||||||
...state.ifItems.map((item) {
|
|
||||||
final functions =
|
|
||||||
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
|
||||||
return functionRow(item, context, functions);
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
),
|
||||||
// Right side - THEN items
|
const SizedBox(height: 18),
|
||||||
|
_buildDivider(),
|
||||||
Expanded(
|
_buildListsLabelRow(selectedConditionLabel),
|
||||||
child: ListView(
|
Expanded(
|
||||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
child: Padding(
|
||||||
shrinkWrap: true,
|
padding: const EdgeInsetsDirectional.symmetric(
|
||||||
children: [
|
horizontal: 16,
|
||||||
const Text(
|
),
|
||||||
'THEN:',
|
child: Row(
|
||||||
style: TextStyle(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
fontSize: 16,
|
mainAxisSize: MainAxisSize.min,
|
||||||
),
|
spacing: 24,
|
||||||
),
|
children: [
|
||||||
const SizedBox(height: 8),
|
_buildIfConditions(state, context),
|
||||||
...state.thenItems.map((item) {
|
Container(
|
||||||
final functions =
|
width: 1,
|
||||||
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
color: ColorsManager.greyColor.withValues(alpha: 0.8),
|
||||||
return functionRow(item, context, functions);
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
_buildThenActions(state, context),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// if (state.errorMessage != null || state.errorMessage!.isNotEmpty)
|
_buildDivider(),
|
||||||
// Padding(
|
const SizedBox(height: 8),
|
||||||
// padding: const EdgeInsets.all(8.0),
|
_buildDialogFooter(context, state),
|
||||||
// child: Text(
|
const SizedBox(height: 8),
|
||||||
// state.errorMessage!,
|
|
||||||
// style: const TextStyle(color: Colors.red),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
DialogFooter(
|
|
||||||
onCancel: () => Navigator.pop(context),
|
|
||||||
onConfirm: () async {
|
|
||||||
if (state.isAutomation) {
|
|
||||||
if (state.isUpdate ?? false) {
|
|
||||||
context.read<RoutineBloc>().add(const UpdateAutomation());
|
|
||||||
} else {
|
|
||||||
context.read<RoutineBloc>().add(const CreateAutomationEvent());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (state.isUpdate ?? false) {
|
|
||||||
context.read<RoutineBloc>().add(const UpdateScene());
|
|
||||||
} else {
|
|
||||||
context.read<RoutineBloc>().add(const CreateSceneEvent());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if (state.errorMessage == null || state.errorMessage!.isEmpty) {
|
|
||||||
Navigator.pop(context);
|
|
||||||
// }
|
|
||||||
},
|
|
||||||
isConfirmEnabled: true,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -132,8 +79,107 @@ class SaveRoutineHelper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Container _buildDivider() {
|
||||||
|
return Container(
|
||||||
|
height: 1,
|
||||||
|
width: double.infinity,
|
||||||
|
color: ColorsManager.greyColor,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildListsLabelRow(String selectedConditionLabel) {
|
||||||
|
const textStyle = TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
);
|
||||||
|
return Container(
|
||||||
|
color: ColorsManager.backgroundColor.withValues(alpha: 0.5),
|
||||||
|
padding: const EdgeInsetsDirectional.all(20),
|
||||||
|
child: Row(
|
||||||
|
spacing: 16,
|
||||||
|
children: [
|
||||||
|
Expanded(child: Text('IF: $selectedConditionLabel', style: textStyle)),
|
||||||
|
const Expanded(child: Text('THEN:', style: textStyle)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildDialogFooter(BuildContext context, RoutineState state) {
|
||||||
|
return Row(
|
||||||
|
spacing: 16,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: [
|
||||||
|
DialogFooterButton(
|
||||||
|
text: 'Cancel',
|
||||||
|
onTap: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
DialogFooterButton(
|
||||||
|
text: 'Confirm',
|
||||||
|
onTap: () {
|
||||||
|
if (state.isAutomation) {
|
||||||
|
if (state.isUpdate ?? false) {
|
||||||
|
context.read<RoutineBloc>().add(const UpdateAutomation());
|
||||||
|
} else {
|
||||||
|
context.read<RoutineBloc>().add(const CreateAutomationEvent());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (state.isUpdate ?? false) {
|
||||||
|
context.read<RoutineBloc>().add(const UpdateScene());
|
||||||
|
} else {
|
||||||
|
context.read<RoutineBloc>().add(const CreateSceneEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
textColor: ColorsManager.primaryColorWithOpacity,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildThenActions(RoutineState state, BuildContext context) {
|
||||||
|
return Expanded(
|
||||||
|
child: ListView(
|
||||||
|
// shrinkWrap: true,
|
||||||
|
children: state.thenItems.map((item) {
|
||||||
|
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
|
return functionRow(item, context, functions);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _buildIfConditions(RoutineState state, BuildContext context) {
|
||||||
|
return Expanded(
|
||||||
|
child: ListView(
|
||||||
|
// shrinkWrap: true,
|
||||||
|
children: [
|
||||||
|
if (state.isTabToRun)
|
||||||
|
ListTile(
|
||||||
|
leading: SvgPicture.asset(
|
||||||
|
Assets.tabToRun,
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
),
|
||||||
|
title: const Text('Tab to run'),
|
||||||
|
),
|
||||||
|
if (state.isAutomation)
|
||||||
|
...state.ifItems.map((item) {
|
||||||
|
final functions =
|
||||||
|
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
|
return functionRow(item, context, functions);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static Widget functionRow(
|
static Widget functionRow(
|
||||||
dynamic item, BuildContext context, List<DeviceFunctionData> functions) {
|
dynamic item,
|
||||||
|
BuildContext context,
|
||||||
|
List<DeviceFunctionData> functions,
|
||||||
|
) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.only(top: 6),
|
padding: const EdgeInsets.only(top: 6),
|
||||||
child: Row(
|
child: Row(
|
||||||
@ -142,19 +188,36 @@ class SaveRoutineHelper {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
spacing: 8,
|
spacing: 17,
|
||||||
children: [
|
children: [
|
||||||
item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
Container(
|
||||||
? Image.memory(
|
width: 22,
|
||||||
base64Decode(item['icon']),
|
height: 22,
|
||||||
width: 22,
|
padding: const EdgeInsetsDirectional.all(4),
|
||||||
height: 22,
|
decoration: BoxDecoration(
|
||||||
)
|
shape: BoxShape.circle,
|
||||||
: SvgPicture.asset(
|
color: ColorsManager.textFieldGreyColor,
|
||||||
item['imagePath'],
|
border: Border.all(
|
||||||
width: 22,
|
color: ColorsManager.neutralGray,
|
||||||
height: 22,
|
width: 1.5,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: item['type'] == 'tap_to_run' || item['type'] == 'scene'
|
||||||
|
? Image.memory(
|
||||||
|
base64Decode(item['icon']),
|
||||||
|
width: 12,
|
||||||
|
height: 22,
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
)
|
||||||
|
: SvgPicture.asset(
|
||||||
|
item['imagePath'],
|
||||||
|
width: 12,
|
||||||
|
height: 12,
|
||||||
|
fit: BoxFit.scaleDown,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@ -166,19 +229,25 @@ class SaveRoutineHelper {
|
|||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
fontSize: 14,
|
fontSize: 15,
|
||||||
color: ColorsManager.textPrimaryColor,
|
color: ColorsManager.textPrimaryColor,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Wrap(
|
Wrap(
|
||||||
|
runSpacing: 16,
|
||||||
|
spacing: 4,
|
||||||
children: functions
|
children: functions
|
||||||
.map((f) => Text(
|
.map(
|
||||||
'${f.operationName}: ${f.value}',
|
(function) => Text(
|
||||||
style: context.textTheme.bodySmall
|
'${function.operationName}: ${function.value}',
|
||||||
?.copyWith(color: ColorsManager.grayColor, fontSize: 8),
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
overflow: TextOverflow.ellipsis,
|
color: ColorsManager.grayColor,
|
||||||
maxLines: 3,
|
fontSize: 8,
|
||||||
))
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 3,
|
||||||
|
),
|
||||||
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -197,7 +266,13 @@ class SaveRoutineHelper {
|
|||||||
child: Row(
|
child: Row(
|
||||||
spacing: 2,
|
spacing: 2,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(width: 8, height: 8, child: SvgPicture.asset(Assets.deviceTagIcon)),
|
SizedBox(
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
Assets.deviceTagIcon,
|
||||||
|
),
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
item['tag'] ?? '',
|
item['tag'] ?? '',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
@ -218,7 +293,12 @@ class SaveRoutineHelper {
|
|||||||
spacing: 2,
|
spacing: 2,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 8, height: 8, child: SvgPicture.asset(Assets.spaceLocationIcon)),
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
Assets.spaceLocationIcon,
|
||||||
|
),
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
item['subSpace'] ?? '',
|
item['subSpace'] ?? '',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/create_new_routines/create_new_routines.dart';
|
import 'package:syncrow_web/pages/routines/create_new_routines/create_new_routines.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
||||||
@ -9,7 +9,6 @@ import 'package:syncrow_web/pages/routines/widgets/main_routine_view/fetch_routi
|
|||||||
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart';
|
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|
||||||
|
|
||||||
class RoutinesView extends StatefulWidget {
|
class RoutinesView extends StatefulWidget {
|
||||||
const RoutinesView({super.key});
|
const RoutinesView({super.key});
|
||||||
@ -28,10 +27,9 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
if (result == null) return;
|
if (result == null) return;
|
||||||
final communityId = result['community'];
|
final communityId = result['community'];
|
||||||
final spaceId = result['space'];
|
final spaceId = result['space'];
|
||||||
final bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
final _bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
||||||
final routineBloc = context.read<RoutineBloc>();
|
final routineBloc = context.read<RoutineBloc>();
|
||||||
bloc.add(
|
_bloc.add(SaveCommunityIdAndSpaceIdEvent(communityID: communityId, spaceID: spaceId));
|
||||||
SaveCommunityIdAndSpaceIdEvent(communityID: communityId, spaceID: spaceId));
|
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
routineBloc.add(const CreateNewRoutineViewEvent(createRoutineView: true));
|
routineBloc.add(const CreateNewRoutineViewEvent(createRoutineView: true));
|
||||||
}
|
}
|
||||||
@ -56,41 +54,43 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 4,
|
flex: 4,
|
||||||
child: SizedBox(
|
child: ListView(
|
||||||
height: context.screenHeight,
|
children: [
|
||||||
width: context.screenWidth,
|
Container(
|
||||||
child: SingleChildScrollView(
|
padding: const EdgeInsets.all(16),
|
||||||
padding: const EdgeInsetsDirectional.all(16),
|
height: MediaQuery.sizeOf(context).height,
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
children: [
|
||||||
spacing: 16,
|
Text(
|
||||||
children: [
|
"Create New Routines",
|
||||||
Text(
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
"Create New Routines",
|
color: ColorsManager.grayColor,
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
fontWeight: FontWeight.bold,
|
||||||
color: ColorsManager.grayColor,
|
),
|
||||||
fontWeight: FontWeight.bold,
|
),
|
||||||
),
|
const SizedBox(height: 10),
|
||||||
),
|
RoutineViewCard(
|
||||||
RoutineViewCard(
|
isLoading: false,
|
||||||
isLoading: false,
|
onChanged: (v) {},
|
||||||
onChanged: (v) {},
|
status: '',
|
||||||
status: '',
|
spaceId: '',
|
||||||
spaceId: '',
|
automationId: '',
|
||||||
automationId: '',
|
communityId: '',
|
||||||
communityId: '',
|
sceneId: '',
|
||||||
sceneId: '',
|
cardType: '',
|
||||||
cardType: '',
|
spaceName: '',
|
||||||
spaceName: '',
|
onTap: () => _handleRoutineCreation(context),
|
||||||
onTap: () => _handleRoutineCreation(context),
|
icon: Icons.add,
|
||||||
icon: Icons.add,
|
textString: '',
|
||||||
textString: '',
|
),
|
||||||
),
|
const SizedBox(height: 15),
|
||||||
const FetchRoutineScenesAutomation(),
|
const Expanded(child: FetchRoutineScenesAutomation()),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 50),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
@ -28,32 +28,40 @@ class DialogFooter extends StatelessWidget {
|
|||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: [
|
children: [
|
||||||
_buildFooterButton(
|
DialogFooterButton(
|
||||||
context: context,
|
|
||||||
text: 'Cancel',
|
text: 'Cancel',
|
||||||
onTap: onCancel,
|
onTap: onCancel,
|
||||||
),
|
),
|
||||||
if (isConfirmEnabled) ...[
|
if (isConfirmEnabled) ...[
|
||||||
Container(width: 1, height: 50, color: ColorsManager.greyColor),
|
Container(width: 1, height: 50, color: ColorsManager.greyColor),
|
||||||
_buildFooterButton(
|
DialogFooterButton(
|
||||||
context: context,
|
|
||||||
text: 'Confirm',
|
text: 'Confirm',
|
||||||
onTap: onConfirm,
|
onTap: onConfirm,
|
||||||
textColor:
|
textColor: isConfirmEnabled
|
||||||
isConfirmEnabled ? ColorsManager.primaryColorWithOpacity : Colors.red,
|
? ColorsManager.primaryColorWithOpacity
|
||||||
|
: Colors.red,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildFooterButton({
|
class DialogFooterButton extends StatelessWidget {
|
||||||
required BuildContext context,
|
const DialogFooterButton({
|
||||||
required String text,
|
required this.text,
|
||||||
required VoidCallback? onTap,
|
required this.onTap,
|
||||||
Color? textColor,
|
this.textColor,
|
||||||
}) {
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final String text;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
final Color? textColor;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
|
|||||||
@ -16,6 +16,7 @@ class DialogHeader extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
title,
|
title,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
|||||||
@ -225,7 +225,7 @@ class DraggableCard extends StatelessWidget {
|
|||||||
if (function.functionCode == 'temp_set' || function.functionCode == 'temp_current') {
|
if (function.functionCode == 'temp_set' || function.functionCode == 'temp_current') {
|
||||||
return '${(function.value / 10).toStringAsFixed(0)}°C';
|
return '${(function.value / 10).toStringAsFixed(0)}°C';
|
||||||
} else if (function.functionCode.contains('countdown')) {
|
} else if (function.functionCode.contains('countdown')) {
|
||||||
final seconds = function.value?.toInt() ?? 0;
|
final seconds = function.value.toInt();
|
||||||
if (seconds >= 3600) {
|
if (seconds >= 3600) {
|
||||||
final hours = (seconds / 3600).floor();
|
final hours = (seconds / 3600).floor();
|
||||||
final remainingMinutes = ((seconds % 3600) / 60).floor();
|
final remainingMinutes = ((seconds % 3600) / 60).floor();
|
||||||
|
|||||||
@ -8,182 +8,211 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
|||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class FetchRoutineScenesAutomation extends StatelessWidget
|
class FetchRoutineScenesAutomation extends StatefulWidget {
|
||||||
with HelperResponsiveLayout {
|
|
||||||
const FetchRoutineScenesAutomation({super.key});
|
const FetchRoutineScenesAutomation({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FetchRoutineScenesAutomation> createState() =>
|
||||||
|
_FetchRoutineScenesState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
||||||
|
with HelperResponsiveLayout {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state.isLoading) return const Center(child: CircularProgressIndicator());
|
return state.isLoading
|
||||||
|
? const Center(
|
||||||
return SingleChildScrollView(
|
child: CircularProgressIndicator(),
|
||||||
child: Padding(
|
)
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
: SingleChildScrollView(
|
||||||
child: Column(
|
child: Padding(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
_buildListTitle(context, "Scenes (Tab to Run)"),
|
mainAxisSize: MainAxisSize.min,
|
||||||
const SizedBox(height: 10),
|
children: [
|
||||||
Visibility(
|
Text(
|
||||||
visible: state.scenes.isNotEmpty,
|
"Scenes (Tab to Run)",
|
||||||
replacement: _buildEmptyState(context, "No scenes found"),
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
child: SizedBox(
|
color: ColorsManager.grayColor,
|
||||||
height: 200,
|
fontWeight: FontWeight.bold,
|
||||||
child: _buildScenes(state),
|
),
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
_buildListTitle(context, "Automations"),
|
|
||||||
const SizedBox(height: 3),
|
|
||||||
Visibility(
|
|
||||||
visible: state.automations.isNotEmpty,
|
|
||||||
replacement: _buildEmptyState(context, "No automations found"),
|
|
||||||
child: SizedBox(
|
|
||||||
height: 200,
|
|
||||||
child: _buildAutomations(state),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildAutomations(RoutineState state) {
|
|
||||||
return ListView.builder(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: state.automations.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final isLoading = state.automations.contains(state.automations[index].id);
|
|
||||||
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
|
||||||
),
|
|
||||||
child: RoutineViewCard(
|
|
||||||
isLoading: isLoading,
|
|
||||||
onChanged: (v) {
|
|
||||||
context.read<RoutineBloc>().add(
|
|
||||||
UpdateAutomationStatus(
|
|
||||||
automationId: state.automations[index].id,
|
|
||||||
automationStatusUpdate: AutomationStatusUpdate(
|
|
||||||
spaceUuid: state.automations[index].spaceId,
|
|
||||||
isEnable: v,
|
|
||||||
),
|
|
||||||
communityId: state.automations[index].communityId,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
status: state.automations[index].status,
|
|
||||||
communityId: '',
|
|
||||||
spaceId: state.automations[index].spaceId,
|
|
||||||
sceneId: '',
|
|
||||||
automationId: state.automations[index].id,
|
|
||||||
cardType: 'automations',
|
|
||||||
spaceName: state.automations[index].spaceName,
|
|
||||||
onTap: () {
|
|
||||||
BlocProvider.of<RoutineBloc>(context).add(
|
|
||||||
const CreateNewRoutineViewEvent(
|
|
||||||
createRoutineView: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
context.read<RoutineBloc>().add(
|
|
||||||
GetAutomationDetails(
|
|
||||||
automationId: state.automations[index].id,
|
|
||||||
isAutomation: true,
|
|
||||||
isUpdate: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
textString: state.automations[index].name,
|
|
||||||
icon: state.automations[index].icon ?? Assets.automation,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildScenes(RoutineState state) {
|
|
||||||
return ListView.builder(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: state.scenes.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final scene = state.scenes[index];
|
|
||||||
final isLoading = state.loadingSceneId == scene.id;
|
|
||||||
|
|
||||||
return Padding(
|
|
||||||
padding: EdgeInsets.only(
|
|
||||||
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
RoutineViewCard(
|
|
||||||
isLoading: isLoading,
|
|
||||||
sceneOnTap: () {
|
|
||||||
context.read<RoutineBloc>().add(
|
|
||||||
SceneTrigger(
|
|
||||||
sceneId: scene.id,
|
|
||||||
name: scene.name,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
status: state.scenes[index].status,
|
|
||||||
communityId: state.scenes[index].communityId,
|
|
||||||
spaceId: state.scenes[index].spaceId,
|
|
||||||
sceneId: state.scenes[index].sceneTuyaId!,
|
|
||||||
automationId: state.scenes[index].id,
|
|
||||||
cardType: 'scenes',
|
|
||||||
spaceName: state.scenes[index].spaceName,
|
|
||||||
onTap: () {
|
|
||||||
BlocProvider.of<RoutineBloc>(context).add(
|
|
||||||
const CreateNewRoutineViewEvent(
|
|
||||||
createRoutineView: true,
|
|
||||||
),
|
),
|
||||||
);
|
const SizedBox(height: 10),
|
||||||
context.read<RoutineBloc>().add(
|
if (state.scenes.isEmpty)
|
||||||
GetSceneDetails(
|
Text(
|
||||||
sceneId: state.scenes[index].id,
|
"No scenes found",
|
||||||
isTabToRun: true,
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
isUpdate: true,
|
color: ColorsManager.grayColor,
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
if (state.scenes.isNotEmpty)
|
||||||
textString: state.scenes[index].name,
|
SizedBox(
|
||||||
icon: state.scenes[index].icon ?? Assets.logoHorizontal,
|
height: 200,
|
||||||
isFromScenes: true,
|
child: ListView.builder(
|
||||||
iconInBytes: state.scenes[index].iconInBytes,
|
shrinkWrap: true,
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: state.scenes.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final scene = state.scenes[index];
|
||||||
|
final isLoading =
|
||||||
|
state.loadingSceneId == scene.id;
|
||||||
|
|
||||||
|
return Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
right:
|
||||||
|
isSmallScreenSize(context) ? 4.0 : 8.0,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
RoutineViewCard(
|
||||||
|
isLoading: isLoading,
|
||||||
|
sceneOnTap: () {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
SceneTrigger(
|
||||||
|
sceneId: scene.id,
|
||||||
|
name: scene.name));
|
||||||
|
},
|
||||||
|
status: state.scenes[index].status,
|
||||||
|
communityId:
|
||||||
|
state.scenes[index].communityId ??
|
||||||
|
'',
|
||||||
|
spaceId: state.scenes[index].spaceId,
|
||||||
|
sceneId:
|
||||||
|
state.scenes[index].sceneTuyaId!,
|
||||||
|
automationId: state.scenes[index].id,
|
||||||
|
cardType: 'scenes',
|
||||||
|
spaceName:
|
||||||
|
state.scenes[index].spaceName,
|
||||||
|
onTap: () {
|
||||||
|
BlocProvider.of<RoutineBloc>(context)
|
||||||
|
.add(
|
||||||
|
const CreateNewRoutineViewEvent(
|
||||||
|
createRoutineView: true),
|
||||||
|
);
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
GetSceneDetails(
|
||||||
|
sceneId:
|
||||||
|
state.scenes[index].id,
|
||||||
|
isTabToRun: true,
|
||||||
|
isUpdate: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
textString: state.scenes[index].name,
|
||||||
|
icon: state.scenes[index].icon ??
|
||||||
|
Assets.logoHorizontal,
|
||||||
|
isFromScenes: true,
|
||||||
|
iconInBytes:
|
||||||
|
state.scenes[index].iconInBytes,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Text(
|
||||||
|
"Automations",
|
||||||
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 3),
|
||||||
|
if (state.automations.isEmpty)
|
||||||
|
Text(
|
||||||
|
"No automations found",
|
||||||
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: ColorsManager.grayColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (state.automations.isNotEmpty)
|
||||||
|
SizedBox(
|
||||||
|
height: 200,
|
||||||
|
|
||||||
|
child: ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: state.automations.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final isLoading = state.automations!
|
||||||
|
.contains(state.automations[index].id);
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
right: isSmallScreenSize(context)
|
||||||
|
? 4.0
|
||||||
|
: 8.0,
|
||||||
|
),
|
||||||
|
child: RoutineViewCard(
|
||||||
|
isLoading: isLoading,
|
||||||
|
onChanged: (v) {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
UpdateAutomationStatus(
|
||||||
|
automationId: state
|
||||||
|
.automations[index].id,
|
||||||
|
automationStatusUpdate:
|
||||||
|
AutomationStatusUpdate(
|
||||||
|
spaceUuid: state
|
||||||
|
.automations[
|
||||||
|
index]
|
||||||
|
.spaceId,
|
||||||
|
isEnable: v),
|
||||||
|
communityId: state
|
||||||
|
.automations[index]
|
||||||
|
.communityId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
status: state.automations[index].status,
|
||||||
|
communityId: '',
|
||||||
|
spaceId:
|
||||||
|
state.automations[index].spaceId,
|
||||||
|
sceneId: '',
|
||||||
|
automationId:
|
||||||
|
state.automations[index].id,
|
||||||
|
cardType: 'automations',
|
||||||
|
spaceName:
|
||||||
|
state.automations[index].spaceName,
|
||||||
|
onTap: () {
|
||||||
|
BlocProvider.of<RoutineBloc>(context)
|
||||||
|
.add(
|
||||||
|
const CreateNewRoutineViewEvent(
|
||||||
|
createRoutineView: true),
|
||||||
|
);
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
GetAutomationDetails(
|
||||||
|
automationId: state
|
||||||
|
.automations[index].id,
|
||||||
|
isAutomation: true,
|
||||||
|
isUpdate: true),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
textString:
|
||||||
|
state.automations[index].name,
|
||||||
|
icon: state.automations[index].icon ??
|
||||||
|
Assets.automation,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
);
|
||||||
),
|
},
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildListTitle(BuildContext context, String title) {
|
|
||||||
return Text(
|
|
||||||
title,
|
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildEmptyState(BuildContext context, String title) {
|
|
||||||
return Text(
|
|
||||||
title,
|
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
@ -67,6 +66,7 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
// Use widget.<mixinMethod> instead of just <mixinMethod>
|
||||||
final double cardWidth = widget.isSmallScreenSize(context)
|
final double cardWidth = widget.isSmallScreenSize(context)
|
||||||
? 120
|
? 120
|
||||||
: widget.isMediumScreenSize(context)
|
: widget.isMediumScreenSize(context)
|
||||||
@ -127,23 +127,22 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
|
|||||||
)
|
)
|
||||||
else
|
else
|
||||||
CupertinoSwitch(
|
CupertinoSwitch(
|
||||||
activeTrackColor: ColorsManager.primaryColor,
|
activeColor: ColorsManager.primaryColor,
|
||||||
value: widget.status == 'enable',
|
value: widget.status == 'enable',
|
||||||
onChanged: widget.onChanged,
|
onChanged: widget.onChanged,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: const SizedBox(),
|
: const SizedBox(),
|
||||||
Column(
|
InkWell(
|
||||||
children: [
|
onTap: widget.onTap,
|
||||||
Center(
|
child: Column(
|
||||||
child: InkWell(
|
children: [
|
||||||
customBorder: const CircleBorder(),
|
Center(
|
||||||
onTap: widget.onTap,
|
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: ColorsManager.graysColor,
|
color: ColorsManager.graysColor,
|
||||||
shape: BoxShape.circle,
|
borderRadius: BorderRadius.circular(120),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: ColorsManager.greyColor,
|
color: ColorsManager.greyColor,
|
||||||
width: 2.0,
|
width: 2.0,
|
||||||
@ -159,8 +158,7 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
|
|||||||
height: iconSize,
|
height: iconSize,
|
||||||
width: iconSize,
|
width: iconSize,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
errorBuilder: (context, error, stackTrace) =>
|
errorBuilder: (context, error, stackTrace) => Image.asset(
|
||||||
Image.asset(
|
|
||||||
Assets.logo,
|
Assets.logo,
|
||||||
height: iconSize,
|
height: iconSize,
|
||||||
width: iconSize,
|
width: iconSize,
|
||||||
@ -173,8 +171,7 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
|
|||||||
width: iconSize,
|
width: iconSize,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
)
|
)
|
||||||
: (widget.icon is String &&
|
: (widget.icon is String && widget.icon.endsWith('.svg'))
|
||||||
widget.icon.endsWith('.svg'))
|
|
||||||
? SvgPicture.asset(
|
? SvgPicture.asset(
|
||||||
height: iconSize,
|
height: iconSize,
|
||||||
width: iconSize,
|
width: iconSize,
|
||||||
@ -184,54 +181,51 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
|
|||||||
: Icon(
|
: Icon(
|
||||||
widget.icon,
|
widget.icon,
|
||||||
color: ColorsManager.dialogBlueTitle,
|
color: ColorsManager.dialogBlueTitle,
|
||||||
size: widget.isSmallScreenSize(context)
|
size: widget.isSmallScreenSize(context) ? 30 : 40,
|
||||||
? 30
|
|
||||||
: 40,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 8),
|
||||||
const SizedBox(height: 8),
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
child: Column(
|
||||||
child: Column(
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
widget.textString,
|
||||||
widget.textString,
|
textAlign: TextAlign.center,
|
||||||
textAlign: TextAlign.center,
|
overflow: TextOverflow.ellipsis,
|
||||||
overflow: TextOverflow.ellipsis,
|
maxLines: 1,
|
||||||
maxLines: 1,
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
color: ColorsManager.blackColor,
|
||||||
color: ColorsManager.blackColor,
|
fontSize: widget.isSmallScreenSize(context) ? 10 : 12,
|
||||||
fontSize: widget.isSmallScreenSize(context) ? 10 : 12,
|
),
|
||||||
),
|
),
|
||||||
),
|
if (widget.spaceName != '')
|
||||||
if (widget.spaceName != '')
|
Row(
|
||||||
Row(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
children: [
|
||||||
children: [
|
SvgPicture.asset(
|
||||||
SvgPicture.asset(
|
Assets.spaceLocationIcon,
|
||||||
Assets.spaceLocationIcon,
|
fit: BoxFit.contain,
|
||||||
fit: BoxFit.contain,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
widget.spaceName,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
maxLines: 1,
|
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
fontSize:
|
|
||||||
widget.isSmallScreenSize(context) ? 10 : 12,
|
|
||||||
),
|
),
|
||||||
),
|
Text(
|
||||||
],
|
widget.spaceName,
|
||||||
),
|
textAlign: TextAlign.center,
|
||||||
],
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
fontSize: widget.isSmallScreenSize(context) ? 10 : 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:flutter_svg/flutter_svg.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/all_devices/models/devices_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart';
|
import 'package:syncrow_web/pages/routines/models/ac/ac_function.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/ac/ac_operational_value.dart';
|
import 'package:syncrow_web/pages/routines/models/ac/ac_operational_value.dart';
|
||||||
@ -11,6 +9,8 @@ import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart';
|
||||||
|
|
||||||
class ACHelper {
|
class ACHelper {
|
||||||
static Future<Map<String, dynamic>?> showACFunctionsDialog({
|
static Future<Map<String, dynamic>?> showACFunctionsDialog({
|
||||||
@ -74,8 +74,10 @@ class ACHelper {
|
|||||||
child: _buildFunctionsList(
|
child: _buildFunctionsList(
|
||||||
context: context,
|
context: context,
|
||||||
acFunctions: acFunctions,
|
acFunctions: acFunctions,
|
||||||
onFunctionSelected: (functionCode, operationName) =>
|
onFunctionSelected:
|
||||||
context.read<FunctionBloc>().add(SelectFunction(
|
(functionCode, operationName) => context
|
||||||
|
.read<FunctionBloc>()
|
||||||
|
.add(SelectFunction(
|
||||||
functionCode: functionCode,
|
functionCode: functionCode,
|
||||||
operationName: operationName,
|
operationName: operationName,
|
||||||
)),
|
)),
|
||||||
@ -189,9 +191,8 @@ class ACHelper {
|
|||||||
required String operationName,
|
required String operationName,
|
||||||
bool? removeComparators,
|
bool? removeComparators,
|
||||||
}) {
|
}) {
|
||||||
final initialVal = selectedFunction == 'temp_set' ? 200 : -100;
|
|
||||||
if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') {
|
if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') {
|
||||||
final initialValue = selectedFunctionData?.value ?? initialVal;
|
final initialValue = selectedFunctionData?.value ?? 250;
|
||||||
return _buildTemperatureSelector(
|
return _buildTemperatureSelector(
|
||||||
context: context,
|
context: context,
|
||||||
initialValue: initialValue,
|
initialValue: initialValue,
|
||||||
@ -204,7 +205,8 @@ class ACHelper {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final selectedFn = acFunctions.firstWhere((f) => f.code == selectedFunction);
|
final selectedFn =
|
||||||
|
acFunctions.firstWhere((f) => f.code == selectedFunction);
|
||||||
final values = selectedFn.getOperationalValues();
|
final values = selectedFn.getOperationalValues();
|
||||||
|
|
||||||
return _buildOperationalValuesList(
|
return _buildOperationalValuesList(
|
||||||
@ -285,9 +287,7 @@ class ACHelper {
|
|||||||
functionCode: selectCode,
|
functionCode: selectCode,
|
||||||
operationName: operationName,
|
operationName: operationName,
|
||||||
condition: conditions[index],
|
condition: conditions[index],
|
||||||
value: selectedFunctionData?.value ?? selectCode == 'temp_set'
|
value: selectedFunctionData?.value,
|
||||||
? 200
|
|
||||||
: -100,
|
|
||||||
valueDescription: selectedFunctionData?.valueDescription,
|
valueDescription: selectedFunctionData?.valueDescription,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -302,7 +302,8 @@ class ACHelper {
|
|||||||
minHeight: 40.0,
|
minHeight: 40.0,
|
||||||
minWidth: 40.0,
|
minWidth: 40.0,
|
||||||
),
|
),
|
||||||
isSelected: conditions.map((c) => c == (currentCondition ?? "==")).toList(),
|
isSelected:
|
||||||
|
conditions.map((c) => c == (currentCondition ?? "==")).toList(),
|
||||||
children: conditions.map((c) => Text(c)).toList(),
|
children: conditions.map((c) => Text(c)).toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -316,7 +317,6 @@ class ACHelper {
|
|||||||
DeviceFunctionData? selectedFunctionData,
|
DeviceFunctionData? selectedFunctionData,
|
||||||
String selectCode,
|
String selectCode,
|
||||||
) {
|
) {
|
||||||
final initialVal = selectCode == 'temp_set' ? 200 : -100;
|
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -324,7 +324,7 @@ class ACHelper {
|
|||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
'${(initialValue ?? initialVal) / 10}°C',
|
'${(initialValue ?? 200) / 10}°C',
|
||||||
style: context.textTheme.headlineMedium!.copyWith(
|
style: context.textTheme.headlineMedium!.copyWith(
|
||||||
color: ColorsManager.primaryColorWithOpacity,
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
),
|
),
|
||||||
@ -397,7 +397,9 @@ class ACHelper {
|
|||||||
style: context.textTheme.bodyMedium,
|
style: context.textTheme.bodyMedium,
|
||||||
),
|
),
|
||||||
trailing: Icon(
|
trailing: Icon(
|
||||||
isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked,
|
isSelected
|
||||||
|
? Icons.radio_button_checked
|
||||||
|
: Icons.radio_button_unchecked,
|
||||||
size: 24,
|
size: 24,
|
||||||
color: isSelected
|
color: isSelected
|
||||||
? ColorsManager.primaryColorWithOpacity
|
? ColorsManager.primaryColorWithOpacity
|
||||||
@ -413,7 +415,8 @@ class ACHelper {
|
|||||||
operationName: operationName,
|
operationName: operationName,
|
||||||
value: value.value,
|
value: value.value,
|
||||||
condition: selectedFunctionData?.condition,
|
condition: selectedFunctionData?.condition,
|
||||||
valueDescription: selectedFunctionData?.valueDescription,
|
valueDescription:
|
||||||
|
selectedFunctionData?.valueDescription,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -46,7 +46,7 @@ class CpsDialogSliderSelector extends StatelessWidget {
|
|||||||
functionCode: selectedFunction,
|
functionCode: selectedFunction,
|
||||||
operationName: operationName,
|
operationName: operationName,
|
||||||
condition: condition,
|
condition: condition,
|
||||||
value: selectedFunctionData.value ?? 0,
|
value: selectedFunctionData.value,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -164,7 +164,7 @@ class OneGangSwitchHelper {
|
|||||||
required bool removeComparetors,
|
required bool removeComparetors,
|
||||||
}) {
|
}) {
|
||||||
if (selectedFunction == 'countdown_1') {
|
if (selectedFunction == 'countdown_1') {
|
||||||
final initialValue = selectedFunctionData?.value ?? 0;
|
final initialValue = selectedFunctionData?.value ?? 200;
|
||||||
return _buildCountDownSelector(
|
return _buildCountDownSelector(
|
||||||
context: context,
|
context: context,
|
||||||
initialValue: initialValue,
|
initialValue: initialValue,
|
||||||
@ -250,7 +250,7 @@ class OneGangSwitchHelper {
|
|||||||
functionCode: selectCode,
|
functionCode: selectCode,
|
||||||
operationName: operationName,
|
operationName: operationName,
|
||||||
condition: conditions[index],
|
condition: conditions[index],
|
||||||
value: selectedFunctionData?.value ?? 0,
|
value: selectedFunctionData?.value,
|
||||||
valueDescription: selectedFunctionData?.valueDescription,
|
valueDescription: selectedFunctionData?.valueDescription,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -170,7 +170,7 @@ class ThreeGangSwitchHelper {
|
|||||||
if (selectedFunction == 'countdown_1' ||
|
if (selectedFunction == 'countdown_1' ||
|
||||||
selectedFunction == 'countdown_2' ||
|
selectedFunction == 'countdown_2' ||
|
||||||
selectedFunction == 'countdown_3') {
|
selectedFunction == 'countdown_3') {
|
||||||
final initialValue = selectedFunctionData?.value ?? 0;
|
final initialValue = selectedFunctionData?.value ?? 200;
|
||||||
return _buildTemperatureSelector(
|
return _buildTemperatureSelector(
|
||||||
context: context,
|
context: context,
|
||||||
initialValue: initialValue,
|
initialValue: initialValue,
|
||||||
@ -251,7 +251,7 @@ class ThreeGangSwitchHelper {
|
|||||||
functionCode: selectCode,
|
functionCode: selectCode,
|
||||||
operationName: operationName,
|
operationName: operationName,
|
||||||
condition: conditions[index],
|
condition: conditions[index],
|
||||||
value: selectedFunctionData?.value ?? 0,
|
value: selectedFunctionData?.value,
|
||||||
valueDescription: selectedFunctionData?.valueDescription,
|
valueDescription: selectedFunctionData?.valueDescription,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -169,7 +169,7 @@ class TwoGangSwitchHelper {
|
|||||||
}) {
|
}) {
|
||||||
if (selectedFunction == 'countdown_1' ||
|
if (selectedFunction == 'countdown_1' ||
|
||||||
selectedFunction == 'countdown_2') {
|
selectedFunction == 'countdown_2') {
|
||||||
final initialValue = selectedFunctionData?.value ?? 0;
|
final initialValue = selectedFunctionData?.value ?? 200;
|
||||||
return _buildTemperatureSelector(
|
return _buildTemperatureSelector(
|
||||||
context: context,
|
context: context,
|
||||||
initialValue: initialValue,
|
initialValue: initialValue,
|
||||||
@ -250,7 +250,7 @@ class TwoGangSwitchHelper {
|
|||||||
functionCode: selectCode,
|
functionCode: selectCode,
|
||||||
operationName: operationName,
|
operationName: operationName,
|
||||||
condition: conditions[index],
|
condition: conditions[index],
|
||||||
value: selectedFunctionData?.value ?? 0,
|
value: selectedFunctionData?.value,
|
||||||
valueDescription: selectedFunctionData?.valueDescription,
|
valueDescription: selectedFunctionData?.valueDescription,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -36,7 +36,7 @@ class WpsValueSelectorWidget extends StatelessWidget {
|
|||||||
dialogType: dialogType,
|
dialogType: dialogType,
|
||||||
sliderRange: sliderRange,
|
sliderRange: sliderRange,
|
||||||
displayedValue: getDisplayText,
|
displayedValue: getDisplayText,
|
||||||
initialValue: functionData.value ?? 0.0,
|
initialValue: functionData.value ?? 250,
|
||||||
onConditionChanged: (condition) => context.read<FunctionBloc>().add(
|
onConditionChanged: (condition) => context.read<FunctionBloc>().add(
|
||||||
AddFunction(
|
AddFunction(
|
||||||
functionData: DeviceFunctionData(
|
functionData: DeviceFunctionData(
|
||||||
@ -44,7 +44,7 @@ class WpsValueSelectorWidget extends StatelessWidget {
|
|||||||
functionCode: selectedFunction,
|
functionCode: selectedFunction,
|
||||||
operationName: functionData.operationName,
|
operationName: functionData.operationName,
|
||||||
condition: condition,
|
condition: condition,
|
||||||
value: functionData.value ?? 0,
|
value: functionData.value,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -87,7 +87,7 @@ class WpsValueSelectorWidget extends StatelessWidget {
|
|||||||
final intValue = int.tryParse('${functionData.value ?? ''}');
|
final intValue = int.tryParse('${functionData.value ?? ''}');
|
||||||
return switch (functionData.functionCode) {
|
return switch (functionData.functionCode) {
|
||||||
'presence_time' => '${intValue ?? '0'}',
|
'presence_time' => '${intValue ?? '0'}',
|
||||||
'dis_current' => '${intValue ?? '0'}',
|
'dis_current' => '${intValue ?? '250'}',
|
||||||
'illuminance_value' => '${intValue ?? '0'}',
|
'illuminance_value' => '${intValue ?? '0'}',
|
||||||
_ => '$intValue',
|
_ => '$intValue',
|
||||||
};
|
};
|
||||||
|
|||||||
@ -592,6 +592,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
return CreateSubSpaceDialog(
|
return CreateSubSpaceDialog(
|
||||||
spaceName: name,
|
spaceName: name,
|
||||||
dialogTitle: isEdit ? 'Edit Sub-space' : 'Create Sub-space',
|
dialogTitle: isEdit ? 'Edit Sub-space' : 'Create Sub-space',
|
||||||
|
spaceTags: spaceTags,
|
||||||
|
isEdit: isEdit,
|
||||||
products: products,
|
products: products,
|
||||||
existingSubSpaces: existingSubSpaces,
|
existingSubSpaces: existingSubSpaces,
|
||||||
onSave: (slectedSubspaces) {
|
onSave: (slectedSubspaces) {
|
||||||
|
|||||||
@ -136,17 +136,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCommunityTile(BuildContext context, CommunityModel community) {
|
Widget _buildCommunityTile(BuildContext context, CommunityModel community) {
|
||||||
final spaces = community.spaces
|
|
||||||
.where(
|
|
||||||
(space) =>
|
|
||||||
{
|
|
||||||
SpaceStatus.deleted,
|
|
||||||
SpaceStatus.parentDeleted,
|
|
||||||
}.contains(space.status) ==
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.map((space) => _buildSpaceTile(space: space, community: community))
|
|
||||||
.toList();
|
|
||||||
return CommunityTile(
|
return CommunityTile(
|
||||||
title: community.name,
|
title: community.name,
|
||||||
key: ValueKey(community.uuid),
|
key: ValueKey(community.uuid),
|
||||||
@ -165,7 +154,15 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onExpansionChanged: (title, expanded) {},
|
onExpansionChanged: (title, expanded) {},
|
||||||
children: spaces,
|
children: community.spaces
|
||||||
|
.where(
|
||||||
|
(space) => {
|
||||||
|
SpaceStatus.deleted,
|
||||||
|
SpaceStatus.parentDeleted,
|
||||||
|
}.contains(space.status),
|
||||||
|
)
|
||||||
|
.map((space) => _buildSpaceTile(space: space, community: community))
|
||||||
|
.toList(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,204 +4,222 @@ import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
|||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace/bloc/subspace_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace/bloc/subspace_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace/bloc/subspace_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace/bloc/subspace_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace/bloc/subspace_state.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace/bloc/subspace_state.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/widgets/subspace_chip.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|
||||||
|
|
||||||
class CreateSubSpaceDialog extends StatefulWidget {
|
class CreateSubSpaceDialog extends StatelessWidget {
|
||||||
|
final bool isEdit;
|
||||||
final String dialogTitle;
|
final String dialogTitle;
|
||||||
final List<SubspaceModel>? existingSubSpaces;
|
final List<SubspaceModel>? existingSubSpaces;
|
||||||
final String? spaceName;
|
final String? spaceName;
|
||||||
|
final List<Tag>? spaceTags;
|
||||||
final List<ProductModel>? products;
|
final List<ProductModel>? products;
|
||||||
final void Function(List<SubspaceModel>?)? onSave;
|
final Function(List<SubspaceModel>?)? onSave;
|
||||||
|
|
||||||
const CreateSubSpaceDialog({
|
const CreateSubSpaceDialog(
|
||||||
required this.dialogTitle,
|
{Key? key,
|
||||||
required this.spaceName,
|
required this.isEdit,
|
||||||
required this.products,
|
required this.dialogTitle,
|
||||||
required this.onSave,
|
this.existingSubSpaces,
|
||||||
this.existingSubSpaces,
|
required this.spaceName,
|
||||||
super.key,
|
required this.spaceTags,
|
||||||
});
|
required this.products,
|
||||||
|
required this.onSave})
|
||||||
@override
|
: super(key: key);
|
||||||
State<CreateSubSpaceDialog> createState() => _CreateSubSpaceDialogState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CreateSubSpaceDialogState extends State<CreateSubSpaceDialog> {
|
|
||||||
late final TextEditingController _subspaceNameController;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
_subspaceNameController = TextEditingController();
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_subspaceNameController.dispose();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
create: (_) {
|
final textController = TextEditingController();
|
||||||
final bloc = SubSpaceBloc();
|
|
||||||
if (widget.existingSubSpaces != null) {
|
return Dialog(
|
||||||
for (final subSpace in widget.existingSubSpaces ?? []) {
|
shape: RoundedRectangleBorder(
|
||||||
bloc.add(AddSubSpace(subSpace));
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
child: BlocProvider(
|
||||||
|
create: (_) {
|
||||||
|
final bloc = SubSpaceBloc();
|
||||||
|
if (existingSubSpaces != null) {
|
||||||
|
for (var subSpace in existingSubSpaces!) {
|
||||||
|
bloc.add(AddSubSpace(subSpace));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return bloc;
|
||||||
return bloc;
|
},
|
||||||
},
|
|
||||||
child: Dialog(
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(20),
|
|
||||||
),
|
|
||||||
child: BlocBuilder<SubSpaceBloc, SubSpaceState>(
|
child: BlocBuilder<SubSpaceBloc, SubSpaceState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return Container(
|
return Container(
|
||||||
width: context.screenWidth * 0.35,
|
color: ColorsManager.whiteColors,
|
||||||
color: ColorsManager.whiteColors,
|
child: SizedBox(
|
||||||
padding: const EdgeInsets.all(16),
|
width: screenWidth * 0.35,
|
||||||
child: Column(
|
child: Padding(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
padding: const EdgeInsets.all(16.0),
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Text(
|
mainAxisSize: MainAxisSize.min,
|
||||||
widget.dialogTitle,
|
|
||||||
style: context.textTheme.headlineLarge?.copyWith(
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Container(
|
|
||||||
width: context.screenWidth * 0.35,
|
|
||||||
padding: const EdgeInsets.symmetric(
|
|
||||||
vertical: 10,
|
|
||||||
horizontal: 16,
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: ColorsManager.boxColor,
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
child: Wrap(
|
|
||||||
spacing: 8,
|
|
||||||
runSpacing: 8,
|
|
||||||
alignment: WrapAlignment.start,
|
|
||||||
crossAxisAlignment: WrapCrossAlignment.center,
|
|
||||||
children: [
|
children: [
|
||||||
...state.subSpaces.asMap().entries.map(
|
Text(
|
||||||
(entry) {
|
dialogTitle,
|
||||||
final index = entry.key;
|
style: Theme.of(context)
|
||||||
final subSpace = entry.value;
|
.textTheme
|
||||||
|
.headlineLarge
|
||||||
final lowerName = subSpace.subspaceName.toLowerCase();
|
?.copyWith(color: ColorsManager.blackColor),
|
||||||
|
|
||||||
final duplicateIndices = state.subSpaces
|
|
||||||
.asMap()
|
|
||||||
.entries
|
|
||||||
.where((e) =>
|
|
||||||
e.value.subspaceName.toLowerCase() == lowerName)
|
|
||||||
.map((e) => e.key)
|
|
||||||
.toList();
|
|
||||||
final isDuplicate = duplicateIndices.length > 1 &&
|
|
||||||
duplicateIndices.indexOf(index) != 0;
|
|
||||||
return SubspaceChip(
|
|
||||||
subSpace: SubspaceTemplateModel(
|
|
||||||
subspaceName: entry.value.subspaceName,
|
|
||||||
disabled: entry.value.disabled,
|
|
||||||
),
|
|
||||||
isDuplicate: isDuplicate,
|
|
||||||
onDeleted: () => context.read<SubSpaceBloc>().add(
|
|
||||||
RemoveSubSpace(subSpace),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
SizedBox(
|
const SizedBox(height: 16),
|
||||||
width: 200,
|
Container(
|
||||||
child: TextField(
|
width: screenWidth * 0.35,
|
||||||
controller: _subspaceNameController,
|
padding: const EdgeInsets.symmetric(
|
||||||
decoration: InputDecoration(
|
vertical: 10.0, horizontal: 16.0),
|
||||||
border: InputBorder.none,
|
decoration: BoxDecoration(
|
||||||
hintText: state.subSpaces.isEmpty
|
color: ColorsManager.boxColor,
|
||||||
? 'Please enter the name'
|
borderRadius: BorderRadius.circular(10),
|
||||||
: null,
|
),
|
||||||
hintStyle: context.textTheme.bodySmall?.copyWith(
|
child: Wrap(
|
||||||
color: ColorsManager.lightGrayColor,
|
spacing: 8.0,
|
||||||
),
|
runSpacing: 8.0,
|
||||||
),
|
children: [
|
||||||
onSubmitted: (value) {
|
...state.subSpaces.asMap().entries.map(
|
||||||
final trimmedValue = value.trim();
|
(entry) {
|
||||||
if (trimmedValue.isNotEmpty) {
|
final index = entry.key;
|
||||||
context.read<SubSpaceBloc>().add(
|
final subSpace = entry.value;
|
||||||
AddSubSpace(
|
|
||||||
SubspaceModel(
|
final lowerName =
|
||||||
subspaceName: trimmedValue,
|
subSpace.subspaceName.toLowerCase();
|
||||||
disabled: false,
|
|
||||||
|
final duplicateIndices = state.subSpaces
|
||||||
|
.asMap()
|
||||||
|
.entries
|
||||||
|
.where((e) =>
|
||||||
|
e.value.subspaceName.toLowerCase() ==
|
||||||
|
lowerName)
|
||||||
|
.map((e) => e.key)
|
||||||
|
.toList();
|
||||||
|
final isDuplicate =
|
||||||
|
duplicateIndices.length > 1 &&
|
||||||
|
duplicateIndices.indexOf(index) != 0;
|
||||||
|
|
||||||
|
return Chip(
|
||||||
|
label: Text(subSpace.subspaceName,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium
|
||||||
|
?.copyWith(
|
||||||
|
color:
|
||||||
|
ColorsManager.spaceColor)),
|
||||||
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
side: BorderSide(
|
||||||
|
color: isDuplicate
|
||||||
|
? ColorsManager.red
|
||||||
|
: ColorsManager.transparentColor,
|
||||||
|
width: 0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
deleteIcon: Container(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
border: Border.all(
|
||||||
|
color: ColorsManager.lightGrayColor,
|
||||||
|
width: 1.5,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
child: const Icon(
|
||||||
_subspaceNameController.clear();
|
Icons.close,
|
||||||
}
|
size: 16,
|
||||||
},
|
color: ColorsManager.lightGrayColor,
|
||||||
style: context.textTheme.bodyMedium,
|
),
|
||||||
|
),
|
||||||
|
onDeleted: () => context
|
||||||
|
.read<SubSpaceBloc>()
|
||||||
|
.add(RemoveSubSpace(subSpace)),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: 200,
|
||||||
|
child: TextField(
|
||||||
|
controller: textController,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
hintText: state.subSpaces.isEmpty
|
||||||
|
? 'Please enter the name'
|
||||||
|
: null,
|
||||||
|
hintStyle: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(
|
||||||
|
color: ColorsManager
|
||||||
|
.lightGrayColor)),
|
||||||
|
onSubmitted: (value) {
|
||||||
|
if (value.trim().isNotEmpty) {
|
||||||
|
context.read<SubSpaceBloc>().add(
|
||||||
|
AddSubSpace(SubspaceModel(
|
||||||
|
subspaceName: value.trim(),
|
||||||
|
disabled: false)));
|
||||||
|
textController.clear();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style:
|
||||||
|
Theme.of(context).textTheme.bodyMedium),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (state.errorMessage.isNotEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
|
child: Text(state.errorMessage,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(
|
||||||
|
color: ColorsManager.warningRed,
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: CancelButton(
|
||||||
|
label: 'Cancel',
|
||||||
|
onPressed: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: DefaultButton(
|
||||||
|
onPressed: (state.errorMessage.isNotEmpty)
|
||||||
|
? null
|
||||||
|
: () async {
|
||||||
|
final subSpaces = context
|
||||||
|
.read<SubSpaceBloc>()
|
||||||
|
.state
|
||||||
|
.subSpaces;
|
||||||
|
onSave!(subSpaces);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
backgroundColor: ColorsManager.secondaryColor,
|
||||||
|
borderRadius: 10,
|
||||||
|
foregroundColor: state.errorMessage.isNotEmpty
|
||||||
|
? ColorsManager.whiteColorsWithOpacity
|
||||||
|
: ColorsManager.whiteColors,
|
||||||
|
child: const Text('OK'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (state.errorMessage.isNotEmpty)
|
));
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(top: 8.0),
|
|
||||||
child: Text(
|
|
||||||
state.errorMessage,
|
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
|
||||||
color: ColorsManager.warningRed,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: CancelButton(
|
|
||||||
label: 'Cancel',
|
|
||||||
onPressed: () async {
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
Expanded(
|
|
||||||
child: DefaultButton(
|
|
||||||
onPressed: state.errorMessage.isEmpty
|
|
||||||
? () {
|
|
||||||
final subSpacesBloc = context.read<SubSpaceBloc>();
|
|
||||||
final subSpaces = subSpacesBloc.state.subSpaces;
|
|
||||||
widget.onSave?.call(subSpaces);
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
backgroundColor: ColorsManager.secondaryColor,
|
|
||||||
borderRadius: 10,
|
|
||||||
foregroundColor: state.errorMessage.isNotEmpty
|
|
||||||
? ColorsManager.whiteColorsWithOpacity
|
|
||||||
: ColorsManager.whiteColors,
|
|
||||||
child: const Text('OK'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,7 +1,4 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/widgets/subspace_chip.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/widgets/subspace_chip.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/widgets/subspaces_textfield.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/widgets/subspaces_textfield.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
||||||
@ -54,9 +51,6 @@ class CreateSubspaceModelChipsBox extends StatelessWidget {
|
|||||||
return SubspaceChip(
|
return SubspaceChip(
|
||||||
subSpace: subSpace,
|
subSpace: subSpace,
|
||||||
isDuplicate: isDuplicate,
|
isDuplicate: isDuplicate,
|
||||||
onDeleted: () => context.read<SubSpaceModelBloc>().add(
|
|
||||||
RemoveSubSpaceModel(subSpace),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
@ -8,12 +11,10 @@ class SubspaceChip extends StatelessWidget {
|
|||||||
required this.subSpace,
|
required this.subSpace,
|
||||||
required this.isDuplicate,
|
required this.isDuplicate,
|
||||||
super.key,
|
super.key,
|
||||||
required this.onDeleted,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final SubspaceTemplateModel subSpace;
|
final SubspaceTemplateModel subSpace;
|
||||||
final bool isDuplicate;
|
final bool isDuplicate;
|
||||||
final void Function() onDeleted;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -49,7 +50,9 @@ class SubspaceChip extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onDeleted: onDeleted,
|
onDeleted: () => context.read<SubSpaceModelBloc>().add(
|
||||||
|
RemoveSubSpaceModel(subSpace),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user