The team management system enables users to create collaborative workspaces where multiple members can work together on tasks. Teams have customizable colors, descriptions, and flexible member management.
Teams are stored in the teams collection with the following structure:
teams/{teamId} ├─ name: string ├─ description: string ├─ userId: string (creator's ID) ├─ createdAt: timestamp ├─ color: number (hex color value) └─ members: array<string> (array of user IDs)
The userId field identifies the team creator, who has special permissions like deleting the team. The members array includes all team members, including the creator.
Enter team name and project description through the AddTeamScreen form.
2
Select Team Color
Choose from 20 predefined colors to visually distinguish the team.
3
Add Members
Search for users by name and add them to the team.
4
Create Team
Save the team to Firestore with all selected members.
Code Example from TeamService:
lib/services/team_service.dart
Future<String?> createTeam( String teamName, String projectDescription, Color color, List<String> selectedMembers) async { try { User? currentUser = _auth.currentUser; if (currentUser != null) { DocumentReference docRef = await _firestore.collection('teams').add({ 'name': teamName, 'description': projectDescription, 'userId': currentUser.uid, 'createdAt': FieldValue.serverTimestamp(), 'color': color.value, // Store color as hexadecimal value 'members': selectedMembers, // Add members when creating team }); return docRef.id; // Return the created document ID } } catch (e) { _logger.e('Error al crear el equipo: $e'); _logger.i('Creando equipo con los siguientes miembros: $selectedMembers'); } return null;}
Future<void> _createTeam() async { if (_teamName.isNotEmpty && _projectDescription.isNotEmpty) { try { User? currentUser = FirebaseAuth.instance.currentUser; if (currentUser != null) { // Get list of selected member IDs List<String> allMembers = _selectedMembers.map((member) => member.uid).toList(); // Ensure current user is included in members if (!allMembers.contains(currentUser.uid)) { allMembers.add(currentUser.uid); } _logger.i('Miembros seleccionados antes de crear el equipo: $allMembers'); // Create the team final teamId = await _teamService.createTeam( _teamName, _projectDescription, _selectedColor, allMembers, ); if (teamId != null) { if (mounted) { Navigator.pop(context, true); } } else { throw Exception('Error al crear el equipo: ID no generado'); } } } catch (e) { _logger.e('Error creating team: $e'); if (mounted) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Error al crear el equipo')), ); } } }}
The team creator is automatically added to the members array if not already included. This ensures the creator always has access to the team they created.