Compare commits

..

8 Commits

20 changed files with 758 additions and 624 deletions

View File

@ -10,7 +10,6 @@ import 'package:syncrow_web/pages/auth/model/region_model.dart';
import 'package:syncrow_web/pages/auth/model/token.dart'; import 'package:syncrow_web/pages/auth/model/token.dart';
import 'package:syncrow_web/pages/auth/model/user_model.dart'; import 'package:syncrow_web/pages/auth/model/user_model.dart';
import 'package:syncrow_web/pages/common/bloc/project_manager.dart'; import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/home/bloc/home_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/bloc/space_tree_event.dart'; import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
import 'package:syncrow_web/services/auth_api.dart'; import 'package:syncrow_web/services/auth_api.dart';
@ -433,13 +432,9 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
} }
static Future<void> logout(BuildContext context) async { static Future<void> logout(BuildContext context) async {
const storage = FlutterSecureStorage(); final storage = FlutterSecureStorage();
ProjectManager.clearProjectUUID();
context.read<SpaceTreeBloc>().add(ClearAllData()); context.read<SpaceTreeBloc>().add(ClearAllData());
user = null; storage.deleteAll();
context.read<HomeBloc>().user = null;
await Future.wait<void>([
ProjectManager.clearProjectUUID(),
storage.deleteAll(),
]);
} }
} }

View File

@ -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,

View File

@ -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,25 +33,128 @@ 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 ?? ""}',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.headlineMedium!.copyWith(
color: ColorsManager.primaryColorWithOpacity,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 18),
_buildDivider(),
_buildListsLabelRow(selectedConditionLabel),
Expanded(
child: Padding(
padding: const EdgeInsetsDirectional.symmetric(
horizontal: 16,
),
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
spacing: 24,
children: [ children: [
// Left side - IF _buildIfConditions(state, context),
Expanded( Container(
child: ListView( width: 1,
// crossAxisAlignment: CrossAxisAlignment.start, color: ColorsManager.greyColor.withValues(alpha: 0.8),
shrinkWrap: true, ),
children: [ _buildThenActions(state, context),
const Text( ],
'IF:',
style: TextStyle(
fontSize: 16,
), ),
), ),
),
_buildDivider(),
const SizedBox(height: 8), const SizedBox(height: 8),
_buildDialogFooter(context, state),
const SizedBox(height: 8),
],
),
),
);
},
);
},
);
}
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) if (state.isTabToRun)
ListTile( ListTile(
leading: SvgPicture.asset( leading: SvgPicture.asset(
@ -65,75 +172,14 @@ class SaveRoutineHelper {
}), }),
], ],
), ),
),
const SizedBox(width: 16),
// Right side - THEN items
Expanded(
child: ListView(
// crossAxisAlignment: CrossAxisAlignment.start,
shrinkWrap: true,
children: [
const Text(
'THEN:',
style: TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 8),
...state.thenItems.map((item) {
final functions =
state.selectedFunctions[item['uniqueCustomId']] ?? [];
return functionRow(item, context, functions);
}),
],
),
),
],
),
),
// if (state.errorMessage != null || state.errorMessage!.isNotEmpty)
// Padding(
// padding: const EdgeInsets.all(8.0),
// child: Text(
// 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,
),
],
),
),
);
},
);
},
); );
} }
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,18 +188,35 @@ 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(
base64Decode(item['icon']),
width: 22, width: 22,
height: 22, height: 22,
padding: const EdgeInsetsDirectional.all(4),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: ColorsManager.textFieldGreyColor,
border: Border.all(
color: ColorsManager.neutralGray,
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( : SvgPicture.asset(
item['imagePath'], item['imagePath'],
width: 22, width: 12,
height: 22, height: 12,
fit: BoxFit.scaleDown,
),
),
), ),
Flexible( Flexible(
child: Column( child: Column(
@ -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(
color: ColorsManager.grayColor,
fontSize: 8,
),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
maxLines: 3, 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,

View File

@ -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,15 +54,13 @@ 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,
spacing: 16,
children: [ children: [
Text( Text(
"Create New Routines", "Create New Routines",
@ -73,6 +69,7 @@ class _RoutinesViewState extends State<RoutinesView> {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
const SizedBox(height: 10),
RoutineViewCard( RoutineViewCard(
isLoading: false, isLoading: false,
onChanged: (v) {}, onChanged: (v) {},
@ -87,10 +84,13 @@ class _RoutinesViewState extends State<RoutinesView> {
icon: Icons.add, icon: Icons.add,
textString: '', textString: '',
), ),
const FetchRoutineScenesAutomation(), const SizedBox(height: 15),
const Expanded(child: FetchRoutineScenesAutomation()),
], ],
), ),
), ),
const SizedBox(height: 50),
],
), ),
) )
], ],

