mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
updated models
This commit is contained in:
@ -58,3 +58,5 @@ class SpacesManagementBloc extends Bloc<SpaceEvent, SpaceState> {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
60
lib/pages/spaces_management/bloc/test_bloc.dart
Normal file
60
lib/pages/spaces_management/bloc/test_bloc.dart
Normal file
@ -0,0 +1,60 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
// Define User States
|
||||
abstract class UserState extends Equatable {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class UserInitial extends UserState {}
|
||||
|
||||
class UserLoaded extends UserState {
|
||||
final List<String> users;
|
||||
final String selectedUser;
|
||||
|
||||
UserLoaded({required this.users, required this.selectedUser});
|
||||
|
||||
@override
|
||||
List<Object> get props => [users, selectedUser];
|
||||
}
|
||||
|
||||
abstract class UserEvent extends Equatable {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class LoadUsers extends UserEvent {
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SelectUser extends UserEvent {
|
||||
final String selectedUser;
|
||||
|
||||
SelectUser(this.selectedUser);
|
||||
|
||||
@override
|
||||
List<Object> get props => [selectedUser];
|
||||
}
|
||||
|
||||
class UserManagementBloc extends Bloc<UserEvent, UserState> {
|
||||
UserManagementBloc() : super(UserInitial()) {
|
||||
on<LoadUsers>((event, emit) {
|
||||
// Dummy list of users
|
||||
final List<String> users = [];
|
||||
|
||||
// Emit the UserLoaded state with the dummy users
|
||||
emit(UserLoaded(users: users, selectedUser: users[0]));
|
||||
});
|
||||
|
||||
on<SelectUser>((event, emit) {
|
||||
// Handle user selection in the UserLoaded state
|
||||
if (state is UserLoaded) {
|
||||
final loadedState = state as UserLoaded;
|
||||
emit(UserLoaded(
|
||||
users: loadedState.users, selectedUser: event.selectedUser));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,6 +1,42 @@
|
||||
class Community {
|
||||
final String name;
|
||||
final List<Community>? children; // Sub-communities
|
||||
import 'package:syncrow_web/pages/auth/model/region_model.dart';
|
||||
|
||||
Community({required this.name, this.children});
|
||||
class CommunityModel {
|
||||
final String uuid;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final String name;
|
||||
final String description;
|
||||
final RegionModel? region;
|
||||
|
||||
CommunityModel({
|
||||
required this.uuid,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
required this.name,
|
||||
required this.description,
|
||||
this.region,
|
||||
});
|
||||
|
||||
factory CommunityModel.fromJson(Map<String, dynamic> json) {
|
||||
return CommunityModel(
|
||||
uuid: json['uuid'],
|
||||
createdAt: DateTime.parse(json['createdAt']),
|
||||
updatedAt: DateTime.parse(json['updatedAt']),
|
||||
name: json['name'],
|
||||
description: json['description'],
|
||||
region:
|
||||
json['region'] != null ? RegionModel.fromJson(json['region']) : null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
'updatedAt': updatedAt.toIso8601String(),
|
||||
'name': name,
|
||||
'description': description,
|
||||
'region': region?.toJson(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,68 @@
|
||||
class SpaceModel {
|
||||
final String communityName;
|
||||
final List<String> subSpaces;
|
||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
|
||||
SpaceModel({required this.communityName, required this.subSpaces});
|
||||
class SpaceModel {
|
||||
final String uuid;
|
||||
final DateTime createdAt;
|
||||
final DateTime updatedAt;
|
||||
final String? spaceTuyaUuid;
|
||||
final String name;
|
||||
final bool isPrivate;
|
||||
final String? invitationCode;
|
||||
final bool isParent;
|
||||
final SpaceModel? parent;
|
||||
final CommunityModel? community;
|
||||
final List<SpaceModel> children; // List of child spaces
|
||||
|
||||
SpaceModel({
|
||||
required this.uuid,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
this.spaceTuyaUuid,
|
||||
required this.name,
|
||||
required this.isPrivate,
|
||||
this.invitationCode,
|
||||
required this.isParent,
|
||||
this.parent,
|
||||
this.community,
|
||||
required this.children,
|
||||
});
|
||||
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
return SpaceModel(
|
||||
uuid: json['uuid'],
|
||||
createdAt: DateTime.parse(json['createdAt']),
|
||||
updatedAt: DateTime.parse(json['updatedAt']),
|
||||
spaceTuyaUuid: json['spaceTuyaUuid'],
|
||||
name: json['name'],
|
||||
isPrivate: json['isPrivate'],
|
||||
invitationCode: json['invitationCode'],
|
||||
isParent: json['isParent'],
|
||||
parent:
|
||||
json['parent'] != null ? SpaceModel.fromJson(json['parent']) : null,
|
||||
community: json['community'] != null
|
||||
? CommunityModel.fromJson(json['community'])
|
||||
: null,
|
||||
children: json['children'] != null
|
||||
? (json['children'] as List)
|
||||
.map((child) => SpaceModel.fromJson(child))
|
||||
.toList()
|
||||
: [],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
'updatedAt': updatedAt.toIso8601String(),
|
||||
'spaceTuyaUuid': spaceTuyaUuid,
|
||||
'name': name,
|
||||
'isPrivate': isPrivate,
|
||||
'invitationCode': invitationCode,
|
||||
'isParent': isParent,
|
||||
'parent': parent?.toMap(),
|
||||
'community': community?.toMap(),
|
||||
'children': children.map((child) => child.toMap()).toList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
67
lib/pages/spaces_management/model/space_response_model.dart
Normal file
67
lib/pages/spaces_management/model/space_response_model.dart
Normal file
@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'space_model.dart';
|
||||
|
||||
class SpacesResponse {
|
||||
final List<SpaceModel> data;
|
||||
final String message;
|
||||
final int page;
|
||||
final int size;
|
||||
final int totalItem;
|
||||
final int totalPage;
|
||||
final bool hasNext;
|
||||
final bool hasPrevious;
|
||||
|
||||
SpacesResponse({
|
||||
required this.data,
|
||||
required this.message,
|
||||
required this.page,
|
||||
required this.size,
|
||||
required this.totalItem,
|
||||
required this.totalPage,
|
||||
required this.hasNext,
|
||||
required this.hasPrevious,
|
||||
});
|
||||
|
||||
factory SpacesResponse.fromJson(Map<String, dynamic> json) {
|
||||
return SpacesResponse(
|
||||
data: (json['data'] as List)
|
||||
.map((jsonItem) => SpaceModel.fromJson(jsonItem))
|
||||
.toList(),
|
||||
message: json['message'],
|
||||
page: json['page'],
|
||||
size: json['size'],
|
||||
totalItem: json['totalItem'],
|
||||
totalPage: json['totalPage'],
|
||||
hasNext: json['hasNext'],
|
||||
hasPrevious: json['hasPrevious'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CommunitySpaceManagementApi {
|
||||
Future<SpacesResponse> fetchSpaces(String communityId) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.listSpaces.replaceAll('{communityId}', communityId),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return SpacesResponse.fromJson(json);
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
debugPrint('Error fetching spaces: $e');
|
||||
return SpacesResponse(
|
||||
data: [],
|
||||
message: 'Error fetching spaces',
|
||||
page: 1,
|
||||
size: 10,
|
||||
totalItem: 0,
|
||||
totalPage: 0,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CreateCommunityDialog extends StatefulWidget {
|
||||
final Function(String) onCreateCommunity;
|
||||
|
||||
const CreateCommunityDialog({super.key, required this.onCreateCommunity});
|
||||
|
||||
@override
|
||||
CreateCommunityDialogState createState() => CreateCommunityDialogState();
|
||||
}
|
||||
|
||||
class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
||||
String enteredName = ''; // Store the entered community name
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
backgroundColor: Colors.transparent, // Transparent for shadow effect
|
||||
child: Stack(
|
||||
children: [
|
||||
// Background container with shadow and rounded corners
|
||||
Container(
|
||||
width: 490,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.25),
|
||||
blurRadius: 20,
|
||||
spreadRadius: 5,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Community Name',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
// Input field for the community name
|
||||
TextField(
|
||||
onChanged: (value) {
|
||||
enteredName = value; // Capture entered name
|
||||
},
|
||||
style: const TextStyle(
|
||||
color: Colors.black,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Please enter the community name',
|
||||
filled: true,
|
||||
fillColor: const Color(0xFFF5F6F7),
|
||||
hintStyle: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF999999),
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
border: OutlineInputBorder(
|
||||
borderSide:
|
||||
const BorderSide(color: Color(0xFFF5F6F7), width: 1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderSide:
|
||||
const BorderSide(color: Color(0xFFF5F6F7), width: 1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide:
|
||||
const BorderSide(color: Color(0xFFF5F6F7), width: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Action buttons
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
style: TextButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: const Color(0xFFF5F6F7),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cancel',
|
||||
style: TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
if (enteredName.isNotEmpty) {
|
||||
widget.onCreateCommunity(enteredName);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: const Color(0xFF023DFE),
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user