From 8af24e575c336564781a4255fe522d70d6f8fcc0 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sat, 8 Mar 2025 09:57:35 +0300 Subject: [PATCH 1/3] fix model and SpaceModelCardWidget and LinkSpaceModelSpacesDialog --- .../models/space_template_model.dart | 11 +- .../link_space_model_spaces_dialog.dart | 34 ++- .../widgets/space_model_card_widget.dart | 236 +++++++----------- 3 files changed, 133 insertions(+), 148 deletions(-) diff --git a/lib/pages/spaces_management/space_model/models/space_template_model.dart b/lib/pages/spaces_management/space_model/models/space_template_model.dart index 3323fe6e..f07853c5 100644 --- a/lib/pages/spaces_management/space_model/models/space_template_model.dart +++ b/lib/pages/spaces_management/space_model/models/space_template_model.dart @@ -11,7 +11,7 @@ class SpaceTemplateModel extends Equatable { List? subspaceModels; final List? tags; String internalId; - String? createdAt; + DateTime? createdAt; @override List get props => [modelName, subspaceModels, tags]; @@ -24,23 +24,24 @@ class SpaceTemplateModel extends Equatable { this.tags, this.createdAt, }) : internalId = internalId ?? const Uuid().v4(); - factory SpaceTemplateModel.fromJson(Map json) { final String internalId = json['internalId'] ?? const Uuid().v4(); return SpaceTemplateModel( uuid: json['uuid'] ?? '', - createdAt: json['createdAt'] ?? '', + createdAt: json['createdAt'] != null + ? DateTime.tryParse(json['createdAt']) + : null, internalId: internalId, modelName: json['modelName'] ?? '', subspaceModels: (json['subspaceModels'] as List?) - ?.where((e) => e is Map) // Validate type + ?.where((e) => e is Map) .map((e) => SubspaceTemplateModel.fromJson(e as Map)) .toList() ?? [], tags: (json['tags'] as List?) - ?.where((item) => item is Map) // Validate type + ?.where((item) => item is Map) .map((item) => TagModel.fromJson(item as Map)) .toList() ?? [], diff --git a/lib/pages/spaces_management/space_model/widgets/dialog/link_space_model_spaces_dialog.dart b/lib/pages/spaces_management/space_model/widgets/dialog/link_space_model_spaces_dialog.dart index 8c6ef3e9..4da0c642 100644 --- a/lib/pages/spaces_management/space_model/widgets/dialog/link_space_model_spaces_dialog.dart +++ b/lib/pages/spaces_management/space_model/widgets/dialog/link_space_model_spaces_dialog.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:intl/intl.dart'; import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart'; import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_bloc.dart'; import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_event.dart'; @@ -45,6 +46,12 @@ class _LinkSpaceModelSpacesDialogState } Widget _buildDialogContent() { + widget.spaceModel.createdAt.toString(); + String formattedDate = + DateFormat('yyyy-MM-dd').format(widget.spaceModel.createdAt!); + String formattedTime = + DateFormat('HH:mm:ss').format(widget.spaceModel.createdAt!); + return Expanded( child: Padding( padding: const EdgeInsets.all(15.0), @@ -75,8 +82,31 @@ class _LinkSpaceModelSpacesDialogState const SizedBox(height: 16), _buildDetailRow( "Space model name:", widget.spaceModel.modelName), - _buildDetailRow("Creation date and time:", - widget.spaceModel.createdAt.toString()), + Padding( + padding: const EdgeInsets.symmetric(vertical: 4), + child: Row( + children: [ + const Expanded( + child: Text( + "Creation date and time:", + style: const TextStyle( + fontWeight: FontWeight.bold), + ), + ), + const SizedBox(width: 8), + Expanded( + child: Text( + "$formattedDate $formattedTime", + style: const TextStyle( + fontWeight: FontWeight.bold, + color: Colors.black), + ), + ), + ], + ), + ), + // _buildDetailRow("Creation date and time:", + // widget.spaceModel.createdAt.toString()), _buildDetailRow("Created by:", "Admin"), const SizedBox(height: 12), const Text( diff --git a/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart b/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart index e9be3829..06a5da2f 100644 --- a/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart @@ -85,111 +85,106 @@ class SpaceModelCardWidget extends StatelessWidget { maxLines: 1, overflow: TextOverflow.ellipsis, ), - Row( - children: [ - InkWell( - onTap: () { - showDialog( - context: context, - builder: (BuildContext dialogContext) { - return BlocProvider( - create: (_) => LinkSpaceToModelBloc(), - child: BlocListener( - listener: (context, state) { - final _bloc = - BlocProvider.of( - context); - if (state is SpaceModelLoading) { - showDialog( - context: context, - barrierDismissible: false, - builder: (BuildContext context) { - return Dialog( - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(20)), - elevation: 10, - backgroundColor: Colors.white, - child: Padding( - padding: - const EdgeInsets.symmetric( - vertical: 30, - horizontal: 50), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CustomLoadingIndicator(), - const SizedBox(height: 20), - const Text( - "Linking in progress", - style: TextStyle( - fontSize: 16, - fontWeight: - FontWeight.w500, - color: Colors.black87, - ), - ), - ], + if (!topActionsDisabled) + Row( + children: [ + InkWell( + onTap: () { + showDialog( + context: context, + builder: (BuildContext dialogContext) { + return BlocProvider( + create: (_) => LinkSpaceToModelBloc(), + child: BlocListener( + listener: (context, state) { + final _bloc = + BlocProvider.of( + context); + if (state is SpaceModelLoading) { + showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return Dialog( + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular( + 20)), + elevation: 10, + backgroundColor: Colors.white, + child: Padding( + padding: + const EdgeInsets.symmetric( + vertical: 30, + horizontal: 50), + child: Column( + mainAxisSize: + MainAxisSize.min, + children: [ + CustomLoadingIndicator(), + ], + ), ), - ), - ); - }, - ); - } else if (state - is AlreadyHaveLinkedState) { - Navigator.of(dialogContext).pop(); - showOverwriteDialog( - context, _bloc, model); - } else if (state - is SpaceValidationSuccess) { - _bloc.add(LinkSpaceModelEvent( - isOverWrite: false, - selectedSpaceMode: model.uuid)); + ); + }, + ); + } else if (state + is AlreadyHaveLinkedState) { + Navigator.of(dialogContext).pop(); + showOverwriteDialog( + context, _bloc, model); + } else if (state + is SpaceValidationSuccess) { + _bloc.add(LinkSpaceModelEvent( + isOverWrite: false, + selectedSpaceMode: model.uuid)); - Future.delayed(const Duration(seconds: 1), - () { - Navigator.of(dialogContext).pop(); - Navigator.of(dialogContext).pop(); - Navigator.of(dialogContext).pop(); - }); - - showDialog( - context: context, - builder: (BuildContext dialogContext) { - return const LinkingSuccessful(); - }, - ).then((v) { Future.delayed( - const Duration(seconds: 2), () { + const Duration(seconds: 1), () { + Navigator.of(dialogContext).pop(); + Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop(); }); - }); - } else if (state is SpaceModelLinkSuccess) { - Navigator.of(dialogContext).pop(); - Navigator.of(dialogContext).pop(); - showDialog( - context: context, - builder: (BuildContext dialogContext) { - return const LinkingSuccessful(); - }, - ); - } - }, - child: LinkSpaceModelSpacesDialog( - spaceModel: model, + + showDialog( + context: context, + builder: + (BuildContext dialogContext) { + return const LinkingSuccessful(); + }, + ).then((v) { + Future.delayed( + const Duration(seconds: 2), () { + Navigator.of(dialogContext).pop(); + }); + }); + } else if (state + is SpaceModelLinkSuccess) { + Navigator.of(dialogContext).pop(); + Navigator.of(dialogContext).pop(); + showDialog( + context: context, + builder: + (BuildContext dialogContext) { + return const LinkingSuccessful(); + }, + ); + } + }, + child: LinkSpaceModelSpacesDialog( + spaceModel: model, + ), ), - ), - ); - }, - ); - }, - child: SvgPicture.asset( - Assets.spaceLinkIcon, - fit: BoxFit.contain, + ); + }, + ); + }, + child: SvgPicture.asset( + Assets.spaceLinkIcon, + fit: BoxFit.contain, + ), ), - ), - if (!topActionsDisabled) InkWell( onTap: () { _showDeleteDialog(context); @@ -199,49 +194,8 @@ class SpaceModelCardWidget extends StatelessWidget { fit: BoxFit.contain, ), ), - ], - ), - // Expanded( - // child: Text( - // model.modelName, - // style: - // Theme.of(context).textTheme.headlineMedium?.copyWith( - // color: Colors.black, - // fontWeight: FontWeight.bold, - // ), - // maxLines: 1, - // overflow: TextOverflow.ellipsis, - // ), - // ), - // if (!topActionsDisabled) - // GestureDetector( - // onTap: () => _showDeleteDialog(context), - // child: Container( - // width: 36, // Adjust size as needed - // height: 36, - // decoration: BoxDecoration( - // shape: BoxShape.circle, - // color: Colors.white, - // boxShadow: [ - // BoxShadow( - // color: Colors.black.withOpacity(0.1), - // spreadRadius: 2, - // blurRadius: 5, - // offset: const Offset(0, 2), - // ), - // ], - // ), - // child: Center( - // child: SvgPicture.asset( - // Assets.deleteSpaceModel, // Your actual SVG path - // width: 20, - // height: 20, - // colorFilter: const ColorFilter.mode( - // Colors.grey, BlendMode.srcIn), - // ), - // ), - // ), - // ), + ], + ), ], ), if (!showOnlyName) ...[ From e8e5e9bcb730a0677ecb67fed8ec3f52a01d02f8 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 9 Mar 2025 14:54:13 +0300 Subject: [PATCH 2/3] fix LoadedSpaceView --- .../all_spaces/widgets/loaded_space_widget.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart index fef2a4c9..45f97150 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart @@ -80,7 +80,7 @@ class _LoadedSpaceViewState extends State { clipBehavior: Clip.none, children: [ widget.shouldNavigateToSpaceModelPage - ? _spaceModels.isNotEmpty + // ? _spaceModels.isNotEmpty ? Row( children: [ SizedBox(width: 300, child: SpaceTreeView(onSelect: () {})), @@ -99,7 +99,7 @@ class _LoadedSpaceViewState extends State { ), ], ) - : const Center(child: CircularProgressIndicator()) + // : const Center(child: CircularProgressIndicator()) : Row( children: [ SidebarWidget( From dee07ebb06bf89b172cffa3d12fe0599aa15d8a5 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 9 Mar 2025 16:01:04 +0300 Subject: [PATCH 3/3] fix LinkingSuccessful --- .../all_spaces/widgets/loaded_space_widget.dart | 4 ++-- .../bloc/link_space_to_model_state.dart | 2 ++ .../widgets/space_model_card_widget.dart | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart index 45f97150..fef2a4c9 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/loaded_space_widget.dart @@ -80,7 +80,7 @@ class _LoadedSpaceViewState extends State { clipBehavior: Clip.none, children: [ widget.shouldNavigateToSpaceModelPage - // ? _spaceModels.isNotEmpty + ? _spaceModels.isNotEmpty ? Row( children: [ SizedBox(width: 300, child: SpaceTreeView(onSelect: () {})), @@ -99,7 +99,7 @@ class _LoadedSpaceViewState extends State { ), ], ) - // : const Center(child: CircularProgressIndicator()) + : const Center(child: CircularProgressIndicator()) : Row( children: [ SidebarWidget( diff --git a/lib/pages/spaces_management/link_space_model/bloc/link_space_to_model_state.dart b/lib/pages/spaces_management/link_space_model/bloc/link_space_to_model_state.dart index 047567a9..ad18b3c7 100644 --- a/lib/pages/spaces_management/link_space_model/bloc/link_space_to_model_state.dart +++ b/lib/pages/spaces_management/link_space_model/bloc/link_space_to_model_state.dart @@ -5,6 +5,8 @@ abstract class LinkSpaceToModelState { class SpaceModelInitial extends LinkSpaceToModelState {} class SpaceModelLoading extends LinkSpaceToModelState {} +class LinkSpaceModelLoading extends LinkSpaceToModelState {} + class SpaceModelSelectedState extends LinkSpaceToModelState { final int selectedIndex; diff --git a/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart b/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart index 06a5da2f..d028acba 100644 --- a/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/space_model_card_widget.dart @@ -97,6 +97,9 @@ class SpaceModelCardWidget extends StatelessWidget { create: (_) => LinkSpaceToModelBloc(), child: BlocListener( + listenWhen: (previous, current) { + return previous != current; + }, listener: (context, state) { final _bloc = BlocProvider.of( @@ -165,8 +168,15 @@ class SpaceModelCardWidget extends StatelessWidget { Navigator.of(dialogContext).pop(); showDialog( context: context, - builder: - (BuildContext dialogContext) { + barrierDismissible: false, + builder: (BuildContext + successDialogContext) { + Future.delayed( + const Duration(seconds: 2), () { + Navigator.of(successDialogContext) + .pop(); + }); + return const LinkingSuccessful(); }, );