View File

@ -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(

View File

@ -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,

View File

@ -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();

View File

@ -8,121 +8,67 @@ 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(),
)
: SingleChildScrollView(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0), padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
_buildListTitle(context, "Scenes (Tab to Run)"), Text(
const SizedBox(height: 10), "Scenes (Tab to Run)",
Visibility( style: Theme.of(context).textTheme.titleLarge?.copyWith(
visible: state.scenes.isNotEmpty, color: ColorsManager.grayColor,
replacement: _buildEmptyState(context, "No scenes found"), fontWeight: FontWeight.bold,
child: SizedBox(
height: 200,
child: _buildScenes(state),
), ),
), ),
const SizedBox(height: 10), const SizedBox(height: 10),
_buildListTitle(context, "Automations"), if (state.scenes.isEmpty)
const SizedBox(height: 3), Text(
Visibility( "No scenes found",
visible: state.automations.isNotEmpty, style: context.textTheme.bodyMedium?.copyWith(
replacement: _buildEmptyState(context, "No automations found"), color: ColorsManager.grayColor,
child: SizedBox( ),
),
if (state.scenes.isNotEmpty)
SizedBox(
height: 200, height: 200,
child: _buildAutomations(state), child: ListView.builder(
), shrinkWrap: true,
)
],
),
),
);
},
);
}
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, scrollDirection: Axis.horizontal,
itemCount: state.scenes.length, itemCount: state.scenes.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final scene = state.scenes[index]; final scene = state.scenes[index];
final isLoading = state.loadingSceneId == scene.id; final isLoading =
state.loadingSceneId == scene.id;
return Padding( return Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(
right: isSmallScreenSize(context) ? 4.0 : 8.0, right:
isSmallScreenSize(context) ? 4.0 : 8.0,
), ),
child: Column( child: Column(
children: [ children: [
@ -132,58 +78,141 @@ class FetchRoutineScenesAutomation extends StatelessWidget
context.read<RoutineBloc>().add( context.read<RoutineBloc>().add(
SceneTrigger( SceneTrigger(
sceneId: scene.id, sceneId: scene.id,
name: scene.name, name: scene.name));
),
);
}, },
status: state.scenes[index].status, status: state.scenes[index].status,
communityId: state.scenes[index].communityId, communityId:
state.scenes[index].communityId ??
'',
spaceId: state.scenes[index].spaceId, spaceId: state.scenes[index].spaceId,
sceneId: state.scenes[index].sceneTuyaId!, sceneId:
state.scenes[index].sceneTuyaId!,
automationId: state.scenes[index].id, automationId: state.scenes[index].id,
cardType: 'scenes', cardType: 'scenes',
spaceName: state.scenes[index].spaceName, spaceName:
state.scenes[index].spaceName,
onTap: () { onTap: () {
BlocProvider.of<RoutineBloc>(context).add( BlocProvider.of<RoutineBloc>(context)
.add(
const CreateNewRoutineViewEvent( const CreateNewRoutineViewEvent(
createRoutineView: true, createRoutineView: true),
),
); );
context.read<RoutineBloc>().add( context.read<RoutineBloc>().add(
GetSceneDetails( GetSceneDetails(
sceneId: state.scenes[index].id, sceneId:
state.scenes[index].id,
isTabToRun: true, isTabToRun: true,
isUpdate: true, isUpdate: true,
), ),
); );
}, },
textString: state.scenes[index].name, textString: state.scenes[index].name,
icon: state.scenes[index].icon ?? Assets.logoHorizontal, icon: state.scenes[index].icon ??
Assets.logoHorizontal,
isFromScenes: true, isFromScenes: true,
iconInBytes: state.scenes[index].iconInBytes, iconInBytes:
state.scenes[index].iconInBytes,
), ),
], ],
), ),
); );
}); }),
} ),
const SizedBox(height: 10),
Widget _buildListTitle(BuildContext context, String title) { Text(
return Text( "Automations",
title,
style: Theme.of(context).textTheme.titleLarge?.copyWith( style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: ColorsManager.grayColor, color: ColorsManager.grayColor,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
); ),
} const SizedBox(height: 3),
if (state.automations.isEmpty)
Widget _buildEmptyState(BuildContext context, String title) { Text(
return Text( "No automations found",
title,
style: context.textTheme.bodyMedium?.copyWith( style: context.textTheme.bodyMedium?.copyWith(
color: ColorsManager.grayColor, 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,
),
),
],
);
}),
),
],
),
),
);
},
); );
} }
} }

