fix pov user y profesional

This commit is contained in:
Felipe
2024-04-18 10:23:43 -05:00
parent 2facd1b1d8
commit 142c09d389
8 changed files with 619 additions and 173 deletions
+188 -41
View File
@@ -7,6 +7,7 @@ import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:injector/injector.dart';
import 'package:prosappco/blocs/score_bloc/score_bloc.dart';
import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
import 'package:prosappco/components/general_reputation.dart';
import 'package:score_repository/score_repository.dart';
import 'package:service_repository/service_repository.dart';
import 'package:user_repository/user_repository.dart';
@@ -24,11 +25,20 @@ class _ScoreScreenState extends State<ScoreScreen> {
double _rating = 1.0;
TextEditingController commentController = TextEditingController();
late Future<List<dynamic>> _userInfoFuture;
late bool isProfessional;
late String userId;
@override
void initState() {
super.initState();
_userInfoFuture = _getUserAndProfessionalInfo(widget.service);
isProfessional =
FirebaseAuth.instance.currentUser!.uid == widget.service.userId
? true
: false;
userId =
isProfessional ? widget.service.professionalId : widget.service.userId;
}
@override
@@ -56,48 +66,155 @@ class _ScoreScreenState extends State<ScoreScreen> {
} else {
final userInfo = snapshot.data![0] as MyUser;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
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,
return SizedBox(
width: double.infinity,
child: Stack(
alignment: Alignment.center,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 95,
height: 95,
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: 50,
)
: null,
),
const SizedBox(height: 8),
Text(
'${userInfo.name}',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 15,
)
],
),
GeneralReputation(
userId: userId,
builder: (BuildContext context,
ReputationEntity reputation) {
final double average;
if (isProfessional) {
average = reputation.averagePro;
} else {
average = reputation.average;
}
return Positioned(
top: 3,
right: MediaQuery.of(context).size.width *
0.3,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 3,
),
),
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: const Text(
'Rating: 5.0',
style: TextStyle(
fontSize: 13,
color: Colors.blue,
),
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color:
Colors.black.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 2,
offset: const Offset(
0,
1,
),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.star,
color: Colors.yellow,
size: 20,
),
const SizedBox(width: 4),
Flexible(
child: Text(
average.toStringAsFixed(2),
style: const TextStyle(
fontSize: 15,
),
),
),
],
),
),
);
},
)
],
),
);
// Padding(
// padding: const EdgeInsets.symmetric(horizontal: 15),
// 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: const Text(
// 'Rating: 5.0',
// style: TextStyle(
// fontSize: 13,
// color: Colors.blue,
// ),
// ),
// ),
// );
}
}
},
@@ -129,6 +246,16 @@ class _ScoreScreenState extends State<ScoreScreen> {
},
ignoreGestures: false,
),
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
customMessage(_rating),
style: const TextStyle(
fontSize: 16,
color: Color(0xFF2BA4EC),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 40, vertical: 40),
@@ -226,6 +353,26 @@ class _ScoreScreenState extends State<ScoreScreen> {
);
}
String customMessage(double rating) {
if (rating > 4.0) {
return '¡Excelente! 👏🌟';
}
if (rating < 2.0) {
return '¡Malo! 😔❌';
}
if (rating <= 4.0 && rating >= 3.0) {
return '¡Bueno! 👍😊';
}
if (rating < 3.0 && rating >= 2.0) {
return '¡Regular! 😐🔄';
}
return '';
}
Future<List<dynamic>> _getUserAndProfessionalInfo(
ServiceEntity service) async {
final userRepo = FirebaseUserRepository(FirebaseAuth.instance);
@@ -233,9 +380,9 @@ class _ScoreScreenState extends State<ScoreScreen> {
final MyUser? userInfo;
if (FirebaseAuth.instance.currentUser!.uid == service.userId) {
userInfo = await userRepo.getMyUser(service.userId);
} else {
userInfo = await userRepo.getMyUser(service.professionalId);
} else {
userInfo = await userRepo.getMyUser(service.userId);
}
return [userInfo];