lading chat

This commit is contained in:
Felipe
2024-04-23 14:51:15 -05:00
parent 34135b25e1
commit 76be1f1f1a
6 changed files with 366 additions and 195 deletions
+234 -116
View File
@@ -8,7 +8,6 @@ import 'package:injector/injector.dart';
import 'package:intl/intl.dart';
import 'package:prosappco/blocs/chat_bloc/chat_bloc.dart';
import 'package:prosappco/components/general_reputation.dart';
import 'package:prosappco/screens/user/user_view_profile_screen.dart';
import 'package:service_repository/service_repository.dart';
import 'package:user_repository/user_repository.dart';
@@ -26,6 +25,8 @@ class _ChatScreenState extends State<ChatScreen> {
final TextEditingController _messageController = TextEditingController();
final FocusNode _messageFocusNode = FocusNode();
List<dynamic>? _userInfo;
@override
void initState() {
super.initState();
@@ -37,6 +38,12 @@ class _ChatScreenState extends State<ChatScreen> {
userId: widget.service.userId,
professionalId: widget.service.professionalId,
));
_getUserAndProfessionalInfo(widget.service).then((userInfo) {
setState(() {
_userInfo = userInfo;
});
});
}
@override
@@ -60,125 +67,236 @@ class _ChatScreenState extends State<ChatScreen> {
return Column(
children: [
FutureBuilder(
future: _getUserAndProfessionalInfo(widget.service),
future: _userInfo != null ? Future.value(_userInfo) : null,
builder: (BuildContext context,
AsyncSnapshot<List<dynamic>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else {
if (snapshot.hasError) {
return Center(
child: Text('Error inesperado: ${snapshot.error}'),
);
} else {
final userInfo = snapshot.data![0] as MyUser;
return Container(
padding: const EdgeInsets.symmetric(vertical: 8),
color: const Color(0xFFD6F4FF),
alignment: Alignment.topCenter,
child: ListTile(
leading: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey.shade300,
shape: BoxShape.circle,
image: userInfo.picture == null
? null
: DecorationImage(
image: NetworkImage(
userInfo.picture ?? ''),
fit: BoxFit.contain,
),
),
child: userInfo.picture == null
? Icon(
CupertinoIcons.person,
color: Colors.grey.shade400,
size: 40,
)
: null,
AsyncSnapshot<List<dynamic>?> snapshot) {
if (_userInfo != null) {
final userInfo = _userInfo![0] as MyUser;
return Container(
padding: const EdgeInsets.symmetric(vertical: 8),
color: const Color(0xFFD6F4FF),
alignment: Alignment.topCenter,
child: ListTile(
leading: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey.shade300,
shape: BoxShape.circle,
image: userInfo.picture == null
? null
: DecorationImage(
image: NetworkImage(
userInfo.picture ?? ''),
fit: BoxFit.contain,
),
),
title: Text(
userInfo.name ?? '',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
subtitle: widget.service.userId ==
FirebaseAuth.instance.currentUser!.uid
? GeneralReputation(
userId: widget.service.professionalId,
builder: (context, reputation) {
final average = reputation.averagePro;
final total = reputation.totalPro;
return Row(
children: [
RatingBar.builder(
initialRating:
calculoRating(average),
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemSize: 25,
maxRating: 5,
itemBuilder: (context, _) =>
const Icon(
Icons.star,
color: Color(0xFF2BA4EC),
),
onRatingUpdate: (rating) {},
ignoreGestures: true,
),
const SizedBox(width: 5),
Text(
'${average.toStringAsFixed(1)} (${total.toString()})',
),
],
);
})
: GeneralReputation(
userId: widget.service.userId,
builder: (context, reputation) {
final average = reputation.average;
final total = reputation.total;
return Row(
children: [
RatingBar.builder(
initialRating:
calculoRating(average),
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemSize: 25,
maxRating: 5,
itemBuilder: (context, _) =>
const Icon(
Icons.star,
color: Color(0xFF2BA4EC),
),
onRatingUpdate: (rating) {},
ignoreGestures: true,
),
const SizedBox(width: 5),
Text(
'${average.toStringAsFixed(1)} (${total.toString()})',
),
],
);
},
),
child: userInfo.picture == null
? Icon(
CupertinoIcons.person,
color: Colors.grey.shade400,
size: 40,
)
: null,
),
);
}
title: Text(
userInfo.name ?? '',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
subtitle: widget.service.userId ==
FirebaseAuth.instance.currentUser!.uid
? GeneralReputation(
userId: widget.service.professionalId,
builder: (context, reputation) {
final average = reputation.averagePro;
final total = reputation.totalPro;
return Row(
children: [
RatingBar.builder(
initialRating:
calculoRating(average),
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemSize: 25,
maxRating: 5,
itemBuilder: (context, _) =>
const Icon(
Icons.star,
color: Color(0xFF2BA4EC),
),
onRatingUpdate: (rating) {},
ignoreGestures: true,
),
const SizedBox(width: 5),
Text(
'${average.toStringAsFixed(1)} (${total.toString()})',
),
],
);
})
: GeneralReputation(
userId: widget.service.userId,
builder: (context, reputation) {
final average = reputation.average;
final total = reputation.total;
return Row(
children: [
RatingBar.builder(
initialRating:
calculoRating(average),
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemSize: 25,
maxRating: 5,
itemBuilder: (context, _) =>
const Icon(
Icons.star,
color: Color(0xFF2BA4EC),
),
onRatingUpdate: (rating) {},
ignoreGestures: true,
),
const SizedBox(width: 5),
Text(
'${average.toStringAsFixed(1)} (${total.toString()})',
),
],
);
},
),
),
);
} else {
// Indicador de carga opcional si se desea mostrar mientras se carga la información por primera vez.
return const Center(child: CircularProgressIndicator());
}
// if (snapshot.connectionState == ConnectionState.waiting) {
// return const Center(child: CircularProgressIndicator());
// } else {
// if (snapshot.hasError) {
// return Center(
// child: Text('Error inesperado: ${snapshot.error}'),
// );
// } else {
// final userInfo = snapshot.data![0] as MyUser;
// return Container(
// padding: const EdgeInsets.symmetric(vertical: 8),
// color: const Color(0xFFD6F4FF),
// alignment: Alignment.topCenter,
// child: ListTile(
// leading: Container(
// width: 60,
// height: 60,
// decoration: BoxDecoration(
// color: Colors.grey.shade300,
// shape: BoxShape.circle,
// image: userInfo.picture == null
// ? null
// : DecorationImage(
// image: NetworkImage(
// userInfo.picture ?? ''),
// fit: BoxFit.contain,
// ),
// ),
// child: userInfo.picture == null
// ? Icon(
// CupertinoIcons.person,
// color: Colors.grey.shade400,
// size: 40,
// )
// : null,
// ),
// title: Text(
// userInfo.name ?? '',
// overflow: TextOverflow.ellipsis,
// style: const TextStyle(
// fontSize: 15,
// fontWeight: FontWeight.w600,
// ),
// ),
// subtitle: widget.service.userId ==
// FirebaseAuth.instance.currentUser!.uid
// ? GeneralReputation(
// userId: widget.service.professionalId,
// builder: (context, reputation) {
// final average = reputation.averagePro;
// final total = reputation.totalPro;
// return Row(
// children: [
// RatingBar.builder(
// initialRating:
// calculoRating(average),
// minRating: 1,
// direction: Axis.horizontal,
// allowHalfRating: true,
// itemCount: 5,
// itemSize: 25,
// maxRating: 5,
// itemBuilder: (context, _) =>
// const Icon(
// Icons.star,
// color: Color(0xFF2BA4EC),
// ),
// onRatingUpdate: (rating) {},
// ignoreGestures: true,
// ),
// const SizedBox(width: 5),
// Text(
// '${average.toStringAsFixed(1)} (${total.toString()})',
// ),
// ],
// );
// })
// : GeneralReputation(
// userId: widget.service.userId,
// builder: (context, reputation) {
// final average = reputation.average;
// final total = reputation.total;
// return Row(
// children: [
// RatingBar.builder(
// initialRating:
// calculoRating(average),
// minRating: 1,
// direction: Axis.horizontal,
// allowHalfRating: true,
// itemCount: 5,
// itemSize: 25,
// maxRating: 5,
// itemBuilder: (context, _) =>
// const Icon(
// Icons.star,
// color: Color(0xFF2BA4EC),
// ),
// onRatingUpdate: (rating) {},
// ignoreGestures: true,
// ),
// const SizedBox(width: 5),
// Text(
// '${average.toStringAsFixed(1)} (${total.toString()})',
// ),
// ],
// );
// },
// ),
// ),
// );
// }
// }
},
),
Expanded(
@@ -73,14 +73,14 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
if (state is ProfessionalListSuccess) {
final List<UserProfessional> filteredUsers;
// TODO : encaso de filtro dañado
// TODO: encaso de filtro dañado
// if (_searchController.text.isNotEmpty) {
filteredUsers = state.users
.where((element) => removeDiacritics(element.myUser.name!)
.toLowerCase()
.contains(removeDiacritics(_searchController.text.toLowerCase())))
// .where((user) =>
// user.myUser.id != FirebaseAuth.instance.currentUser!.uid)
.where((user) =>
user.myUser.id != FirebaseAuth.instance.currentUser!.uid)
.toList();
// } else {
// filteredUsers = state.users
@@ -148,35 +148,38 @@ class _ProfessionalProfileScreenState extends State<ProfessionalProfileScreen> {
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 15),
child: Column(
children: [
Row(
children: [
const Expanded(
child: Text(
'Servicio a domicilio',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.black,
Visibility(
visible: settings?.domicilios ?? false,
child: Row(
children: [
const Expanded(
child: Text(
'Servicio a domicilio',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
),
),
Switch(
value: deliveryValue,
onChanged: (value) {
setState(() {
deliveryValue = value;
if (settings?.domicilios == true) {
Switch(
value: deliveryValue,
onChanged: (value) {
setState(() {
deliveryValue = value;
if (!deliveryValue) {
officeValue = true;
if (settings?.domicilios == true) {
deliveryValue = value;
if (!deliveryValue) {
officeValue = true;
}
} else {
deliveryValue = false;
}
} else {
deliveryValue = false;
}
});
},
),
],
});
},
),
],
),
),
Row(
children: [