fix model and SpaceModelCardWidget and LinkSpaceModelSpacesDialog

This commit is contained in:
mohammad
2025-03-08 09:57:35 +03:00
parent fa39182386
commit 8af24e575c
3 changed files with 133 additions and 148 deletions

View File

@ -11,7 +11,7 @@ class SpaceTemplateModel extends Equatable {
List<SubspaceTemplateModel>? subspaceModels; List<SubspaceTemplateModel>? subspaceModels;
final List<TagModel>? tags; final List<TagModel>? tags;
String internalId; String internalId;
String? createdAt; DateTime? createdAt;
@override @override
List<Object?> get props => [modelName, subspaceModels, tags]; List<Object?> get props => [modelName, subspaceModels, tags];
@ -24,23 +24,24 @@ class SpaceTemplateModel extends Equatable {
this.tags, this.tags,
this.createdAt, this.createdAt,
}) : internalId = internalId ?? const Uuid().v4(); }) : internalId = internalId ?? const Uuid().v4();
factory SpaceTemplateModel.fromJson(Map<String, dynamic> json) { factory SpaceTemplateModel.fromJson(Map<String, dynamic> json) {
final String internalId = json['internalId'] ?? const Uuid().v4(); final String internalId = json['internalId'] ?? const Uuid().v4();
return SpaceTemplateModel( return SpaceTemplateModel(
uuid: json['uuid'] ?? '', uuid: json['uuid'] ?? '',
createdAt: json['createdAt'] ?? '', createdAt: json['createdAt'] != null
? DateTime.tryParse(json['createdAt'])
: null,
internalId: internalId, internalId: internalId,
modelName: json['modelName'] ?? '', modelName: json['modelName'] ?? '',
subspaceModels: (json['subspaceModels'] as List<dynamic>?) subspaceModels: (json['subspaceModels'] as List<dynamic>?)
?.where((e) => e is Map<String, dynamic>) // Validate type ?.where((e) => e is Map<String, dynamic>)
.map((e) => .map((e) =>
SubspaceTemplateModel.fromJson(e as Map<String, dynamic>)) SubspaceTemplateModel.fromJson(e as Map<String, dynamic>))
.toList() ?? .toList() ??
[], [],
tags: (json['tags'] as List<dynamic>?) tags: (json['tags'] as List<dynamic>?)
?.where((item) => item is Map<String, dynamic>) // Validate type ?.where((item) => item is Map<String, dynamic>)
.map((item) => TagModel.fromJson(item as Map<String, dynamic>)) .map((item) => TagModel.fromJson(item as Map<String, dynamic>))
.toList() ?? .toList() ??
[], [],

View File

@ -1,5 +1,6 @@
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:intl/intl.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/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_bloc.dart';
import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_event.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 _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( return Expanded(
child: Padding( child: Padding(
padding: const EdgeInsets.all(15.0), padding: const EdgeInsets.all(15.0),
@ -75,8 +82,31 @@ class _LinkSpaceModelSpacesDialogState
const SizedBox(height: 16), const SizedBox(height: 16),
_buildDetailRow( _buildDetailRow(
"Space model name:", widget.spaceModel.modelName), "Space model name:", widget.spaceModel.modelName),
_buildDetailRow("Creation date and time:", Padding(
widget.spaceModel.createdAt.toString()), 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"), _buildDetailRow("Created by:", "Admin"),
const SizedBox(height: 12), const SizedBox(height: 12),
const Text( const Text(

View File

@ -85,6 +85,7 @@ class SpaceModelCardWidget extends StatelessWidget {
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
if (!topActionsDisabled)
Row( Row(
children: [ children: [
InkWell( InkWell(
@ -108,7 +109,8 @@ class SpaceModelCardWidget extends StatelessWidget {
return Dialog( return Dialog(
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: borderRadius:
BorderRadius.circular(20)), BorderRadius.circular(
20)),
elevation: 10, elevation: 10,
backgroundColor: Colors.white, backgroundColor: Colors.white,
child: Padding( child: Padding(
@ -117,19 +119,10 @@ class SpaceModelCardWidget extends StatelessWidget {
vertical: 30, vertical: 30,
horizontal: 50), horizontal: 50),
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize:
MainAxisSize.min,
children: [ children: [
CustomLoadingIndicator(), CustomLoadingIndicator(),
const SizedBox(height: 20),
const Text(
"Linking in progress",
style: TextStyle(
fontSize: 16,
fontWeight:
FontWeight.w500,
color: Colors.black87,
),
),
], ],
), ),
), ),
@ -147,8 +140,8 @@ class SpaceModelCardWidget extends StatelessWidget {
isOverWrite: false, isOverWrite: false,
selectedSpaceMode: model.uuid)); selectedSpaceMode: model.uuid));
Future.delayed(const Duration(seconds: 1), Future.delayed(
() { const Duration(seconds: 1), () {
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
@ -156,7 +149,8 @@ class SpaceModelCardWidget extends StatelessWidget {
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext dialogContext) { builder:
(BuildContext dialogContext) {
return const LinkingSuccessful(); return const LinkingSuccessful();
}, },
).then((v) { ).then((v) {
@ -165,12 +159,14 @@ class SpaceModelCardWidget extends StatelessWidget {
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
}); });
}); });
} else if (state is SpaceModelLinkSuccess) { } else if (state
is SpaceModelLinkSuccess) {
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
Navigator.of(dialogContext).pop(); Navigator.of(dialogContext).pop();
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext dialogContext) { builder:
(BuildContext dialogContext) {
return const LinkingSuccessful(); return const LinkingSuccessful();
}, },
); );
@ -189,7 +185,6 @@ class SpaceModelCardWidget extends StatelessWidget {
fit: BoxFit.contain, fit: BoxFit.contain,
), ),
), ),
if (!topActionsDisabled)
InkWell( InkWell(
onTap: () { onTap: () {
_showDeleteDialog(context); _showDeleteDialog(context);
@ -201,47 +196,6 @@ class SpaceModelCardWidget extends StatelessWidget {
), ),
], ],
), ),
// 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) ...[ if (!showOnlyName) ...[