Compare commits

...
Author SHA1 Message Date
Faris Armoush 01d5cb48cc Refactor onChanged callback in Checkbox for improved readability in CustomExpansionTileSpaceTree. 2025-04-16 14:49:20 +03:00
Faris Armoush 3216d6b879 Refactor fillColor assignment in CustomExpansionTileSpaceTree for improved readability. 2025-04-16 14:47:52 +03:00
Faris Armoush 52e1ff94de Refactor onItemSelected handling in CustomExpansionTileSpaceTree for improved readability. 2025-04-16 14:47:42 +03:00
Faris Armoush 0cc867a4ea Refactor text color assignment in CustomExpansionTileSpaceTree for improved readability. 2025-04-16 14:47:19 +03:00
Faris Armoush 3de7606a00 Refactor expansion icon handling in CustomExpansionTileSpaceTree for improved readability and maintainability. 2025-04-16 14:46:37 +03:00
Faris Armoush f709b92e12 Refactor constructor formatting and improve readability in CustomExpansionTileSpaceTree. 2025-04-16 14:44:31 +03:00
Faris Armoush f1667d4458 Refactor type annotations for onExpansionChanged and onItemSelected in CustomExpansionTileSpaceTree for improved clarity. 2025-04-16 14:44:11 +03:00
Faris Armoush b4f03ab6c3 Initialize ScrollController in initState for better state management in SpaceTreeView. 2025-04-16 14:36:37 +03:00
Faris Armoush 4c38c50649 Refactor notification handling in SidebarCommunitiesList for improved readability and maintainability. 2025-04-16 14:35:29 +03:00
Faris Armoush 8b441aaf46 Refactor SidebarCommunitiesList to be a StatelessWidget and update its usage across SpaceTreeView and SidebarWidget for improved performance and maintainability. 2025-04-16 14:09:36 +03:00
Faris Armoush afdd44e098 removed comments from SpaceTreeView. 2025-04-16 13:18:52 +03:00
Faris Armoush fc1d394509 Extracted SidebarCommunitiesList into a reusable widget. 2025-04-16 13:17:09 +03:00
Faris Armoush dce44e20ec Extracted EmptyResultsWidget into its own widget and file for reusability. 2025-04-16 13:11:56 +03:00
Faris Armoush 91c4c772b5 SP-1330. 2025-04-16 13:08:38 +03:00
Abdullah Alassaf e0be44a507 Merged with dev 2025-04-16 04:00:07 +03:00
Abdullah Alassaf d4a7dd5854 Fixed design issues, added tag and location to the save dialog 2025-04-16 03:46:10 +03:00
Faris Armoush 50eb890d18 Merge pull request #142 from SyncrowIOT/SP-1278-FE-Allow-Simple-Edit-Delete
Added Ceiling Presence Sensor Device To Routine
2025-04-15 16:56:05 +03:00
Faris Armoush 9eefd522b7 bump flutter version on production github action. 2025-04-15 16:25:00 +03:00
Faris Armoush 4989a0e95c removed the use of Flexible that was causing an exception. 2025-04-15 16:24:46 +03:00
Faris Armoush 3c6b9f9ef4 Merge branch 'dev' of https://github.com/SyncrowIOT/web into dev 2025-04-15 16:12:03 +03:00
Faris Armoush 86b8771694 bump-v of web deployment action. 2025-04-15 16:12:01 +03:00
Faris Armoush ea1d3d18c8 Merge pull request #143 from SyncrowIOT/SP-1189-Rework-Add-Button-Not-clickable-Opening-Pop-up-in-Community-Screen
Sp 1189 rework add button not clickable opening pop up in community screen
2025-04-15 15:55:36 +03:00
Faris Armoush 1bfab8cc76 SP-1189-Fix tapping ok and nothing happening bug by taking the action out of the widget. 2025-04-15 14:38:06 +03:00
Faris Armoush 7dcaa20da1 Enhanced the code and look of DialogFooter buttons. 2025-04-15 13:06:30 +03:00
Faris Armoush 616adccfdd Applied the correct scenario of tapping add community icon button. 2025-04-15 12:58:20 +03:00
23 changed files with 973 additions and 772 deletions
@@ -25,7 +25,7 @@ jobs:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
flutter-version: '3.22.2' # Specify the Flutter version you want to use flutter-version: '3.27.3' # Specify the Flutter version you want to use
- name: Install dependencies - name: Install dependencies
run: flutter pub get run: flutter pub get
@@ -25,7 +25,7 @@ jobs:
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
with: with:
flutter-version: '3.22.2' # Specify the Flutter version you want to use flutter-version: '3.27.3' # Specify the Flutter version you want to use
- name: Install dependencies - name: Install dependencies
run: flutter pub get run: flutter pub get
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
class EmptySearchResultWidget extends StatelessWidget {
const EmptySearchResultWidget({
this.message = 'No results found',
super.key,
});
final String message;
@override
Widget build(BuildContext context) {
return Center(
child: Text(
message,
textAlign: TextAlign.center,
style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.lightGreyColor,
fontWeight: FontWeight.w400,
),
),
);
}
}
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
class SidebarCommunitiesList extends StatelessWidget {
const SidebarCommunitiesList({
required this.communities,
required this.itemBuilder,
required this.scrollController,
required this.onScrollToEnd,
super.key,
});
final List<CommunityModel> communities;
final Widget Function(BuildContext context, int index) itemBuilder;
final ScrollController scrollController;
final void Function() onScrollToEnd;
bool _onNotification(ScrollEndNotification notification) {
final hasReachedEnd = notification.metrics.extentAfter == 0;
if (hasReachedEnd) {
onScrollToEnd.call();
return true;
}
return false;
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(
width: context.screenWidth * 0.5,
child: Scrollbar(
scrollbarOrientation: ScrollbarOrientation.left,
thumbVisibility: true,
controller: scrollController,
child: NotificationListener<ScrollEndNotification>(
onNotification: _onNotification,
child: ListView.builder(
shrinkWrap: true,
padding: const EdgeInsetsDirectional.only(start: 16),
itemCount: communities.length,
controller: scrollController,
itemBuilder: itemBuilder,
),
),
),
),
);
}
}
@@ -239,8 +239,6 @@ SOS
// tempIcon = Assets.gang3touch; // tempIcon = Assets.gang3touch;
} else if (type == DeviceType.WaterLeak) { } else if (type == DeviceType.WaterLeak) {
tempIcon = Assets.waterLeakNormal; tempIcon = Assets.waterLeakNormal;
} else if (type == DeviceType.WaterLeak) {
tempIcon = Assets.waterLeakNormal;
} else { } else {
tempIcon = Assets.logoHorizontal; tempIcon = Assets.logoHorizontal;
} }
@@ -684,40 +684,45 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
? '${action.entityId}_automation' ? '${action.entityId}_automation'
: action.actionExecutor == 'delay' : action.actionExecutor == 'delay'
? '${action.entityId}_delay' ? '${action.entityId}_delay'
: action.entityId; : const Uuid().v4();
if (!deviceCards.containsKey(deviceId)) { // if (!deviceCards.containsKey(deviceId)) {
deviceCards[deviceId] = { deviceCards[deviceId] = {
'entityId': action.entityId, 'entityId': action.entityId,
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId, 'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
'uniqueCustomId': action.type == 'automation' || action.actionExecutor == 'delay' 'uniqueCustomId': action.type == 'automation' || action.actionExecutor == 'delay'
? const Uuid().v4() ? action.entityId
: action.entityId, : const Uuid().v4(),
'title': action.actionExecutor == 'delay' 'title': action.actionExecutor == 'delay'
? 'Delay' ? 'Delay'
: action.type == 'automation' : action.type == 'automation'
? action.name ?? 'Automation' ? action.name ?? 'Automation'
: (matchingDevice?.name ?? 'Device'), : (matchingDevice?.name ?? 'Device'),
'productType': action.productType, 'productType': action.productType,
'functions': matchingDevice?.functions, 'functions': matchingDevice?.functions,
'imagePath': action.type == 'automation' 'imagePath': action.type == 'automation'
? Assets.automation ? Assets.automation
: action.actionExecutor == 'delay' : action.actionExecutor == 'delay'
? Assets.delay ? Assets.delay
: matchingDevice?.getDefaultIcon(action.productType), : matchingDevice?.getDefaultIcon(action.productType),
'device': matchingDevice, 'device': matchingDevice,
'name': action.name, 'name': action.name,
'type': action.type, 'type': action.type,
}; 'tag': matchingDevice?.deviceTags?.isNotEmpty ?? false
} ? matchingDevice?.deviceTags![0].name ?? ''
: '',
'subSpace': matchingDevice?.deviceSubSpace?.subspaceName ?? '',
};
// }
final cardData = deviceCards[deviceId]!; final cardData = deviceCards[deviceId]!;
final uniqueCustomId = cardData['uniqueCustomId'].toString(); final uniqueCustomId = cardData['uniqueCustomId'].toString();
if (!updatedFunctions.containsKey(uniqueCustomId)) {
updatedFunctions[uniqueCustomId] = [];
}
if (action.type == 'automation') { if (action.type == 'automation') {
if (!updatedFunctions.containsKey(uniqueCustomId)) {
updatedFunctions[uniqueCustomId] = [];
}
updatedFunctions[uniqueCustomId]!.add( updatedFunctions[uniqueCustomId]!.add(
DeviceFunctionData( DeviceFunctionData(
entityId: action.entityId, entityId: action.entityId,
@@ -728,14 +733,11 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
); );
// emit(state.copyWith(automationActionExecutor: action.actionExecutor)); // emit(state.copyWith(automationActionExecutor: action.actionExecutor));
} else if (action.executorProperty != null && action.actionExecutor != 'delay') { } else if (action.executorProperty != null && action.actionExecutor != 'delay') {
// if (!updatedFunctions.containsKey(uniqueCustomId)) { final functions = matchingDevice?.functions ?? [];
// updatedFunctions[uniqueCustomId] = [];
// }
final functions = matchingDevice?.functions;
final functionCode = action.executorProperty?.functionCode; final functionCode = action.executorProperty?.functionCode;
for (DeviceFunction function in functions ?? []) { for (DeviceFunction function in functions) {
if (function.code == functionCode) { if (function.code == functionCode) {
updatedFunctions[const Uuid().v4()]!.add( updatedFunctions[uniqueCustomId]!.add(
DeviceFunctionData( DeviceFunctionData(
entityId: action.entityId, entityId: action.entityId,
functionCode: functionCode ?? '', functionCode: functionCode ?? '',
@@ -747,9 +749,6 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
} }
} }
} else if (action.actionExecutor == 'delay') { } else if (action.actionExecutor == 'delay') {
if (!updatedFunctions.containsKey(uniqueCustomId)) {
updatedFunctions[uniqueCustomId] = [];
}
final delayFunction = DelayFunction( final delayFunction = DelayFunction(
deviceId: action.entityId, deviceId: action.entityId,
deviceName: 'Delay', deviceName: 'Delay',
@@ -1156,21 +1155,25 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
), ),
); );
final deviceId = condition.entityId; final deviceId = const Uuid().v4();
if (!deviceIfCards.containsKey(deviceId)) { // if (!deviceIfCards.containsKey(deviceId)) {
deviceIfCards[deviceId] = { deviceIfCards[deviceId] = {
'entityId': condition.entityId, 'entityId': condition.entityId,
'deviceId': condition.entityId, 'deviceId': condition.entityId,
'uniqueCustomId': const Uuid().v4(), 'uniqueCustomId': const Uuid().v4(),
'title': matchingDevice.name ?? 'Device', 'title': matchingDevice.name ?? 'Device',
'productType': condition.productType, 'productType': condition.productType,
'functions': matchingDevice.functions, 'functions': matchingDevice.functions,
'imagePath': matchingDevice.getDefaultIcon(condition.productType), 'imagePath': matchingDevice.getDefaultIcon(condition.productType),
'device': matchingDevice, 'device': matchingDevice,
'type': 'condition', 'type': 'condition',
}; 'tag': matchingDevice.deviceTags?.isNotEmpty ?? false
} ? matchingDevice.deviceTags![0].name
: '',
'subSpace': matchingDevice.deviceSubSpace?.subspaceName ?? '',
};
// }
final cardData = deviceIfCards[deviceId]!; final cardData = deviceIfCards[deviceId]!;
final uniqueCustomId = cardData['uniqueCustomId'].toString(); final uniqueCustomId = cardData['uniqueCustomId'].toString();
@@ -1206,35 +1209,38 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
), ),
); );
final deviceId = final deviceId = const Uuid().v4();
action.actionExecutor == 'delay' ? '${action.entityId}_delay' : action.entityId;
if (!deviceThenCards.containsKey(deviceId)) { // if (!deviceThenCards.containsKey(deviceId)) {
deviceThenCards[deviceId] = { deviceThenCards[deviceId] = {
'entityId': action.entityId, 'entityId': action.entityId,
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId, 'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
'uniqueCustomId': const Uuid().v4(), 'uniqueCustomId': const Uuid().v4(),
'title': action.actionExecutor == 'delay' 'title': action.actionExecutor == 'delay'
? 'Delay' ? 'Delay'
: (action.type == 'scene' || action.type == 'automation') : (action.type == 'scene' || action.type == 'automation')
? action.name ? action.name
: (matchingDevice.name ?? 'Device'), : (matchingDevice.name ?? 'Device'),
'productType': action.productType, 'productType': action.productType,
'functions': matchingDevice.functions, 'functions': matchingDevice.functions,
'imagePath': action.actionExecutor == 'delay' 'imagePath': action.actionExecutor == 'delay'
? Assets.delay ? Assets.delay
: action.type == 'automation' : action.type == 'automation'
? Assets.automation ? Assets.automation
: matchingDevice.getDefaultIcon(action.productType), : matchingDevice.getDefaultIcon(action.productType),
'device': matchingDevice, 'device': matchingDevice,
'type': action.type == 'scene' 'type': action.type == 'scene'
? 'scene' ? 'scene'
: action.type == 'automation' : action.type == 'automation'
? 'automation' ? 'automation'
: 'action', : 'action',
'icon': action.icon ?? '', 'icon': action.icon ?? '',
}; 'tag': matchingDevice.deviceTags?.isNotEmpty ?? false
} ? matchingDevice.deviceTags![0].name
: '',
'subSpace': matchingDevice.deviceSubSpace?.subspaceName ?? '',
};
// }
final cardData = deviceThenCards[deviceId]!; final cardData = deviceThenCards[deviceId]!;
final uniqueCustomId = cardData['uniqueCustomId'].toString(); final uniqueCustomId = cardData['uniqueCustomId'].toString();
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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/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/widgets/dialog_header.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';
@@ -20,7 +21,7 @@ class SaveRoutineHelper {
return AlertDialog( return AlertDialog(
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
content: Container( content: Container(
width: 600, width: MediaQuery.sizeOf(context).width * 0.5,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
@@ -30,14 +31,15 @@ class SaveRoutineHelper {
children: [ children: [
DialogHeader('Create a scene: ${state.routineName ?? ""}'), DialogHeader('Create a scene: ${state.routineName ?? ""}'),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Left side - IF // Left side - IF
Expanded( Expanded(
child: Column( child: ListView(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
shrinkWrap: true,
children: [ children: [
const Text( const Text(
'IF:', 'IF:',
@@ -59,26 +61,7 @@ class SaveRoutineHelper {
...state.ifItems.map((item) { ...state.ifItems.map((item) {
final functions = final functions =
state.selectedFunctions[item['uniqueCustomId']] ?? []; state.selectedFunctions[item['uniqueCustomId']] ?? [];
return ListTile( return functionRow(item, context, functions);
leading: SvgPicture.asset(
item['imagePath'],
width: 22,
height: 22,
),
title:
Text(item['title'], style: const TextStyle(fontSize: 14)),
subtitle: Wrap(
children: functions
.map((f) => Text(
'${f.operationName}: ${f.value}, ',
style: const TextStyle(
color: ColorsManager.grayColor, fontSize: 8),
overflow: TextOverflow.ellipsis,
maxLines: 3,
))
.toList(),
),
);
}), }),
], ],
), ),
@@ -87,8 +70,9 @@ class SaveRoutineHelper {
// Right side - THEN items // Right side - THEN items
Expanded( Expanded(
child: Column( child: ListView(
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
shrinkWrap: true,
children: [ children: [
const Text( const Text(
'THEN:', 'THEN:',
@@ -100,37 +84,7 @@ class SaveRoutineHelper {
...state.thenItems.map((item) { ...state.thenItems.map((item) {
final functions = final functions =
state.selectedFunctions[item['uniqueCustomId']] ?? []; state.selectedFunctions[item['uniqueCustomId']] ?? [];
return ListTile( return functionRow(item, context, functions);
leading: item['type'] == 'tap_to_run' || item['type'] == 'scene'
? Image.memory(
base64Decode(item['icon']),
width: 22,
height: 22,
)
: SvgPicture.asset(
item['imagePath'],
width: 22,
height: 22,
),
title: Text(
item['title'],
style: context.textTheme.bodySmall?.copyWith(
fontSize: 14,
color: ColorsManager.grayColor,
),
),
subtitle: Wrap(
children: functions
.map((f) => Text(
'${f.operationName}: ${f.value}, ',
style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.grayColor, fontSize: 8),
overflow: TextOverflow.ellipsis,
maxLines: 3,
))
.toList(),
),
);
}), }),
], ],
), ),
@@ -177,4 +131,112 @@ class SaveRoutineHelper {
}, },
); );
} }
static Widget functionRow(
dynamic item, BuildContext context, List<DeviceFunctionData> functions) {
return Padding(
padding: const EdgeInsets.only(top: 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
spacing: 8,
children: [
item['type'] == 'tap_to_run' || item['type'] == 'scene'
? Image.memory(
base64Decode(item['icon']),
width: 22,
height: 22,
)
: SvgPicture.asset(
item['imagePath'],
width: 22,
height: 22,
),
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 2,
children: [
Text(
item['title'],
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: context.textTheme.bodySmall?.copyWith(
fontSize: 14,
color: ColorsManager.textPrimaryColor,
),
),
Wrap(
children: functions
.map((f) => Text(
'${f.operationName}: ${f.value}',
style: context.textTheme.bodySmall
?.copyWith(color: ColorsManager.grayColor, fontSize: 8),
overflow: TextOverflow.ellipsis,
maxLines: 3,
))
.toList(),
),
],
),
),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 2,
children: [
Visibility(
visible: item['tag'] != null && item['tag'] != '',
child: Row(
spacing: 2,
children: [
SizedBox(width: 8, height: 8, child: SvgPicture.asset(Assets.deviceTagIcon)),
Text(
item['tag'] ?? '',
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.lightGreyColor,
fontSize: 9,
fontWeight: FontWeight.w400,
),
),
],
),
),
Visibility(
visible: item['subSpace'] != null && item['subSpace'] != '',
child: Row(
spacing: 2,
children: [
SizedBox(
width: 8, height: 8, child: SvgPicture.asset(Assets.spaceLocationIcon)),
Text(
item['subSpace'] ?? '',
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.lightGreyColor,
fontSize: 9,
fontWeight: FontWeight.w400,
),
),
],
),
),
],
),
],
),
);
}
} }
+7 -8
View File
@@ -29,8 +29,7 @@ class _RoutinesViewState extends State<RoutinesView> {
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(SaveCommunityIdAndSpaceIdEvent( _bloc.add(SaveCommunityIdAndSpaceIdEvent(communityID: communityId, spaceID: spaceId));
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));
} }
@@ -49,7 +48,8 @@ class _RoutinesViewState extends State<RoutinesView> {
child: SpaceTreeView( child: SpaceTreeView(
onSelect: () => context.read<RoutineBloc>() onSelect: () => context.read<RoutineBloc>()
..add(const LoadScenes()) ..add(const LoadScenes())
..add(const LoadAutomation()), ..add(const LoadAutomation())
..add(FetchDevicesInRoutine()),
), ),
), ),
Expanded( Expanded(
@@ -64,11 +64,10 @@ class _RoutinesViewState extends State<RoutinesView> {
children: [ children: [
Text( Text(
"Create New Routines", "Create New Routines",
style: style: Theme.of(context).textTheme.titleLarge?.copyWith(
Theme.of(context).textTheme.titleLarge?.copyWith( color: ColorsManager.grayColor,
color: ColorsManager.grayColor, fontWeight: FontWeight.bold,
fontWeight: FontWeight.bold, ),
),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
RoutineViewCard( RoutineViewCard(
+30 -32
View File
@@ -8,12 +8,12 @@ class DialogFooter extends StatelessWidget {
final int? dialogWidth; final int? dialogWidth;
const DialogFooter({ const DialogFooter({
Key? key, super.key,
required this.onCancel, required this.onCancel,
required this.onConfirm, required this.onConfirm,
required this.isConfirmEnabled, required this.isConfirmEnabled,
this.dialogWidth, this.dialogWidth,
}) : super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -28,21 +28,19 @@ class DialogFooter extends StatelessWidget {
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
Expanded( _buildFooterButton(
child: _buildFooterButton( context: context,
context, text: 'Cancel',
'Cancel', onTap: onCancel,
onCancel,
),
), ),
if (isConfirmEnabled) ...[ if (isConfirmEnabled) ...[
Container(width: 1, height: 50, color: ColorsManager.greyColor), Container(width: 1, height: 50, color: ColorsManager.greyColor),
Expanded( _buildFooterButton(
child: _buildFooterButton( context: context,
context, text: 'Confirm',
'Confirm', onTap: onConfirm,
onConfirm, textColor:
), isConfirmEnabled ? ColorsManager.primaryColorWithOpacity : Colors.red,
), ),
], ],
], ],
@@ -50,24 +48,24 @@ class DialogFooter extends StatelessWidget {
); );
} }
Widget _buildFooterButton( Widget _buildFooterButton({
BuildContext context, required BuildContext context,
String text, required String text,
VoidCallback? onTap, required VoidCallback? onTap,
) { Color? textColor,
return GestureDetector( }) {
onTap: onTap, return Expanded(
child: SizedBox( child: TextButton(
height: 50, style: TextButton.styleFrom(
child: Center( foregroundColor: ColorsManager.primaryColorWithOpacity,
child: Text( disabledForegroundColor: ColorsManager.primaryColor,
text, ),
style: Theme.of(context).textTheme.bodyMedium!.copyWith( onPressed: onTap,
color: text == 'Confirm' child: Text(
? ColorsManager.primaryColorWithOpacity text,
: ColorsManager.textGray, style: Theme.of(context).textTheme.bodyMedium?.copyWith(
), color: textColor ?? ColorsManager.textGray,
), ),
), ),
), ),
); );
+12 -14
View File
@@ -69,9 +69,9 @@ class DraggableCard extends StatelessWidget {
Card( Card(
color: ColorsManager.whiteColors, color: ColorsManager.whiteColors,
child: Container( child: Container(
padding: padding ?? const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
width: 110, width: 110,
height: deviceFunctions.isEmpty ? 160 : 170, height: deviceFunctions.isEmpty ? 160 : 180,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
@@ -103,16 +103,14 @@ class DraggableCard extends StatelessWidget {
const SizedBox(height: 8), const SizedBox(height: 8),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 3), padding: const EdgeInsets.symmetric(horizontal: 3),
child: Flexible( child: Text(
child: Text( deviceData['title'] ?? deviceData['name'] ?? title,
deviceData['title'] ?? deviceData['name'] ?? title, textAlign: TextAlign.center,
textAlign: TextAlign.center, overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis, maxLines: 2,
maxLines: 2, style: context.textTheme.bodySmall?.copyWith(
style: context.textTheme.bodySmall?.copyWith( color: ColorsManager.blackColor,
color: ColorsManager.blackColor, fontSize: 12,
fontSize: 12,
),
), ),
), ),
), ),
@@ -131,7 +129,7 @@ class DraggableCard extends StatelessWidget {
deviceData['tag'] ?? '', deviceData['tag'] ?? '',
textAlign: TextAlign.center, textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 2, maxLines: 1,
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.lightGreyColor, color: ColorsManager.lightGreyColor,
fontSize: 9, fontSize: 9,
@@ -162,7 +160,7 @@ class DraggableCard extends StatelessWidget {
deviceData['subSpace'] ?? '', deviceData['subSpace'] ?? '',
textAlign: TextAlign.center, textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 2, maxLines: 1,
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.lightGreyColor, color: ColorsManager.lightGreyColor,
fontSize: 9, fontSize: 9,
+79 -90
View File
@@ -17,90 +17,87 @@ class IfContainer extends StatelessWidget {
builder: (context, state) { builder: (context, state) {
return DragTarget<Map<String, dynamic>>( return DragTarget<Map<String, dynamic>>(
builder: (context, candidateData, rejectedData) { builder: (context, candidateData, rejectedData) {
return Container( return SingleChildScrollView(
width: double.infinity, child: Container(
padding: const EdgeInsets.all(16), width: double.infinity,
child: Column( padding: const EdgeInsets.all(16),
crossAxisAlignment: CrossAxisAlignment.start, child: Column(
children: [ crossAxisAlignment: CrossAxisAlignment.start,
Row( children: [
mainAxisAlignment: MainAxisAlignment.spaceBetween, Row(
children: [ mainAxisAlignment: MainAxisAlignment.spaceBetween,
const Text('IF',
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
if (state.isAutomation && state.ifItems.isNotEmpty)
AutomationOperatorSelector(
selectedOperator: state.selectedAutomationOperator),
],
),
const SizedBox(height: 16),
if (state.isTabToRun)
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
DraggableCard( const Text('IF',
imagePath: Assets.tabToRun, style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
title: 'Tab to run', if (state.isAutomation && state.ifItems.isNotEmpty)
deviceData: {}, AutomationOperatorSelector(
), selectedOperator: state.selectedAutomationOperator),
], ],
), ),
if (!state.isTabToRun) const SizedBox(height: 16),
Wrap( if (state.isTabToRun)
spacing: 8, const Row(
runSpacing: 8, mainAxisAlignment: MainAxisAlignment.center,
children: List.generate( children: [
state.ifItems.length, DraggableCard(
(index) => GestureDetector( imagePath: Assets.tabToRun,
onTap: () async { title: 'Tab to run',
if (!state.isTabToRun) { deviceData: {},
final result = ),
await DeviceDialogHelper.showDeviceDialog( ],
context: context, ),
data: state.ifItems[index], if (!state.isTabToRun)
removeComparetors: false, Wrap(
dialogType: "IF"); spacing: 8,
runSpacing: 8,
children: List.generate(
state.ifItems.length,
(index) => GestureDetector(
onTap: () async {
if (!state.isTabToRun) {
final result = await DeviceDialogHelper.showDeviceDialog(
context: context,
data: state.ifItems[index],
removeComparetors: false,
dialogType: "IF");
if (result != null) { if (result != null) {
context.read<RoutineBloc>().add( context
AddToIfContainer( .read<RoutineBloc>()
state.ifItems[index], false)); .add(AddToIfContainer(state.ifItems[index], false));
} else if (![ } else if (![
'AC', 'AC',
'1G', '1G',
'2G', '2G',
'3G', '3G',
'WPS', 'WPS',
'GW', 'GW',
'CPS', 'CPS',
].contains( ].contains(state.ifItems[index]['productType'])) {
state.ifItems[index]['productType'])) { context
context.read<RoutineBloc>().add( .read<RoutineBloc>()
AddToIfContainer( .add(AddToIfContainer(state.ifItems[index], false));
state.ifItems[index], false)); }
} }
}
},
child: DraggableCard(
imagePath: state.ifItems[index]['imagePath'] ?? '',
title: state.ifItems[index]['title'] ?? '',
deviceData: state.ifItems[index],
padding: const EdgeInsets.symmetric(
horizontal: 4, vertical: 8),
isFromThen: false,
isFromIf: true,
onRemove: () {
context.read<RoutineBloc>().add(RemoveDragCard(
index: index,
isFromThen: false,
key: state.ifItems[index]
['uniqueCustomId']));
}, },
), child: DraggableCard(
)), imagePath: state.ifItems[index]['imagePath'] ?? '',
), title: state.ifItems[index]['title'] ?? '',
], deviceData: state.ifItems[index],
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8),
isFromThen: false,
isFromIf: true,
onRemove: () {
context.read<RoutineBloc>().add(RemoveDragCard(
index: index,
isFromThen: false,
key: state.ifItems[index]['uniqueCustomId']));
},
),
)),
),
],
),
), ),
); );
}, },
@@ -124,14 +121,10 @@ class IfContainer extends StatelessWidget {
removeComparetors: false); removeComparetors: false);
if (result != null) { if (result != null) {
context context.read<RoutineBloc>().add(AddToIfContainer(mutableData, false));
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false));
} else if (!['AC', '1G', '2G', '3G', 'WPS', 'GW', 'CPS'] } else if (!['AC', '1G', '2G', '3G', 'WPS', 'GW', 'CPS']
.contains(mutableData['productType'])) { .contains(mutableData['productType'])) {
context context.read<RoutineBloc>().add(AddToIfContainer(mutableData, false));
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false));
} }
} }
} }
@@ -177,9 +170,7 @@ class AutomationOperatorSelector extends StatelessWidget {
), ),
), ),
onPressed: () { onPressed: () {
context context.read<RoutineBloc>().add(const ChangeAutomationOperator(operator: 'or'));
.read<RoutineBloc>()
.add(const ChangeAutomationOperator(operator: 'or'));
}, },
), ),
Container( Container(
@@ -205,9 +196,7 @@ class AutomationOperatorSelector extends StatelessWidget {
), ),
), ),
onPressed: () { onPressed: () {
context context.read<RoutineBloc>().add(const ChangeAutomationOperator(operator: 'and'));
.read<RoutineBloc>()
.add(const ChangeAutomationOperator(operator: 'and'));
}, },
), ),
], ],
@@ -121,8 +121,7 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
child: SizedBox( child: SizedBox(
width: 16, width: 16,
height: 16, height: 16,
child: child: CircularProgressIndicator(strokeWidth: 2),
CircularProgressIndicator(strokeWidth: 2),
), ),
), ),
) )
@@ -159,9 +158,7 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
height: iconSize, height: iconSize,
width: iconSize, width: iconSize,
fit: BoxFit.contain, fit: BoxFit.contain,
errorBuilder: errorBuilder: (context, error, stackTrace) => Image.asset(
(context, error, stackTrace) =>
Image.asset(
Assets.logo, Assets.logo,
height: iconSize, height: iconSize,
width: iconSize, width: iconSize,
@@ -174,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,
@@ -185,9 +181,7 @@ 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,
), ),
), ),
), ),
@@ -200,11 +194,10 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
widget.textString, widget.textString,
textAlign: TextAlign.center, textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 2, maxLines: 1,
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.blackColor, color: ColorsManager.blackColor,
fontSize: fontSize: widget.isSmallScreenSize(context) ? 10 : 12,
widget.isSmallScreenSize(context) ? 10 : 12,
), ),
), ),
if (widget.spaceName != '') if (widget.spaceName != '')
@@ -220,14 +213,10 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
widget.spaceName, widget.spaceName,
textAlign: TextAlign.center, textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 2, maxLines: 1,
style: style: context.textTheme.bodySmall?.copyWith(
context.textTheme.bodySmall?.copyWith(
color: ColorsManager.blackColor, color: ColorsManager.blackColor,
fontSize: fontSize: widget.isSmallScreenSize(context) ? 10 : 12,
widget.isSmallScreenSize(context)
? 10
: 12,
), ),
), ),
], ],
+37 -42
View File
@@ -8,19 +8,20 @@ class CustomExpansionTileSpaceTree extends StatelessWidget {
final bool isSelected; final bool isSelected;
final bool isSoldCheck; final bool isSoldCheck;
final bool isExpanded; final bool isExpanded;
final Function? onExpansionChanged; final void Function()? onExpansionChanged;
final Function? onItemSelected; final void Function()? onItemSelected;
const CustomExpansionTileSpaceTree( const CustomExpansionTileSpaceTree({
{super.key, required this.isSelected,
this.spaceId, required this.title,
required this.title, this.spaceId,
this.children, this.children,
this.isExpanded = false, this.onExpansionChanged,
this.onExpansionChanged, this.onItemSelected,
this.onItemSelected, this.isExpanded = false,
required this.isSelected, this.isSoldCheck = false,
this.isSoldCheck = false}); super.key,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -30,50 +31,30 @@ class CustomExpansionTileSpaceTree extends StatelessWidget {
children: [ children: [
Checkbox( Checkbox(
value: isSoldCheck ? null : isSelected, value: isSoldCheck ? null : isSelected,
onChanged: (bool? value) { onChanged: (value) => onItemSelected ?? () {},
if (onItemSelected != null) {
onItemSelected!();
}
},
tristate: true, tristate: true,
side: WidgetStateBorderSide.resolveWith((states) { side: WidgetStateBorderSide.resolveWith(
return const BorderSide(color: ColorsManager.grayBorder); (states) => const BorderSide(color: ColorsManager.grayBorder),
}), ),
fillColor: WidgetStateProperty.resolveWith((states) { fillColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.selected)) { if (states.contains(WidgetState.selected)) {
return ColorsManager.blue1; return ColorsManager.blue1;
} else {
return ColorsManager.checkBoxFillColor;
} }
return ColorsManager.checkBoxFillColor;
}), }),
checkColor: ColorsManager.whiteColors, checkColor: ColorsManager.whiteColors,
), ),
if (children != null && children!.isNotEmpty) _buildExpansionIcon(),
InkWell(
onTap: () {
if (onExpansionChanged != null) {
onExpansionChanged!();
}
},
child: Icon(
isExpanded ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right,
color: ColorsManager.lightGrayColor,
size: 16.0,
),
),
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: onItemSelected,
if (onItemSelected != null) {
onItemSelected!();
}
},
child: Text( child: Text(
_capitalizeFirstLetter(title), _capitalizeFirstLetter(title),
style: Theme.of(context).textTheme.bodySmall!.copyWith( style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: isSelected color: isSelected
? ColorsManager.blackColor // Change color to black when selected ? ColorsManager.blackColor
: ColorsManager.lightGrayColor, // Gray when not selected : ColorsManager.lightGrayColor,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
@@ -92,6 +73,20 @@ class CustomExpansionTileSpaceTree extends StatelessWidget {
); );
} }
Widget _buildExpansionIcon() {
return Visibility(
visible: children != null && children!.isNotEmpty,
child: InkWell(
onTap: onExpansionChanged,
child: Icon(
isExpanded ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right,
color: ColorsManager.lightGrayColor,
size: 16.0,
),
),
);
}
String _capitalizeFirstLetter(String text) { String _capitalizeFirstLetter(String text) {
if (text.isEmpty) return text; if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1); return text[0].toUpperCase() + text.substring(1);
+151 -202
View File
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/common/widgets/search_bar.dart'; import 'package:syncrow_web/common/widgets/search_bar.dart';
import 'package:syncrow_web/common/widgets/sidebar_communities_list.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart'; import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart'; import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
@@ -23,7 +24,13 @@ class SpaceTreeView extends StatefulWidget {
} }
class _SpaceTreeViewState extends State<SpaceTreeView> { class _SpaceTreeViewState extends State<SpaceTreeView> {
final ScrollController _scrollController = ScrollController(); late final ScrollController _scrollController;
@override
void initState() {
_scrollController = ScrollController();
super.initState();
}
@override @override
void dispose() { void dispose() {
@@ -34,225 +41,161 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(builder: (context, state) { return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(builder: (context, state) {
List<CommunityModel> list = final communities = state.searchQuery.isNotEmpty
state.searchQuery.isNotEmpty ? state.filteredCommunity : state.communityList; ? state.filteredCommunity
: state.communityList;
return Container( return Container(
height: MediaQuery.sizeOf(context).height, height: MediaQuery.sizeOf(context).height,
decoration: widget.isSide == true decoration: widget.isSide == true
? subSectionContainerDecoration.copyWith(color: ColorsManager.whiteColors) ? subSectionContainerDecoration.copyWith(
color: ColorsManager.whiteColors)
: const BoxDecoration(color: ColorsManager.whiteColors), : const BoxDecoration(color: ColorsManager.whiteColors),
child: state is SpaceTreeLoadingState child: state is SpaceTreeLoadingState
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
: Column( : Column(
children: [ children: [
widget.isSide == true if (widget.isSide == true)
? Container( Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: ColorsManager.circleRolesBackground, color: ColorsManager.circleRolesBackground,
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
topRight: Radius.circular(20), topLeft: Radius.circular(20)), topRight: Radius.circular(20),
), topLeft: Radius.circular(20),
child: Padding( ),
padding: const EdgeInsets.all(8.0), ),
child: Row( child: Padding(
children: [ padding: const EdgeInsets.all(8.0),
Expanded( child: Row(
child: Container( children: [
decoration: BoxDecoration( Expanded(
borderRadius: const BorderRadius.all(Radius.circular(20)), child: Container(
border: Border.all(color: ColorsManager.grayBorder)), decoration: BoxDecoration(
child: TextFormField( borderRadius: const BorderRadius.all(
style: context.textTheme.bodyMedium Radius.circular(20),
?.copyWith(color: ColorsManager.blackColor), ),
onChanged: (value) { border: Border.all(
context.read<SpaceTreeBloc>().add(SearchQueryEvent(value)); color: ColorsManager.grayBorder,
}, ),
decoration: textBoxDecoration(radios: 20)!.copyWith( ),
fillColor: Colors.white, child: TextFormField(
suffixIcon: Padding( style: context.textTheme.bodyMedium?.copyWith(
padding: const EdgeInsets.only(right: 16), color: ColorsManager.blackColor,
child: SvgPicture.asset( ),
Assets.textFieldSearch, onChanged: (value) =>
width: 24, context.read<SpaceTreeBloc>().add(
height: 24, SearchQueryEvent(value),
), ),
), decoration:
hintStyle: context.textTheme.bodyMedium?.copyWith( textBoxDecoration(radios: 20)?.copyWith(
fontWeight: FontWeight.w400, fillColor: Colors.white,
fontSize: 12, suffixIcon: Padding(
color: ColorsManager.textGray), padding: const EdgeInsets.only(right: 16),
child: SvgPicture.asset(
Assets.textFieldSearch,
width: 24,
height: 24,
), ),
), ),
hintStyle:
context.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12,
color: ColorsManager.textGray,
),
), ),
), ),
], ),
), ),
), ],
)
: CustomSearchBar(
onSearchChanged: (query) {
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
},
), ),
),
)
else
CustomSearchBar(
onSearchChanged: (query) => context.read<SpaceTreeBloc>().add(
SearchQueryEvent(query),
),
),
const SizedBox(height: 16), const SizedBox(height: 16),
Expanded( Expanded(
child: state.isSearching child: state.isSearching
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
: ListView( : SidebarCommunitiesList(
shrinkWrap: true, onScrollToEnd: () => context.read<SpaceTreeBloc>().add(
scrollDirection: Axis.horizontal, PaginationEvent(
children: [ state.paginationModel,
Container( state.communityList,
width: MediaQuery.sizeOf(context).width * 0.5, ),
padding: const EdgeInsets.all(8.0), ),
child: list.isEmpty scrollController: _scrollController,
? Center( communities: communities,
child: Text( itemBuilder: (context, index) {
'No results found', return CustomExpansionTileSpaceTree(
style: Theme.of(context).textTheme.bodySmall!.copyWith( title: communities[index].name,
color: ColorsManager.lightGrayColor, isSelected: state.selectedCommunities
fontWeight: FontWeight.w400, .contains(communities[index].uuid),
), isSoldCheck: state.selectedCommunities
), .contains(communities[index].uuid),
) onExpansionChanged: () =>
: Scrollbar( context.read<SpaceTreeBloc>().add(
scrollbarOrientation: ScrollbarOrientation.left, OnCommunityExpanded(
thumbVisibility: true, communities[index].uuid,
controller: _scrollController,
child: NotificationListener(
onNotification: (notification) {
if (notification is ScrollEndNotification &&
notification.metrics.extentAfter == 0) {
// If the user has reached the end of the list Load more data
context.read<SpaceTreeBloc>().add(PaginationEvent(
state.paginationModel, state.communityList));
}
return false;
},
child: Padding(
padding: const EdgeInsets.only(left: 16),
child: ListView.builder(
shrinkWrap: true,
itemCount: list.length,
controller: _scrollController,
itemBuilder: (context, index) {
return CustomExpansionTileSpaceTree(
title: list[index].name,
isSelected: state.selectedCommunities
.contains(list[index].uuid),
isSoldCheck: state.selectedCommunities
.contains(list[index].uuid),
onExpansionChanged: () {
context.read<SpaceTreeBloc>().add(
OnCommunityExpanded(list[index].uuid));
},
isExpanded: state.expandedCommunities
.contains(list[index].uuid),
onItemSelected: () {
context.read<SpaceTreeBloc>().add(
OnCommunitySelected(list[index].uuid,
list[index].spaces));
widget.onSelect();
},
children: list[index].spaces.map((space) {
return CustomExpansionTileSpaceTree(
title: space.name,
isExpanded: state.expandedSpaces
.contains(space.uuid),
onItemSelected: () {
context.read<SpaceTreeBloc>().add(
OnSpaceSelected(
list[index],
space.uuid ?? '',
space.children));
widget.onSelect();
},
onExpansionChanged: () {
context.read<SpaceTreeBloc>().add(
OnSpaceExpanded(list[index].uuid,
space.uuid ?? ''));
},
isSelected: state.selectedSpaces
.contains(space.uuid) ||
state.soldCheck.contains(space.uuid),
isSoldCheck:
state.soldCheck.contains(space.uuid),
children: _buildNestedSpaces(
context, state, space, list[index]),
);
}).toList(),
);
}),
), ),
), ),
isExpanded: state.expandedCommunities.contains(
communities[index].uuid,
),
onItemSelected: () {
context.read<SpaceTreeBloc>().add(
OnCommunitySelected(
communities[index].uuid,
communities[index].spaces,
),
);
widget.onSelect();
},
children: communities[index].spaces.map(
(space) {
return CustomExpansionTileSpaceTree(
title: space.name,
isExpanded:
state.expandedSpaces.contains(space.uuid),
onItemSelected: () {
context.read<SpaceTreeBloc>().add(
OnSpaceSelected(
communities[index],
space.uuid ?? '',
space.children,
),
);
widget.onSelect();
},
onExpansionChanged: () =>
context.read<SpaceTreeBloc>().add(
OnSpaceExpanded(
communities[index].uuid,
space.uuid ?? '',
),
),
isSelected: state.selectedSpaces
.contains(space.uuid) ||
state.soldCheck.contains(space.uuid),
isSoldCheck:
state.soldCheck.contains(space.uuid),
children: _buildNestedSpaces(
context,
state,
space,
communities[index],
), ),
), );
], },
).toList(),
);
},
), ),
), ),
if (state.paginationIsLoading) const CircularProgressIndicator(), if (state.paginationIsLoading) const CircularProgressIndicator(),
// Expanded(
// child: Padding(
// padding: const EdgeInsets.all(8.0),
// child: list.isEmpty
// ? Center(
// child: Text(
// 'No results found',
// style: Theme.of(context).textTheme.bodySmall!.copyWith(
// color: ColorsManager.lightGrayColor, // Gray when not selected
// fontWeight: FontWeight.w400,
// ),
// ),
// )
// : ListView(
// shrinkWrap: true,
// children: list
// .map(
// (community) => CustomExpansionTileSpaceTree(
// title: community.name,
// isSelected:
// state.selectedCommunities.contains(community.uuid),
// isSoldCheck:
// state.selectedCommunities.contains(community.uuid),
// onExpansionChanged: () {
// context
// .read<SpaceTreeBloc>()
// .add(OnCommunityExpanded(community.uuid));
// },
// isExpanded:
// state.expandedCommunities.contains(community.uuid),
// onItemSelected: () {
// context.read<SpaceTreeBloc>().add(
// OnCommunitySelected(community.uuid, community.spaces));
// onSelect();
// },
// children: community.spaces.map((space) {
// return CustomExpansionTileSpaceTree(
// title: space.name,
// isExpanded: state.expandedSpaces.contains(space.uuid),
// onItemSelected: () {
// context.read<SpaceTreeBloc>().add(OnSpaceSelected(
// community.uuid, space.uuid ?? '', space.children));
// onSelect();
// },
// onExpansionChanged: () {
// context.read<SpaceTreeBloc>().add(
// OnSpaceExpanded(community.uuid, space.uuid ?? ''));
// },
// isSelected: state.selectedSpaces.contains(space.uuid) ||
// state.soldCheck.contains(space.uuid),
// isSoldCheck: state.soldCheck.contains(space.uuid),
// children: _buildNestedSpaces(
// context, state, space, community.uuid),
// );
// }).toList(),
// ),
// )
// .toList(),
// ),
// ),
// ),
], ],
), ),
); );
@@ -260,22 +203,28 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
} }
List<Widget> _buildNestedSpaces( List<Widget> _buildNestedSpaces(
BuildContext context, SpaceTreeState state, SpaceModel space, CommunityModel community) { BuildContext context,
SpaceTreeState state,
SpaceModel space,
CommunityModel community,
) {
return space.children.map((child) { return space.children.map((child) {
return CustomExpansionTileSpaceTree( return CustomExpansionTileSpaceTree(
isSelected: isSelected: state.selectedSpaces.contains(child.uuid) ||
state.selectedSpaces.contains(child.uuid) || state.soldCheck.contains(child.uuid), state.soldCheck.contains(child.uuid),
isSoldCheck: state.soldCheck.contains(child.uuid), isSoldCheck: state.soldCheck.contains(child.uuid),
title: child.name, title: child.name,
isExpanded: state.expandedSpaces.contains(child.uuid), isExpanded: state.expandedSpaces.contains(child.uuid),
onItemSelected: () { onItemSelected: () {
context context.read<SpaceTreeBloc>().add(
.read<SpaceTreeBloc>() OnSpaceSelected(community, child.uuid ?? '', child.children),
.add(OnSpaceSelected(community, child.uuid ?? '', child.children)); );
widget.onSelect(); widget.onSelect();
}, },
onExpansionChanged: () { onExpansionChanged: () {
context.read<SpaceTreeBloc>().add(OnSpaceExpanded(community.uuid, child.uuid ?? '')); context.read<SpaceTreeBloc>().add(
OnSpaceExpanded(community.uuid, child.uuid ?? ''),
);
}, },
children: _buildNestedSpaces(context, state, child, community), children: _buildNestedSpaces(context, state, child, community),
); );
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart'; import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.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/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_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/product_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
@@ -107,6 +109,11 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
selectedSpaceUuid: widget.selectedSpace?.uuid ?? selectedSpaceUuid: widget.selectedSpace?.uuid ??
widget.selectedCommunity?.uuid ?? widget.selectedCommunity?.uuid ??
'', '',
onCreateCommunity: (name, description) {
context.read<SpaceManagementBloc>().add(
CreateCommunityEvent(name, description, context),
);
},
), ),
CommunityStructureArea( CommunityStructureArea(
selectedCommunity: widget.selectedCommunity, selectedCommunity: widget.selectedCommunity,
@@ -1,19 +1,15 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
import 'package:syncrow_web/pages/spaces_management/create_community/view/create_community_dialog.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';
class SidebarAddCommunityButton extends StatelessWidget { class SidebarAddCommunityButton extends StatelessWidget {
const SidebarAddCommunityButton({ const SidebarAddCommunityButton({
required this.existingCommunityNames, required this.onTap,
super.key, super.key,
}); });
final List<String> existingCommunityNames; final void Function() onTap;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -30,22 +26,9 @@ class SidebarAddCommunityButton extends StatelessWidget {
), ),
), ),
), ),
onPressed: () => _showCreateCommunityDialog(context), onPressed: onTap,
icon: SvgPicture.asset(Assets.addIcon), icon: SvgPicture.asset(Assets.addIcon),
), ),
); );
} }
void _showCreateCommunityDialog(BuildContext context) => showDialog<void>(
context: context,
builder: (context) => CreateCommunityDialog(
isEditMode: false,
existingCommunityNames: existingCommunityNames,
onCreateCommunity: (name, description) {
context.read<SpaceManagementBloc>().add(
CreateCommunityEvent(name, description, context),
);
},
),
);
} }
@@ -5,9 +5,12 @@ import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/utils/style.dart'; import 'package:syncrow_web/utils/style.dart';
class SidebarHeader extends StatelessWidget { class SidebarHeader extends StatelessWidget {
const SidebarHeader({required this.existingCommunityNames, super.key}); const SidebarHeader({
required this.onAddCommunity,
super.key,
});
final List<String> existingCommunityNames; final void Function() onAddCommunity;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -23,7 +26,9 @@ class SidebarHeader extends StatelessWidget {
color: ColorsManager.blackColor, color: ColorsManager.blackColor,
), ),
), ),
SidebarAddCommunityButton(existingCommunityNames: existingCommunityNames), SidebarAddCommunityButton(
onTap: onAddCommunity,
),
], ],
), ),
); );
@@ -1,6 +1,8 @@
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/common/widgets/empty_search_result_widget.dart';
import 'package:syncrow_web/common/widgets/search_bar.dart'; import 'package:syncrow_web/common/widgets/search_bar.dart';
import 'package:syncrow_web/common/widgets/sidebar_communities_list.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
@@ -8,6 +10,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/community_tile.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/community_tile.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/sidebar_header.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/sidebar_header.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_tile_widget.dart';
import 'package:syncrow_web/pages/spaces_management/create_community/view/create_community_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_event.dart'; import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_event.dart';
import 'package:syncrow_web/utils/style.dart'; import 'package:syncrow_web/utils/style.dart';
@@ -15,9 +18,11 @@ import 'package:syncrow_web/utils/style.dart';
class SidebarWidget extends StatefulWidget { class SidebarWidget extends StatefulWidget {
final List<CommunityModel> communities; final List<CommunityModel> communities;
final String? selectedSpaceUuid; final String? selectedSpaceUuid;
final void Function(String name, String description) onCreateCommunity;
const SidebarWidget({ const SidebarWidget({
required this.communities, required this.communities,
required this.onCreateCommunity,
this.selectedSpaceUuid, this.selectedSpaceUuid,
super.key, super.key,
}); });
@@ -27,6 +32,8 @@ class SidebarWidget extends StatefulWidget {
} }
class _SidebarWidgetState extends State<SidebarWidget> { class _SidebarWidgetState extends State<SidebarWidget> {
late final ScrollController _scrollController;
String _searchQuery = ''; String _searchQuery = '';
String? _selectedSpaceUuid; String? _selectedSpaceUuid;
String? _selectedId; String? _selectedId;
@@ -34,9 +41,16 @@ class _SidebarWidgetState extends State<SidebarWidget> {
@override @override
void initState() { void initState() {
_selectedId = widget.selectedSpaceUuid; _selectedId = widget.selectedSpaceUuid;
_scrollController = ScrollController();
super.initState(); super.initState();
} }
@override
void dispose() {
_scrollController.dispose();
super.dispose();
}
@override @override
void didUpdateWidget(covariant SidebarWidget oldWidget) { void didUpdateWidget(covariant SidebarWidget oldWidget) {
if (widget.selectedSpaceUuid != oldWidget.selectedSpaceUuid) { if (widget.selectedSpaceUuid != oldWidget.selectedSpaceUuid) {
@@ -83,30 +97,37 @@ class _SidebarWidgetState extends State<SidebarWidget> {
return isSpaceSelected || anySubSpaceIsSelected; return isSpaceSelected || anySubSpaceIsSelected;
} }
static const _width = 300.0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final filteredCommunities = _filteredCommunities(); final filteredCommunities = _filteredCommunities();
return Container( return Container(
width: 300, width: _width,
decoration: subSectionContainerDecoration, decoration: subSectionContainerDecoration,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SidebarHeader( SidebarHeader(onAddCommunity: _onAddCommunity),
existingCommunityNames:
widget.communities.map((community) => community.name).toList(),
),
CustomSearchBar( CustomSearchBar(
onSearchChanged: (query) => setState(() => _searchQuery = query), onSearchChanged: (query) => setState(() => _searchQuery = query),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Expanded( Expanded(
child: ListView( child: Visibility(
children: filteredCommunities visible: filteredCommunities.isNotEmpty,
.map((community) => _buildCommunityTile(context, community)) replacement: const EmptySearchResultWidget(),
.toList(), child: SidebarCommunitiesList(
scrollController: _scrollController,
onScrollToEnd: () {},
communities: filteredCommunities,
itemBuilder: (context, index) => _buildCommunityTile(
context,
filteredCommunities[index],
),
),
), ),
), ),
], ],
@@ -134,11 +155,12 @@ class _SidebarWidgetState extends State<SidebarWidget> {
}, },
onExpansionChanged: (title, expanded) {}, onExpansionChanged: (title, expanded) {},
children: community.spaces children: community.spaces
.where((space) { .where(
final isDeleted = space.status != SpaceStatus.deleted; (space) => {
final isParentDeleted = space.status != SpaceStatus.parentDeleted; SpaceStatus.deleted,
return (isDeleted || isParentDeleted); SpaceStatus.parentDeleted,
}) }.contains(space.status),
)
.map((space) => _buildSpaceTile(space: space, community: community)) .map((space) => _buildSpaceTile(space: space, community: community))
.toList(), .toList(),
); );
@@ -179,4 +201,26 @@ class _SidebarWidgetState extends State<SidebarWidget> {
), ),
); );
} }
void _onAddCommunity() => _selectedId?.isNotEmpty ?? true
? _clearSelection()
: _showCreateCommunityDialog();
void _clearSelection() {
setState(() => _selectedId = '');
context.read<SpaceManagementBloc>().add(
NewCommunityEvent(communities: widget.communities),
);
}
void _showCreateCommunityDialog() {
showDialog<void>(
context: context,
builder: (context) => CreateCommunityDialog(
isEditMode: false,
existingCommunityNames: widget.communities.map((e) => e.name).toList(),
onCreateCommunity: widget.onCreateCommunity,
),
);
}
} }
@@ -1,12 +1,13 @@
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/common/buttons/cancel_button.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.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_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/bloc/subspace_model_event.dart';
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_state.dart'; import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_state.dart';
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/widgets/create_subspace_model_chips_box.dart';
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/widgets/create_subspace_model_footer_buttons.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';
class CreateSubSpaceModelDialog extends StatelessWidget { class CreateSubSpaceModelDialog extends StatelessWidget {
final bool isEdit; final bool isEdit;
@@ -14,211 +15,67 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
final List<SubspaceTemplateModel>? existingSubSpaces; final List<SubspaceTemplateModel>? existingSubSpaces;
final void Function(List<SubspaceTemplateModel> newSubspaces)? onUpdate; final void Function(List<SubspaceTemplateModel> newSubspaces)? onUpdate;
const CreateSubSpaceModelDialog( const CreateSubSpaceModelDialog({
{Key? key, required this.isEdit,
required this.isEdit, required this.dialogTitle,
required this.dialogTitle, this.existingSubSpaces,
this.existingSubSpaces, this.onUpdate,
this.onUpdate}) super.key,
: super(key: key); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width; final screenWidth = MediaQuery.of(context).size.width;
final textController = TextEditingController();
return Dialog( return Dialog(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
), ),
child: BlocProvider( child: BlocProvider(
create: (_) { create: (context) {
final bloc = SubSpaceModelBloc(); final bloc = SubSpaceModelBloc();
if (existingSubSpaces != null) { if (existingSubSpaces != null) {
for (var subSpace in existingSubSpaces!) { for (final subSpace in existingSubSpaces ?? []) {
bloc.add(AddSubSpaceModel(subSpace)); bloc.add(AddSubSpaceModel(subSpace));
} }
} }
return bloc; return bloc;
}, },
child: BlocBuilder<SubSpaceModelBloc, SubSpaceModelState>( child: BlocBuilder<SubSpaceModelBloc, SubSpaceModelState>(
builder: (context, state) { builder: (context, state) => Container(
return Container( color: ColorsManager.whiteColors,
color: ColorsManager.whiteColors, width: screenWidth * 0.3,
child: SizedBox( padding: const EdgeInsets.all(16),
width: screenWidth * 0.3, 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, dialogTitle,
children: [ style: context.textTheme.headlineLarge?.copyWith(
Text( color: ColorsManager.blackColor,
dialogTitle, ),
style: Theme.of(context) ),
.textTheme const SizedBox(height: 16),
.headlineLarge CreateSubspaceModelChipsBox(subSpaces: state.subSpaces),
?.copyWith(color: ColorsManager.blackColor), if (state.errorMessage.isNotEmpty)
), Padding(
const SizedBox(height: 16), padding: const EdgeInsets.only(bottom: 16),
Container( child: Text(
width: screenWidth * 0.35, state.errorMessage,
padding: const EdgeInsets.symmetric( style: context.textTheme.bodySmall?.copyWith(
vertical: 10.0, horizontal: 16.0), color: ColorsManager.red,
decoration: BoxDecoration( ),
color: ColorsManager.boxColor,
borderRadius: BorderRadius.circular(10),
),
child: Wrap(
spacing: 8.0,
runSpacing: 8.0,
children: [
...state.subSpaces.asMap().entries.map(
(entry) {
final index = entry.key;
final subSpace = entry.value;
final lowerName =
subSpace.subspaceName.toLowerCase();
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
.bodySmall
?.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(
Icons.close,
size: 16,
color: ColorsManager.lightGrayColor,
),
),
onDeleted: () => context
.read<SubSpaceModelBloc>()
.add(RemoveSubSpaceModel(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<SubSpaceModelBloc>().add(
AddSubSpaceModel(
SubspaceTemplateModel(
subspaceName: value.trim(),
disabled: false)));
textController.clear();
}
},
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(
color: ColorsManager.blackColor)),
),
],
),
),
if (state.errorMessage.isNotEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: Text(state.errorMessage,
style: Theme.of(context)
.textTheme
.bodySmall
?.copyWith(
color: ColorsManager.red,
)),
),
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<SubSpaceModelBloc>()
.state
.subSpaces;
Navigator.of(context).pop();
if (onUpdate != null) {
onUpdate!(subSpaces);
}
},
backgroundColor: ColorsManager.secondaryColor,
borderRadius: 10,
foregroundColor: state.errorMessage.isNotEmpty
? ColorsManager.whiteColorsWithOpacity
: ColorsManager.whiteColors,
child: const Text('OK'),
),
),
],
),
],
), ),
), ),
)); const SizedBox(height: 16),
}, CreateSubspaceModelFooterButtons(
onUpdate: onUpdate,
errorMessage: state.errorMessage,
),
],
),
),
), ),
), ),
); );
@@ -0,0 +1,64 @@
import 'package:flutter/material.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/space_model/models/subspace_template_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class CreateSubspaceModelChipsBox extends StatelessWidget {
const CreateSubspaceModelChipsBox({
required this.subSpaces,
super.key,
});
final List<SubspaceTemplateModel> subSpaces;
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
return Container(
width: 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: [
...subSpaces.asMap().entries.map(
(entry) {
final index = entry.key;
final subSpace = entry.value;
final lowerName = subSpace.subspaceName.toLowerCase();
final duplicateIndices = 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: subSpace,
isDuplicate: isDuplicate,
);
},
),
SubspacesTextfield(
hintText: subSpaces.isEmpty ? 'Please enter the name' : null,
),
],
),
);
}
}
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
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/spaces_management/create_subspace_model/bloc/subspace_model_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class CreateSubspaceModelFooterButtons extends StatelessWidget {
const CreateSubspaceModelFooterButtons({
required this.onUpdate,
required this.errorMessage,
super.key,
});
final void Function(List<SubspaceTemplateModel> newSubspaces)? onUpdate;
final String errorMessage;
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: CancelButton(
label: 'Cancel',
onPressed: () => Navigator.of(context).pop(),
),
),
const SizedBox(width: 10),
Expanded(
child: DefaultButton(
onPressed: errorMessage.isEmpty
? () {
Navigator.of(context).pop();
if (onUpdate != null) {
final subSpaces =
context.read<SubSpaceModelBloc>().state.subSpaces;
onUpdate!(subSpaces);
}
}
: null,
backgroundColor: ColorsManager.secondaryColor,
borderRadius: 10,
foregroundColor: errorMessage.isNotEmpty
? ColorsManager.whiteColorsWithOpacity
: ColorsManager.whiteColors,
child: const Text('OK'),
),
),
],
);
}
}
@@ -0,0 +1,58 @@
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/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
class SubspaceChip extends StatelessWidget {
const SubspaceChip({
required this.subSpace,
required this.isDuplicate,
super.key,
});
final SubspaceTemplateModel subSpace;
final bool isDuplicate;
@override
Widget build(BuildContext context) {
return Chip(
label: Text(
subSpace.subspaceName,
style: context.textTheme.bodySmall?.copyWith(
color: isDuplicate ? ColorsManager.red : ColorsManager.spaceColor,
),
),
backgroundColor: ColorsManager.whiteColors,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: BorderSide(
color: isDuplicate ? ColorsManager.red : ColorsManager.transparentColor,
width: 0,
),
),
deleteIcon: Container(
padding: const EdgeInsetsDirectional.all(1),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: ColorsManager.lightGrayColor,
width: 1.5,
),
),
child: const FittedBox(
fit: BoxFit.scaleDown,
child: Icon(
Icons.close,
color: ColorsManager.lightGrayColor,
),
),
),
onDeleted: () => context.read<SubSpaceModelBloc>().add(
RemoveSubSpaceModel(subSpace),
),
);
}
}
@@ -0,0 +1,68 @@
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/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
class SubspacesTextfield extends StatefulWidget {
const SubspacesTextfield({
required this.hintText,
super.key,
});
final String? hintText;
@override
State<SubspacesTextfield> createState() => _SubspacesTextfieldState();
}
class _SubspacesTextfieldState extends State<SubspacesTextfield> {
late final TextEditingController _controller;
@override
void initState() {
_controller = TextEditingController();
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return SizedBox(
width: 100,
child: TextField(
controller: _controller,
decoration: InputDecoration(
border: InputBorder.none,
hintText: widget.hintText,
hintStyle: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.lightGrayColor,
),
),
onSubmitted: (value) {
final trimmedValue = value.trim();
if (trimmedValue.isNotEmpty) {
context.read<SubSpaceModelBloc>().add(
AddSubSpaceModel(
SubspaceTemplateModel(
subspaceName: trimmedValue,
disabled: false,
),
),
);
_controller.clear();
}
},
style: context.textTheme.bodyMedium?.copyWith(
color: ColorsManager.blackColor,
),
),
);
}
}