View File

@ -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(
onTap: widget.onTap,
child: Column(
children: [ children: [
Center( Center(
child: InkWell(
customBorder: const CircleBorder(),
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,10 +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,
),
), ),
), ),
), ),
@ -222,8 +216,7 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
maxLines: 1, 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,
), ),
), ),
], ],
@ -233,6 +226,7 @@ class _RoutineViewCardState extends State<RoutineViewCard> {
), ),
], ],
), ),
),
], ],
), ),
), ),

View File

@ -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,
), ),
), ),
); );

View File

@ -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,
), ),
), ),
), ),

View File

@ -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,
), ),
), ),

View File

@ -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,
), ),
), ),

View File

@ -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,
), ),
), ),

View File

@ -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',
}; };

View File

@ -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) {

View File

@ -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(),
); );
} }

View File

@ -4,155 +4,169 @@ 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(
{Key? key,
required this.isEdit,
required this.dialogTitle, required this.dialogTitle,
required this.spaceName,
required this.products,
required this.onSave,
this.existingSubSpaces, this.existingSubSpaces,
super.key, required this.spaceName,
}); required this.spaceTags,
required this.products,
@override required this.onSave})
State<CreateSubSpaceDialog> createState() => _CreateSubSpaceDialogState(); : super(key: key);
}
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;
final textController = TextEditingController();
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: BlocProvider(
create: (_) { create: (_) {
final bloc = SubSpaceBloc(); final bloc = SubSpaceBloc();
if (widget.existingSubSpaces != null) { if (existingSubSpaces != null) {
for (final subSpace in widget.existingSubSpaces ?? []) { for (var subSpace in existingSubSpaces!) {
bloc.add(AddSubSpace(subSpace)); 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,
padding: const EdgeInsets.all(16), child: SizedBox(
width: screenWidth * 0.35,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( Text(
widget.dialogTitle, dialogTitle,
style: context.textTheme.headlineLarge?.copyWith( style: Theme.of(context)
color: ColorsManager.blackColor, .textTheme
), .headlineLarge
?.copyWith(color: ColorsManager.blackColor),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Container( Container(
width: context.screenWidth * 0.35, width: screenWidth * 0.35,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 10, vertical: 10.0, horizontal: 16.0),
horizontal: 16,
),
decoration: BoxDecoration( decoration: BoxDecoration(
color: ColorsManager.boxColor, color: ColorsManager.boxColor,
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
), ),
child: Wrap( child: Wrap(
spacing: 8, spacing: 8.0,
runSpacing: 8, runSpacing: 8.0,
alignment: WrapAlignment.start,
crossAxisAlignment: WrapCrossAlignment.center,
children: [ children: [
...state.subSpaces.asMap().entries.map( ...state.subSpaces.asMap().entries.map(
(entry) { (entry) {
final index = entry.key; final index = entry.key;
final subSpace = entry.value; final subSpace = entry.value;
final lowerName = subSpace.subspaceName.toLowerCase(); final lowerName =
subSpace.subspaceName.toLowerCase();
final duplicateIndices = state.subSpaces final duplicateIndices = state.subSpaces
.asMap() .asMap()
.entries .entries
.where((e) => .where((e) =>
e.value.subspaceName.toLowerCase() == lowerName) e.value.subspaceName.toLowerCase() ==
lowerName)
.map((e) => e.key) .map((e) => e.key)
.toList(); .toList();
final isDuplicate = duplicateIndices.length > 1 && final isDuplicate =
duplicateIndices.length > 1 &&
duplicateIndices.indexOf(index) != 0; duplicateIndices.indexOf(index) != 0;
return SubspaceChip(
subSpace: SubspaceTemplateModel( return Chip(
subspaceName: entry.value.subspaceName, label: Text(subSpace.subspaceName,
disabled: entry.value.disabled, 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,
), ),
isDuplicate: isDuplicate,
onDeleted: () => context.read<SubSpaceBloc>().add(
RemoveSubSpace(subSpace),
), ),
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<SubSpaceBloc>()
.add(RemoveSubSpace(subSpace)),
); );
}, },
), ),
SizedBox( SizedBox(
width: 200, width: 200,
child: TextField( child: TextField(
controller: _subspaceNameController, controller: textController,
decoration: InputDecoration( decoration: InputDecoration(
border: InputBorder.none, border: InputBorder.none,
hintText: state.subSpaces.isEmpty hintText: state.subSpaces.isEmpty
? 'Please enter the name' ? 'Please enter the name'
: null, : null,
hintStyle: context.textTheme.bodySmall?.copyWith( hintStyle: Theme.of(context)
color: ColorsManager.lightGrayColor, .textTheme
), .bodySmall
), ?.copyWith(
color: ColorsManager
.lightGrayColor)),
onSubmitted: (value) { onSubmitted: (value) {
final trimmedValue = value.trim(); if (value.trim().isNotEmpty) {
if (trimmedValue.isNotEmpty) {
context.read<SubSpaceBloc>().add( context.read<SubSpaceBloc>().add(
AddSubSpace( AddSubSpace(SubspaceModel(
SubspaceModel( subspaceName: value.trim(),
subspaceName: trimmedValue, disabled: false)));
disabled: false, textController.clear();
),
),
);
_subspaceNameController.clear();
} }
}, },
style: context.textTheme.bodyMedium, style:
), Theme.of(context).textTheme.bodyMedium),
), ),
], ],
), ),
@ -160,12 +174,13 @@ class _CreateSubSpaceDialogState extends State<CreateSubSpaceDialog> {
if (state.errorMessage.isNotEmpty) if (state.errorMessage.isNotEmpty)
Padding( Padding(
padding: const EdgeInsets.only(top: 8.0), padding: const EdgeInsets.only(top: 8.0),
child: Text( child: Text(state.errorMessage,
state.errorMessage, style: Theme.of(context)
style: context.textTheme.bodySmall?.copyWith( .textTheme
.bodySmall
?.copyWith(
color: ColorsManager.warningRed, color: ColorsManager.warningRed,
), )),
),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
Row( Row(
@ -181,14 +196,16 @@ class _CreateSubSpaceDialogState extends State<CreateSubSpaceDialog> {
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded( Expanded(
child: DefaultButton( child: DefaultButton(
onPressed: state.errorMessage.isEmpty onPressed: (state.errorMessage.isNotEmpty)
? () { ? null
final subSpacesBloc = context.read<SubSpaceBloc>(); : () async {
final subSpaces = subSpacesBloc.state.subSpaces; final subSpaces = context
widget.onSave?.call(subSpaces); .read<SubSpaceBloc>()
.state
.subSpaces;
onSave!(subSpaces);
Navigator.of(context).pop(); Navigator.of(context).pop();
} },
: null,
backgroundColor: ColorsManager.secondaryColor, backgroundColor: ColorsManager.secondaryColor,
borderRadius: 10, borderRadius: 10,
foregroundColor: state.errorMessage.isNotEmpty foregroundColor: state.errorMessage.isNotEmpty
@ -201,7 +218,8 @@ class _CreateSubSpaceDialogState extends State<CreateSubSpaceDialog> {
), ),
], ],
), ),
); ),
));
}, },
), ),
), ),

View File

@ -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),
),
); );
}, },
), ),

View File

@ -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),
),
); );
} }
} }