voice_and_message_room 0.1.0
voice_and_message_room: ^0.1.0 copied to clipboard
Voice and message meeting room UI components with role-based chairs, real-time user management and chat support.
/*
***
Meeting Room Page - Paketli Versiyon
Paket 3 ana yapıdan oluştur:
1- Top Bar (MeetingRoomTopBar) // kullanıcı rolüne göre (admin,proje yöneticisi,bayi) koltuklarını ayarlar, ilgili kullanıcını
odaya/kanala ses alması ve sesini kapatması için ses ikonu sağlar
2- Chairs (MeetingRoomChairs) // odaya gelen kullanıcıların koltuklarını ayarlar
3- Chat (MeetingRoomChat) // mesajlaşma alanı
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
import 'package:fund_wallet/others/firebase/firebase_manager.dart';
import 'package:voice_and_message_room/voice_and_message_room.dart'
show
MeetingRoomUsersModel,
MeetingRoomTopBar,
MeetingRoomChairs,
MeetingRoomChat,
UserProfileModel,
MeetingRoomModel,
ChairModel;
import '../../models/manager_chair_model.dart';
import '../../others/firebase/firebase_manager_paket.dart'
show FirebaseManagerPaket;
import '../../others/functions.dart';
import '../../others/strings.dart';
import '../../others/voice_call_manager.dart';
// ignore: must_be_immutable
class MeetingRoomPagePaketli extends StatefulWidget {
bool isMeeting;
String token;
MeetingRoomModel meetingRoomModel;
MeetingRoomPagePaketli(
{super.key,
required this.isMeeting,
required this.token,
required this.meetingRoomModel});
@override
State<MeetingRoomPagePaketli> createState() => _MeetingRoomPagePaketliState();
}
class _MeetingRoomPagePaketliState extends State<MeetingRoomPagePaketli> {
Functions functions = Functions();
Strings strings = Strings();
double sizeWidth = 0.0;
double sizeHeight = 0.0;
int usersCount = 0;
String projectName = "Örnek Sohbet ve Ses Odası";
List<MeetingRoomUsersModel> meetingRoomUserList = [];
List<MeetingRoomUsersModel> sittingUserList = [];
List<MeetingRoomUsersModel> lockingUserList = [];
List<MeetingRoomUsersModel> volumeUnMutedUserList = [];
UserProfileModel? userProfil;
String? userRol;
String? projeManager;
bool isMuted = true;
bool isJoined = false;
late StreamSubscription _chairSubscription;
final TextEditingController _controller = TextEditingController();
late String channelUniq;
@override
void initState() {
super.initState();
channelUniq =
'${dotenv.env['CHANNAL_NAME']}';
transactions();
_initAgora();
_chairSubscription =
FirebaseManagerPaket.listenToChairs().listen(_handleChairUpdate);
}
Future<void> toggleUserAudio(BuildContext context, bool isMuted) async {
if (userRol == "Developer") {
final isUserOnCharit = sittingUserList
.where((p) =>
p.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId.toString()}" &&
p.developerId != null &&
p.developerId != "" &&
p.userId == widget.meetingRoomModel.developerId.toString() &&
p.developerId == widget.meetingRoomModel.developerId.toString())
.firstOrNull;
if (isUserOnCharit != null) {
final isMutedUserByAdmin = isUserOnCharit.isMuted ?? false;
if (isMutedUserByAdmin) {
functions.showToast(
context, "Sesiniz admin tararfından kısıtlanmıştır");
setState(() {
isMuted = true;
});
return;
}
if (!isJoined) {
await _joinChannel();
}
print("mute : $isMuted");
await VoiceCallManager.muteMyMic(isMuted);
functions.showToast(
context,
isMuted ? "Sesiniz kapatıldı." : "Konuşabilirsiniz.",
);
setState(() {
isMuted = isMuted;
});
} else {
functions.showToast(
context, "Sesi açmanız için öncelikle koltuğa oturmalısınız");
setState(() {
isMuted = true;
});
}
} else {
if (!isJoined) {
await _joinChannel();
}
print("mute : $isMuted");
await VoiceCallManager.muteMyMic(isMuted);
functions.showToast(
context,
isMuted ? "Sesiniz kapatıldı." : "Konuşabilirsiniz.",
);
setState(() {
isMuted = isMuted;
});
}
}
void _handleChairUpdate(List<ChairModel> chairs) {
setState(() {
sittingUserList = sittingUserList.map((user) {
final match = chairs
.where((p) =>
p.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId.toString()}")
.firstWhere(
(c) => c.chairId == user.roomId.toString(),
orElse: () => ChairModel(),
);
final isChairOccupied = match.chairId != null;
String pUrl = "";
if (match.profileURL == null || match.profileURL == '') {
pUrl = "";
} else {
pUrl = dotenv.env[strings.baseTopURL]! +
"/assets/img/users/${match.profileURL}";
}
return user.copyWith(
userOnChair: isChairOccupied,
profileURL: pUrl,
developerId: match.developerId,
username: match.username,
isChairLockByAdmin: match.isAdminChairLock,
projectId: match.productId);
}).toList();
});
}
Future<void> _initAgora() async {
await VoiceCallManager
.initAgora(); // mikrofon izni + engine init + event kayıt
}
Future<void> _joinChannel() async {
await VoiceCallManager.joinChannel(
uid: widget.meetingRoomModel.developerId ?? 0,
projectId: widget.meetingRoomModel.projectId.toString());
setState(() {
isJoined = true;
});
}
@override
void dispose() {
VoiceCallManager.dispose();
_chairSubscription.cancel();
super.dispose();
}
transactions() async {
userRol = "admin"; //"project_manager"; ,"admin"
print("userRol : $userRol");
userProfil = UserProfileModel(userId: 1, name: "Mansur Emin", profile: "", totalScore: 0);
projectName = widget.meetingRoomModel.projectName;
for (int i = 0; i < widget.meetingRoomModel.userCount; i++) { // ilgili odaya ait kullanıcı sayısı
sittingUserList.add(MeetingRoomUsersModel(
roomId: i,
username: "",
isChairLockByAdmin: false,
isMuted: false,
nameAndSurname: "No: ${i + 1}",
profileURL: "",
developerId: "",
userId: widget.meetingRoomModel.developerId.toString(),
projectId: widget.meetingRoomModel.projectId.toString(),
channelId:
"${channelUniq}_${widget.meetingRoomModel.projectId.toString()}",
userOnChair: false));
}
setState(() {});
}
// odaya/kanala gelen kullanıcılar
Future<void> showDevelopersBottomSheet(
BuildContext context, List<MeetingRoomUsersModel>? list) async {
if (list == null || list.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Geliştirici bilgisi bulunamadı.")),
);
return;
}
showModalBottomSheet(
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.min, // İçeriğe göre küçülür
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Geliştiriciler",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
Divider(height: 1),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height *
0.5,
),
child: ListView.builder(
shrinkWrap: true,
itemCount: list.length,
itemBuilder: (context, i) {
final dev = list[i];
return ListTile(
leading: CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
dotenv.env[strings.baseTopURL]! +
"/assets/img/users/${dev.profileURL}"),
backgroundColor: Colors.grey[200],
),
title: Text(dev.username ?? "Bilinmiyor"),
subtitle: Text("ID: ${dev.developerId}"),
);
},
),
),
Divider(height: 1),
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text("Kapat"),
),
],
),
);
},
);
}
// koltuğu kilitlenip /açılacak kullanıcılar
Future<void> showWillLockingDevelopersBottomSheet(
BuildContext context, List<MeetingRoomUsersModel>? list) async {
if (list == null || list.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Geliştirici bilgisi bulunamadı.")),
);
return;
}
//lockingUserList = [];
showModalBottomSheet(
context: context,
isScrollControlled: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Koltuğu Kilitlenip/Açılacak Geliştiriciler",
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
Divider(height: 1),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.5,
),
child: ListView.builder(
shrinkWrap: true,
itemCount: list.length,
itemBuilder: (context, i) {
final dev = list[i];
final isChecked = lockingUserList.any((user) =>
user.developerId == dev.developerId &&
user.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId}");
return CheckboxListTile(
value: isChecked,
onChanged: (val) {
setState(() {
if (val == true) {
final alreadyExists = lockingUserList.any((user) =>
user.developerId == dev.developerId &&
user.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId}");
if (!alreadyExists) {
lockingUserList.add(dev);
}
} else {
lockingUserList.removeWhere((user) =>
user.developerId == dev.developerId &&
user.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId}");
}
});
},
secondary: CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
dotenv.env[strings.baseTopURL]! +
"/assets/img/users/${dev.profileURL}",
),
backgroundColor: Colors.grey[200],
),
title: Text(dev.username ?? "Bilinmiyor"),
subtitle: Text("ID: ${dev.developerId}"),
);
},
),
),
Divider(height: 1),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
print("Seçilen geliştiriciler:");
for (var user in lockingUserList) {
print("${user.username} - ${user.developerId}");
}
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: const Text("Kapat"),
),
TextButton(
onPressed: () async {
final channelId =
"${channelUniq}_${widget.meetingRoomModel.projectId}";
final updatedList = [...sittingUserList];
for (var lockedUser in lockingUserList) {
final matchingIndexes = updatedList
.asMap()
.entries
.where((entry) =>
entry.value.userId ==
lockedUser.developerId &&
entry.value.developerId == "" &&
entry.value.channelId == channelId)
.map((entry) => entry.key)
.toList();
for (var index in matchingIndexes) {
final current = updatedList[index];
final updatedUser = current.copyWith(
userOnChair: false,
profileURL: lockedUser.profileURL,
developerId: lockedUser.developerId,
username: lockedUser.username,
isChairLockByAdmin: true,
projectId: lockedUser.projectId,
);
updatedList[index] = updatedUser;
// Firebase'e güncelleme gönder
await updateChairModel(
item: updatedUser,
userProfil: userProfil,
meetingRoomModel: widget.meetingRoomModel,
);
}
}
// Güncellenmiş listeyi state'e yaz
setState(() {
sittingUserList = updatedList;
});
// Log
print("🔒 Kilitlenen kullanıcılar:");
for (var user in sittingUserList
.where((e) => e.isChairLockByAdmin == true)) {
print(
"${user.username} - ${user.developerId} - ${user.roomId}");
}
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: const Text("Kilitle"),
),
],
),
],
),
);
},
);
},
);
}
// ses iaç/kapat yapıalcak kullanıcılar
Future<void> showWillVolumeUnMutedDevelopersBottomSheet(
BuildContext context,
List<MeetingRoomUsersModel>? list,
) async {
if (list == null || list.isEmpty) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text("Geliştirici bilgisi bulunamadı.")),
);
return;
}
showModalBottomSheet(
context: context,
isScrollControlled: true,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16)),
),
builder: (context) {
return StatefulBuilder(
builder: (context, setState) {
return Padding(
padding:
const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Padding(
padding: EdgeInsets.all(8.0),
child: Text(
"Sesi Açılıp/Kapatılacak Geliştiriciler",
style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
const Divider(height: 1),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height * 0.5,
),
child: ListView.builder(
shrinkWrap: true,
itemCount: list.length,
itemBuilder: (context, i) {
final dev = list[i];
final isChecked = volumeUnMutedUserList.any(
(user) =>
user.developerId == dev.developerId &&
user.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId}",
);
return CheckboxListTile(
value: isChecked,
onChanged: (val) {
setState(() {
final channelId =
"${channelUniq}_${widget.meetingRoomModel.projectId}";
if (val == true) {
final alreadyExists = volumeUnMutedUserList.any(
(user) =>
user.developerId == dev.developerId &&
user.channelId == channelId,
);
if (!alreadyExists) {
volumeUnMutedUserList.add(dev);
}
} else {
volumeUnMutedUserList.removeWhere(
(user) =>
user.developerId == dev.developerId &&
user.channelId == channelId,
);
}
});
},
secondary: CircleAvatar(
radius: 20,
backgroundImage: NetworkImage(
"${dotenv.env[strings.baseTopURL]}/assets/img/users/${dev.profileURL}",
),
backgroundColor: Colors.grey[200],
),
title: Text(dev.username ?? "Bilinmiyor"),
subtitle: Text("ID: ${dev.developerId}"),
);
},
),
),
const Divider(height: 1),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
//
print("Seçilen geliştiriciler:");
for (var user in volumeUnMutedUserList) {
print("${user.username} - ${user.developerId}");
}
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: const Text("Kapat"),
),
TextButton(
onPressed: () async {
print("🔊 Sesi açılacak/kapatılacak geliştiriciler:");
for (var user in volumeUnMutedUserList) {
print("${user.username} - ${user.developerId}");
}
final channelId =
"${channelUniq}_${widget.meetingRoomModel.projectId}";
final updatedVolumeList = [...sittingUserList];
for (var lockedUser in volumeUnMutedUserList) {
final matchingIndexes = updatedVolumeList
.asMap()
.entries
.where((entry) =>
entry.value.userId ==
lockedUser.developerId &&
entry.value.channelId == channelId)
.map((entry) => entry.key)
.toList();
for (var index in matchingIndexes) {
final current = updatedVolumeList[index];
final updatedUser = current.copyWith(
userOnChair: false,
isMuted: true,
profileURL: lockedUser.profileURL,
developerId: lockedUser.developerId,
username: lockedUser.username,
isChairLockByAdmin: true,
projectId: lockedUser.projectId,
);
updatedVolumeList[index] = updatedUser;
// Firebase'e güncelleme gönder
/*await updateChairModel(
item: updatedUser,
userProfil: userProfil,
meetingRoomModel: widget.meetingRoomModel,
);*/
}
}
// Güncellenmiş listeyi state'e yaz
setState(() {
sittingUserList = updatedVolumeList;
});
if (context.mounted) {
Navigator.of(context).pop();
}
},
child: const Text("Kaydet"),
),
],
),
],
),
);
},
);
},
);
}
Widget buildRoleChairWidget({
required String rolePrefix,
required String roleName,
required String userRoleCheck,
required String userRol,
required double sizeWidth,
required UserProfileModel? userProfil,
required MeetingRoomModel meetingRoomModel,
required BuildContext context,
}) {
final developerId = userProfil?.userId == 0
? meetingRoomModel.developerId.toString()
: userProfil?.userId.toString();
final model = ManagerChairModel(
chairId: "",
profileURL: "${userProfil?.profile ?? ''}",
channelId:
"${channelUniq}_${meetingRoomModel.projectId.toString()}",
productId: meetingRoomModel.projectId.toString(),
developerId: developerId,
username: projeManager != null ? projeManager : userProfil?.name ?? "",
);
final key = "${rolePrefix}_$developerId";
return Padding(
padding: EdgeInsets.all(sizeWidth * 0.035),
child: GestureDetector(
onTap: () async {
//if(projeManager != null || projeManager != "" || projeManager=="") return;
if (userRol != userRoleCheck) return;
await FirebaseManager.createAdminChair(key, model.toMap());
},
child: Column(
children: [
StreamBuilder<ManagerChairModel>(
stream: FirebaseManager.listenToeAdminChairsByKey(key),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
}
if (!snapshot.hasData) {
return Column(
children: [
Icon(
userRoleCheck == "project_manager"
? Icons.person
: Icons.chair,
color: Colors.green.shade500,
size: sizeWidth * 0.075,
),
SizedBox(height: 4),
Text(
roleName,
style: TextStyle(
color: Colors.grey.shade600,
fontSize: sizeWidth * 0.025,
fontWeight: FontWeight.w600,
),
),
],
);
}
final data = snapshot.data!;
final imageUrl = data.profileURL?.isNotEmpty == true
? dotenv.env[strings.baseTopURL]! +
"/assets/img/users/${data.profileURL}"
: null;
return Column(
children: [
imageUrl != null
? Image.network(
imageUrl,
width: sizeWidth * 0.075,
height: sizeWidth * 0.075,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Icon(
Icons.person,
color: Colors.green.shade500,
size: sizeWidth * 0.075,
);
},
)
: Icon(
Icons.person,
color: Colors.green.shade500,
size: sizeWidth * 0.075,
),
SizedBox(height: 4),
Text(
data.username ?? roleName,
style: TextStyle(
color: Colors.grey.shade600,
fontSize: sizeWidth * 0.025,
fontWeight: FontWeight.w600,
),
),
],
);
},
),
],
),
),
);
}
@override
Widget build(BuildContext context) {
sizeWidth = functions.getSizeWidth(context);
sizeHeight = functions.getSizeHeight(context);
return Scaffold(
body: SafeArea(
child: Container(
width: sizeWidth,
height: sizeHeight,
color: Colors.white,
child: Column(
children: [
/// üst kısım
/// start: meeting_room_top_bar , package
MeetingRoomTopBar(
sizeWidth: sizeWidth,
userRol: userRol ?? "",
projectId: widget.meetingRoomModel.projectId ?? 0,
projectName: projectName,
onGetUsers: () async {
if (userRol == "Developer") {
functions.showToast(context,
"Odaya gelenleri görme admin veya proje yöneticisi yetkisi ile yapılabilir.");
return;
};
int projectId = widget.meetingRoomModel.projectId ?? 0;
List<MeetingRoomUsersModel>? users =
await FirebaseManagerPaket.getUsers();
final listUser = users
.where((p) => p.projectId == projectId.toString())
.toList();
if (context.mounted) {
await showDevelopersBottomSheet(context, listUser);
}
},
onVolumePressed: () async {
if (projeManager == null) {
if (userRol == "Developer" || userRol == "bayi") {
functions.showToast(context,
"Kullanıcı Sesi Açıp Kapatma admin veya proje yöneticisi yetkisi ile yapılabilir.");
return;
};
}
int projectId = widget.meetingRoomModel.projectId ?? 0;
List<MeetingRoomUsersModel>? users =
await FirebaseManagerPaket.getUsers();
final listUser = users
.where((p) => p.projectId == projectId.toString())
.toList();
if (context.mounted) {
await showWillVolumeUnMutedDevelopersBottomSheet(
context, listUser);
}
},
onBackPressed: () async {
Navigator.pop(context);
},
onLockPressed: () async {
// sadece admin erişecek
if (userRol == "Developer" || userRol == "bayi") {
functions.showToast(context,
"Kullanıcı Koltuk Kilitleme admin yetkisi ile yapılabilir.");
return;
};
int projectId = widget.meetingRoomModel.projectId ?? 0;
List<MeetingRoomUsersModel>? users =
await FirebaseManagerPaket.getUsers();
final listUser = users
.where((p) => p.projectId == projectId.toString())
.toList();
if (context.mounted) {
await showWillLockingDevelopersBottomSheet(
context, listUser);
}
},
onExitPressed: () async {
// çıkış işlemleri
var key = widget.meetingRoomModel.developerId.toString() +
"-" +
widget.meetingRoomModel.projectId.toString();
await FirebaseManagerPaket.deleteUser(key);
FirebaseManagerPaket.listenToUsers()
.listen((listOnlineUser) async {
if (listOnlineUser.isEmpty) {
final channelId =
"${channelUniq}_${widget.meetingRoomModel.projectId}";
await FirebaseManagerPaket.deleteAllMessagesByChannelId(
channelId);
}
});
final currentChairUser = sittingUserList
.where((p) =>
p.developerId != null &&
p.developerId ==
widget.meetingRoomModel.developerId.toString() &&
p.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId.toString()}")
.firstOrNull;
final keyChair =
"${currentChairUser?.roomId.toString()}-${currentChairUser?.projectId.toString()}";
await FirebaseManagerPaket.deleteChair(keyChair);
if (mounted) {
Navigator.pop(context);
}
},
),
/// end : meeting_room_top_bar , package
/// start: meeting_room_chairs , package
//koltuklar ,admin, proje yöneticisi, bayi
Expanded(
flex: 1,
child: MeetingRoomChairs(
sizeWidth: sizeWidth,
isAdmin: true,
isProjectManager: true ,
userRole: userRol ?? "",
isMuted: isMuted,
onToggleAudio: (context, muted) async {
await toggleUserAudio(context, muted);
},
sittingUserList: sittingUserList,
onChairAction: (item, action) async {
// Yetki kontrolü
if (userRol != "Developer") return;
// Admin lock kontrolü
final isAdminLock = item.isChairLockByAdmin ?? false;
if (isAdminLock) {
functions.showToast(context,
"Koltuk size admin tarafından kısıtlanmıştır");
return;
}
// Tek oturma kontrolü
bool showSheet = false;
final isUser = sittingUserList.where((p) =>
p.developerId != "" &&
p.developerId ==
widget.meetingRoomModel.developerId?.toString());
if (isUser.isEmpty) {
showSheet = true;
} else {
if ((item.userId == item.developerId &&
item.userOnChair == true)) {
showSheet = true;
}
}
if (showSheet) {
await showChairActionsBottomSheet(
context: context,
item: item,
sittingUserList: sittingUserList,
userProfil: userProfil,
meetingRoomModel: widget.meetingRoomModel,
onTapLeave: () async {
final isAdminLockChair =
item.isChairLockByAdmin ?? false;
if (isAdminLockChair) {
functions.showToast(context,
"Admin koltuk işlemlerinizi kilitledi.");
Navigator.of(context).pop();
return;
}
item.isChairLockByAdmin = false;
item.userOnChair = false;
await updateChairModel(
item: item,
userProfil: userProfil,
meetingRoomModel: widget.meetingRoomModel,
);
setState(() {
final index = sittingUserList.indexWhere(
(e) => e.roomId.toString() == item.roomId);
if (index != -1) {
sittingUserList[index] =
sittingUserList[index].copyWith(
userOnChair: false,
isChairLockByAdmin: false,
profileURL: "",
developerId: "",
projectId: "",
);
}
});
if (context.mounted) Navigator.of(context).pop();
},
onTapSit: () async {
final isAdminLockChair =
item.isChairLockByAdmin ?? false;
if (isAdminLockChair) {
functions.showToast(context,
"Admin koltuk işlemlerinizi kilitledi.");
Navigator.of(context).pop();
return;
}
final chairId = item.roomId ?? "0";
final model = ChairModel(
chairId: chairId.toString(),
isChair: true,
isAdminChairLock: false,
profileURL: "${userProfil?.profile ?? ''}",
channelId:
"${channelUniq}_${widget.meetingRoomModel.projectId.toString()}",
productId:
widget.meetingRoomModel.projectId.toString(),
developerId: userProfil?.userId == 0
? widget.meetingRoomModel.developerId
.toString()
: userProfil?.userId.toString(),
username: userProfil?.name ?? "",
);
final alreadySeated = sittingUserList.any((p) =>
(p.developerId != null ||
p.developerId != "") &&
p.developerId.toString() ==
widget.meetingRoomModel.developerId
?.toString() &&
p.channelId != null &&
p.userOnChair == true &&
p.channelId ==
"${channelUniq}_${widget.meetingRoomModel.projectId.toString()}");
if (alreadySeated) {
functions.showToast(
context, "Birden fazla koltuğa oturmazsınız");
Navigator.of(context).pop();
} else {
var key =
"$chairId-${widget.meetingRoomModel.projectId.toString()}";
await FirebaseManagerPaket.createChair(
key.toString(), model.toMap());
Navigator.of(context).pop();
}
});
}
},
projectManagerChairWidget: buildRoleChairWidget(
rolePrefix: "project_manager",
roleName: "Project Manager",
userRoleCheck: "project_manager",
userRol: userRol ?? "",
sizeWidth: sizeWidth,
userProfil: userProfil,
meetingRoomModel: widget.meetingRoomModel,
context: context,
),
adminChairWidget: buildRoleChairWidget(
rolePrefix: "admin",
roleName: "Administrator",
userRoleCheck: "admin",
userRol: userRol ?? "",
sizeWidth: sizeWidth,
userProfil: userProfil,
meetingRoomModel: widget.meetingRoomModel,
context: context,
),
bayiChairWidget: buildRoleChairWidget(
rolePrefix: "bayi",
roleName: "Dealer",
userRoleCheck: "bayi",
userRol: userRol ?? "",
sizeWidth: sizeWidth,
userProfil: userProfil,
meetingRoomModel: widget.meetingRoomModel,
context: context,
),
),
),
/// end: meeting_room_chairs , package
//mesajlaşmalar burda
/// start: meeting_room_chat , package
Expanded(
flex: 1,
child: MeetingRoomChat(
sizeWidth: sizeWidth,
controller: _controller,
avatarBuilder: (context, msg) {
return CircleAvatar(
radius: 20,
backgroundImage: const AssetImage('assets/icons/profile.png'),
);
},
projectId: widget.meetingRoomModel.projectId.toString(),
streamMessages: () {
return FirebaseManagerPaket.listenToMessage();
// return Stream<List<MessageModel>>.empty();
},
sendMessage: (message) async {
_sendMessage(message);
},
),
)
/// end: meeting_room_chat , package
],
),
),
),
);
}
Future<void> showChairActionsBottomSheet({
required BuildContext context,
required MeetingRoomUsersModel item,
required List<MeetingRoomUsersModel> sittingUserList,
required dynamic userProfil,
required dynamic meetingRoomModel,
required void Function()? onTapSit,
required void Function()? onTapLeave,
}) async {
await showModalBottomSheet(
context: context,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.max,
children: [
ListTile(
leading: const Icon(Icons.chair_alt, color: Colors.green),
title: const Text('Koltukta Otur'),
onTap: onTapSit),
const Divider(height: 1),
ListTile(
leading: const Icon(Icons.exit_to_app, color: Colors.red),
title: const Text('Koltuktan Kalk'),
onTap: onTapLeave,
),
],
);
},
);
}
Future<void> updateChairModel({
required MeetingRoomUsersModel item,
required UserProfileModel? userProfil,
required MeetingRoomModel meetingRoomModel,
}) async {
final chairId = item.roomId.toString();
final key = '$chairId-${meetingRoomModel.projectId}';
final model = ChairModel(
chairId: chairId,
isChair: item.userOnChair,
isAdminChairLock: item.isChairLockByAdmin,
profileURL: '', //userProfil?.profile ??
channelId: '${channelUniq}_${meetingRoomModel.projectId}',
productId: meetingRoomModel.projectId.toString(),
developerId: (userProfil?.userId == 0)
? meetingRoomModel.developerId.toString()
: userProfil?.userId.toString(),
username: '', // userProfil?.name ??
);
await FirebaseManager.updateChair(key, model.toMap());
}
void _sendMessage(mesaj) async {
//final text = _controller.text.trim();
if (mesaj.isEmpty) return;
await FirebaseManager.sendMessage({
'channelId':
"${channelUniq}_${widget.meetingRoomModel.projectId.toString()}",
'productId': widget.meetingRoomModel.projectId,
'developerId': widget.meetingRoomModel.developerId,
'message': mesaj,
'profileLink': userProfil?.profile,
'timestamp': FieldValue.serverTimestamp(),
});
_controller.clear();
}
menuIcon(double sizeWidth, IconData icon, int number,
[VoidCallback? onPressed]) {
return TextButton(
onPressed: onPressed ??
() { },
child: Icon(
icon,
color: Colors.pinkAccent,
size: sizeWidth * 0.075,
),
);
}
}
*/