This commit is contained in:
Felipe
2024-04-18 18:29:41 -05:00
parent 8084d5fc7f
commit c874178019
12 changed files with 1042 additions and 557 deletions
@@ -79,8 +79,8 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
.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
@@ -183,12 +183,19 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
)
: null,
),
title: Text(
'${filteredUsers[index].myUser.name ?? ''}, ${filteredUsers[index].professionalInfo.profession}',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 15,
),
title: Row(
children: [
Flexible(
child: Text(
'${filteredUsers[index].myUser.name ?? ''}, ',
overflow: TextOverflow.ellipsis,
),
),
Text(
filteredUsers[index].professionalInfo.profession,
overflow: TextOverflow.ellipsis,
),
],
),
subtitle: Text(
_disponibilidad(filteredUsers[index].professionalInfo),
@@ -0,0 +1,151 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injector/injector.dart';
import 'package:prosappco/blocs/score_bloc/score_bloc.dart';
import 'package:shimmer/shimmer.dart';
class ProfessionalScoreListScreen extends StatefulWidget {
const ProfessionalScoreListScreen({super.key});
@override
State<ProfessionalScoreListScreen> createState() =>
_ProfessionalScoreListScreenState();
}
class _ProfessionalScoreListScreenState
extends State<ProfessionalScoreListScreen> {
late final ScoreBloc scoreBloc;
@override
void initState() {
super.initState();
scoreBloc = Injector.appInstance.get<ScoreBloc>();
scoreBloc.add(LoadScoresForProfessionalEvent(
userId: FirebaseAuth.instance.currentUser!.uid));
}
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => scoreBloc,
child: Scaffold(
appBar: AppBar(
title: const Text('Reputación'),
),
body: BlocBuilder<ScoreBloc, ScoreState>(
builder: (context, scoreState) {
if (scoreState is ScoresForUserLoaded) {
return scoreState.scores.isEmpty
? const Center(
child: Text('No tienes calificaciones'),
)
: ListView.builder(
itemCount: scoreState.scores.length,
itemBuilder: (_, index) {
final scoreInfo = scoreState.scores[index];
final score = scoreInfo.score;
final user = scoreInfo.user;
return Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.withOpacity(0.2)),
),
),
child: ListTile(
leading: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey.shade300,
shape: BoxShape.circle,
image: user.picture == null
? null
: DecorationImage(
image: NetworkImage(user.picture!),
fit: BoxFit.contain,
),
),
child: user.picture == null
? Icon(
CupertinoIcons.person,
color: Colors.grey.shade400,
size: 40,
)
: null,
),
title: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: Text(
'${user.name}',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 5),
Text(
'${score.createdAt.toDate().day}/${score.createdAt.toDate().month}/${score.createdAt.toDate().year}',
style: TextStyle(
color: Colors.grey[600],
),
),
],
),
subtitle: Text(
'"${score.content.trim()}"',
overflow: TextOverflow.ellipsis,
),
// icono de calificación
trailing: Text(
'${score.score}',
style: const TextStyle(
fontSize: 13,
),
),
),
);
},
);
}
return Shimmer.fromColors(
baseColor: Colors.grey[300]!,
highlightColor: Colors.grey[100]!,
child: ListView.builder(
itemCount: 10,
itemBuilder: (_, __) => ListTile(
leading: CircleAvatar(
backgroundColor: Colors.grey[300],
radius: 30,
),
title: Container(
height: 20,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(8),
),
),
subtitle: Container(
height: 15,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(8),
),
),
),
),
);
},
),
),
);
}
}
@@ -0,0 +1,150 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injector/injector.dart';
import 'package:intl/intl.dart';
import 'package:prosappco/blocs/score_bloc/score_bloc.dart';
import 'package:shimmer/shimmer.dart';
class UserScoreListScreen extends StatefulWidget {
const UserScoreListScreen({super.key});
@override
State<UserScoreListScreen> createState() => _UserScoreListScreenState();
}
class _UserScoreListScreenState extends State<UserScoreListScreen> {
late final ScoreBloc scoreBloc;
@override
void initState() {
super.initState();
scoreBloc = Injector.appInstance.get<ScoreBloc>();
scoreBloc.add(
LoadScoresForUserEvent(userId: FirebaseAuth.instance.currentUser!.uid));
}
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => scoreBloc,
child: Scaffold(
appBar: AppBar(
title: const Text('Reputación'),
),
body: BlocBuilder<ScoreBloc, ScoreState>(
builder: (context, scoreState) {
if (scoreState is ScoresForUserLoaded) {
return scoreState.scores.isEmpty
? const Center(
child: Text('No tienes calificaciones'),
)
: ListView.builder(
itemCount: scoreState.scores.length,
itemBuilder: (_, index) {
final scoreInfo = scoreState.scores[index];
final score = scoreInfo.score;
final user = scoreInfo.user;
return Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.withOpacity(0.2)),
),
),
child: ListTile(
leading: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: Colors.grey.shade300,
shape: BoxShape.circle,
image: user.picture == null
? null
: DecorationImage(
image: NetworkImage(user.picture!),
fit: BoxFit.contain,
),
),
child: user.picture == null
? Icon(
CupertinoIcons.person,
color: Colors.grey.shade400,
size: 40,
)
: null,
),
title: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: Text(
'${user.name}',
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 5),
Text(
'${score.createdAt.toDate().day}/${score.createdAt.toDate().month}/${score.createdAt.toDate().year}',
style: TextStyle(
color: Colors.grey[600],
),
),
],
),
subtitle: Text(
'"${score.content.trim()}"',
overflow: TextOverflow.ellipsis,
),
// icono de calificación
trailing: Text(
'${score.score}',
style: const TextStyle(
fontSize: 13,
),
),
),
);
},
);
}
return Shimmer.fromColors(
baseColor: Colors.grey[300]!,
highlightColor: Colors.grey[100]!,
child: ListView.builder(
itemCount: 10,
itemBuilder: (_, __) => ListTile(
leading: CircleAvatar(
backgroundColor: Colors.grey[300],
radius: 30,
),
title: Container(
height: 20,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(8),
),
),
subtitle: Container(
height: 15,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(8),
),
),
),
),
);
},
),
),
);
}
}
+306 -296
View File
@@ -43,319 +43,329 @@ class _ScoreScreenState extends State<ScoreScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Calificación'),
),
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
FutureBuilder(
future: _userInfoFuture,
builder: (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}'),
);
return BlocProvider(
create: (context) => Injector.appInstance.get<ScoreBloc>(),
child: Scaffold(
appBar: AppBar(
title: const Text('Calificación'),
),
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
FutureBuilder(
future: _userInfoFuture,
builder:
(context, AsyncSnapshot<List<dynamic>> snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator());
} else {
final userInfo = snapshot.data![0] as MyUser;
if (snapshot.hasError) {
return Center(
child:
Text('Error inesperado: ${snapshot.error}'),
);
} else {
final userInfo = snapshot.data![0] as MyUser;
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,
),
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.white,
borderRadius:
BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color:
Colors.black.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 2,
offset: const Offset(
0,
1,
),
),
],
color: Colors.grey.shade300,
shape: BoxShape.circle,
image: userInfo.picture == null
? null
: DecorationImage(
image: NetworkImage(
userInfo.picture!),
fit: BoxFit.contain,
),
),
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,
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,
),
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,
// ),
// ),
// ),
// );
);
},
)
],
),
);
// 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,
// ),
// ),
// ),
// );
}
}
}
},
),
const SizedBox(height: 10),
const Text(
'Califica el servicio',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
RatingBar.builder(
initialRating: _rating,
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemSize: 40,
glow: false,
maxRating: 5,
itemPadding: const EdgeInsets.symmetric(horizontal: 5),
itemBuilder: (context, _) => const Icon(
Icons.star,
color: Color(0xFF2BA4EC),
},
),
onRatingUpdate: (rating) {
setState(() {
_rating = rating;
});
},
ignoreGestures: false,
),
Padding(
padding: const EdgeInsets.only(top: 8),
child: Text(
customMessage(_rating),
style: const TextStyle(
fontSize: 16,
const SizedBox(height: 10),
const Text(
'Califica el servicio',
style:
TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
RatingBar.builder(
initialRating: _rating,
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemSize: 40,
glow: false,
maxRating: 5,
itemPadding: const EdgeInsets.symmetric(horizontal: 5),
itemBuilder: (context, _) => const Icon(
Icons.star,
color: Color(0xFF2BA4EC),
),
onRatingUpdate: (rating) {
setState(() {
_rating = rating;
});
},
ignoreGestures: false,
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 40, vertical: 40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Comentario',
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),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Comentario',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w600),
),
TextFormField(
maxLines: null,
maxLength: 400,
keyboardType: TextInputType.multiline,
controller: commentController,
),
],
),
),
],
),
),
),
const Divider(
height: 1,
thickness: 0.5,
),
BlocProvider<ServiceBloc>(
create: (context) => Injector.appInstance.get<ServiceBloc>(),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 15,
),
child: BlocBuilder<ServiceBloc, ServiceState>(
builder: (context, serviceState) {
return FilledButton(
onPressed: () {
final CommentEntity comment = widget.service.userId ==
FirebaseAuth.instance.currentUser!.uid
? CommentEntity(
serviceId: widget.service.id!,
authorId:
FirebaseAuth.instance.currentUser!.uid,
isFromUser: true,
score: _rating,
destinationId: widget.service.professionalId,
content: commentController.text.trim(),
createdAt: Timestamp.now(),
)
: CommentEntity(
serviceId: widget.service.id!,
authorId:
FirebaseAuth.instance.currentUser!.uid,
isFromUser: false,
score: _rating,
destinationId: widget.service.userId,
content: commentController.text.trim(),
createdAt: Timestamp.now(),
);
BlocProvider.of<ScoreBloc>(context)
.add(SendScoreEvent(comment: comment));
if (widget.service.userId ==
FirebaseAuth.instance.currentUser!.uid) {
context.read<ServiceBloc>().add(
UpdateProfessionalScored(widget.service.id!));
} else {
context
.read<ServiceBloc>()
.add(UpdateUserScored(widget.service.id!));
}
Navigator.pop(context);
},
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Container(
alignment: Alignment.center,
width: double.infinity,
child: const Text(
'Enviar calificación',
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w600),
),
TextFormField(
maxLines: null,
maxLength: 400,
keyboardType: TextInputType.multiline,
controller: commentController,
),
],
),
),
],
),
),
),
const Divider(
height: 1,
thickness: 0.5,
),
BlocProvider<ServiceBloc>(
create: (context) => Injector.appInstance.get<ServiceBloc>(),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 15,
),
child: BlocBuilder<ServiceBloc, ServiceState>(
builder: (context, state) {
return FilledButton(
onPressed: () {
final CommentEntity comment = widget.service.userId ==
FirebaseAuth.instance.currentUser!.uid
? CommentEntity(
serviceId: widget.service.id!,
authorId: FirebaseAuth.instance.currentUser!.uid,
isFromUser: true,
score: _rating,
destinationId: widget.service.professionalId,
content: commentController.text.trim(),
createdAt: Timestamp.now(),
)
: CommentEntity(
serviceId: widget.service.id!,
authorId: FirebaseAuth.instance.currentUser!.uid,
isFromUser: false,
score: _rating,
destinationId: widget.service.userId,
content: commentController.text.trim(),
createdAt: Timestamp.now(),
);
BlocProvider.of<ScoreBloc>(context)
.add(SendScoreEvent(comment: comment));
if (widget.service.userId ==
FirebaseAuth.instance.currentUser!.uid) {
context
.read<ServiceBloc>()
.add(UpdateProfessionalScored(widget.service.id!));
} else {
context
.read<ServiceBloc>()
.add(UpdateUserScored(widget.service.id!));
}
Navigator.pop(context);
},
style: FilledButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.primary,
padding: const EdgeInsets.symmetric(vertical: 15),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Container(
alignment: Alignment.center,
width: double.infinity,
child: const Text(
'Enviar calificación',
style: TextStyle(
color: Colors.white,
fontSize: 18,
color: Colors.white,
fontSize: 18,
),
),
),
),
);
},
);
},
),
),
),
),
],
],
),
),
);
}