puntaje pro

This commit is contained in:
Juan Felipe Duarte
2023-04-26 16:55:58 -05:00
parent 0a70d40d2d
commit c1747a45b9
12 changed files with 781 additions and 436 deletions
+9 -1
View File
@@ -7,6 +7,7 @@ import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/photo_view.dart';
import 'package:prosappco/src/models/user_model.dart';
import 'package:prosappco/src/screens/profile.dart';
import 'package:prosappco/src/screens/prueba.dart';
class DrawerMenu extends StatefulWidget {
@override
@@ -292,7 +293,14 @@ class _DrawerMenuState extends State<DrawerMenu> {
} else if (user?.state == 'revision') {
Navigator.pushNamed(context, '/profesionalRevision');
} else if (user?.state == 'activo') {
Navigator.pushNamed(context, '/profilePro');
Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return const PruebaScreen();
},
),
);
}
},
style: ElevatedButton.styleFrom(
+30 -2
View File
@@ -1,3 +1,4 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/cupertino.dart';
@@ -5,9 +6,14 @@ import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/photo_view.dart';
import 'package:prosappco/src/models/score_model.dart';
import 'package:prosappco/src/models/user_model.dart';
import 'package:prosappco/src/screens/calendar.dart';
import 'package:prosappco/src/screens/professional.dart';
import 'package:prosappco/src/screens/professional_profile.dart';
import 'package:prosappco/src/screens/profile.dart';
import 'package:prosappco/src/screens/profile_pro.dart';
import 'package:prosappco/src/screens/reputation.dart';
class DrawerProfessional extends StatefulWidget {
@override
@@ -112,7 +118,16 @@ class _DrawerProfessionalState extends State<DrawerProfessional> {
),
),
ListTile(
onTap: () {},
onTap: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return const ProfilePro();
},
),
);
},
leading: const Icon(
Icons.person_outline,
color: Colors.black,
@@ -211,7 +226,20 @@ class _DrawerProfessionalState extends State<DrawerProfessional> {
child: Container(
color: Colors.white,
child: ListTile(
onTap: () {},
onTap: () async {
var professional =
await Professional.getProfessional(uid!);
Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return ReputationScreen(
professional: professional!);
},
),
);
},
trailing: const Icon(Icons.keyboard_arrow_right,
color: Colors.black),
title: const Text(
+6 -6
View File
@@ -13,7 +13,7 @@ class EventoService {
) async {
try {
await FirebaseFirestore.instance.collection('services').add({
'profesional_id': uid,
'user_id': uid,
'title': title,
'description': description,
'day': day,
@@ -34,7 +34,7 @@ Future<List<Event>> getByProId(String day) async {
try {
var snapshot = await FirebaseFirestore.instance
.collection('services')
.where('profesional_id', isEqualTo: uid)
.where('user_id', isEqualTo: uid)
.where('day', isEqualTo: day.toString())
.get();
@@ -56,7 +56,7 @@ class Event {
String? day;
String? range1Hour1;
String? range1Hour2;
String? profesionalId;
String? userId;
Event({
this.title,
@@ -64,7 +64,7 @@ class Event {
this.day,
this.range1Hour1,
this.range1Hour2,
this.profesionalId,
this.userId,
});
factory Event.fromJson(Map<String, dynamic> json) {
@@ -74,7 +74,7 @@ class Event {
day: json['day'],
range1Hour1: json['range1Hour1'],
range1Hour2: json['range1Hour2'],
profesionalId: json['profesional_id'],
userId: json['user_id'],
);
}
@@ -82,7 +82,7 @@ class Event {
try {
var snapshot = await FirebaseFirestore.instance
.collection('services')
.where('profesional_id', isEqualTo: uid)
.where('user_id', isEqualTo: uid)
.get();
List<Event> eventos = [];
+95
View File
@@ -0,0 +1,95 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:prosappco/src/models/user_model.dart';
class ScoresModel {
late int total;
late double average;
final List<ScoreModel2> scores;
ScoresModel(this.scores) {
total = scores.length;
average = averageScore(scores);
}
double averageScore(List<ScoreModel2> scores) {
if (scores.isEmpty) {
return 0.0;
}
final sum = scores.map((score) => score.score).reduce((a, b) => a + b);
return sum / scores.length;
}
// Me
static Future<ScoresModel> scoreTo(String userReceived, bool userInfo) async {
final receivedScoresQuery = FirebaseFirestore.instance
.collection('scores')
.where('to_user', isEqualTo: userReceived);
final receivedScoresSnapshot = await receivedScoresQuery.get();
final receivedScores = await Future.wait(receivedScoresSnapshot.docs
.map((doc) async =>
await ScoreModel2.fromDocumentSnapshot(doc, userInfo))
.toList());
return ScoresModel(receivedScores);
}
// You
static Future<ScoresModel> scoreFrom(String userGiven, bool userInfo) async {
final givenScoresQuery = FirebaseFirestore.instance
.collection('scores')
.where('from_user', isEqualTo: userGiven);
final givenScoresSnapshot = await givenScoresQuery.get();
final givenScores = await Future.wait(givenScoresSnapshot.docs
.map((doc) async =>
await ScoreModel2.fromDocumentSnapshot(doc, userInfo))
.toList());
return ScoresModel(givenScores);
}
}
class ScoreModel2 {
final String id;
final double score;
final String fromUser;
final String toUser;
final String comment;
final String name;
final Reference? avatar;
ScoreModel2({
required this.id,
required this.score,
required this.fromUser,
required this.toUser,
required this.comment,
required this.name,
required this.avatar,
});
static Future<ScoreModel2> fromDocumentSnapshot(
DocumentSnapshot<Map<String, dynamic>> snapshot, bool userInfo) async {
try {
final Map<String, dynamic> data = snapshot.data()!;
final user = userInfo ? await UserModel.getUser(data['from_user']) : null;
return ScoreModel2(
id: snapshot.id,
score: double.parse(data['score'].toString()),
fromUser: data['from_user'],
toUser: data['to_user'],
comment: data['comment'],
name: user?.name ?? "...",
avatar: user?.photo);
} catch (e) {
print('error en score $e');
rethrow;
}
}
}
+24 -9
View File
@@ -1,11 +1,10 @@
import 'dart:ffi';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/components/primary_btn.dart';
import 'package:prosappco/src/models/event_model.dart';
import 'package:prosappco/src/screens/cita.dart';
import 'package:table_calendar/table_calendar.dart';
import 'package:intl/intl.dart';
@@ -90,8 +89,7 @@ class _CalendarScreenState extends State<CalendarScreen> {
// DateTime firstDay = today.subtract(Duration(days: 365));
DateTime lastDay = today.add(const Duration(days: 365));
return SafeArea(
child: Scaffold(
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: PopAppbar(
onPressed: () {
@@ -148,7 +146,6 @@ class _CalendarScreenState extends State<CalendarScreen> {
onPressed: _showDialog,
child: const Icon(Icons.add),
),
),
);
}
@@ -329,7 +326,7 @@ class _CalendarScreenState extends State<CalendarScreen> {
try {
eventos.addAll(snapshot.data!);
} catch (e) {
print("Hola" + e.toString());
print("Error" + e.toString());
}
if (eventos.isEmpty) {
@@ -339,6 +336,24 @@ class _CalendarScreenState extends State<CalendarScreen> {
children: [
...eventos.map(
(e) => ListTile(
onTap: () {
final evento = Event(
day: e.day,
description: e.description,
userId: e.userId,
range1Hour1: e.range1Hour1,
range1Hour2: e.range1Hour2,
title: e.title,
);
Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return CitaScreen(evento: evento);
},
),
);
},
leading: Text('${e.range1Hour1}'),
title: RichText(
text: TextSpan(
@@ -354,8 +369,8 @@ class _CalendarScreenState extends State<CalendarScreen> {
TextSpan(
text: DateFormat('dd MMM', 'es')
.format(DateTime.parse(e.day!)),
style: TextStyle(
color: Colors.grey[400],
style: const TextStyle(
color: Colors.grey,
fontSize: 16,
),
),
+149
View File
@@ -0,0 +1,149 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:intl/intl.dart';
import 'package:prosappco/src/components/photo_view.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/models/event_model.dart';
import 'package:prosappco/src/models/user_model.dart';
class CitaScreen extends StatefulWidget {
final Event evento;
const CitaScreen({super.key, required this.evento});
@override
State<CitaScreen> createState() => _CitaScreenState();
}
class _CitaScreenState extends State<CitaScreen> {
UserModel? user;
@override
String nombre = '';
Reference? ref_photo;
@override
void initState() {
super.initState();
if (user == null) {
UserModel.getUser(uid.toString()).then(
(UserModel s) => setState(() => user = s),
);
}
}
Widget build(BuildContext context) {
if (nombre == '') {
UserModel.getUser(widget.evento.userId!).then((value) {
setState(() {
nombre = value.name;
ref_photo = value.photo;
});
});
}
final User? currentUser = FirebaseAuth.instance.currentUser;
return Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Servicio'),
body: Column(
children: [
Expanded(
child: Column(
children: [
ListTile(
leading: ReferencePhoto(
ref: ref_photo,
size: 50,
sizeCircle: 50,
sizeIcon: 35,
),
title: RichText(
text: TextSpan(
children: [
TextSpan(
text: '${nombre}, ',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
TextSpan(
text:
'${DateFormat('dd MMM', 'es').format(DateTime.parse(widget.evento.day!))} ${widget.evento.range1Hour1}',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
),
),
],
),
),
subtitle: Row(
children: [
RatingBar.builder(
initialRating: user?.score?.average ?? 0,
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemSize: 25,
maxRating: 5,
itemPadding: const EdgeInsets.symmetric(horizontal: 0),
itemBuilder: (context, _) => const Icon(
Icons.star,
color: Color(0xFF2BA4EC),
),
onRatingUpdate: (rating) {},
ignoreGestures: true,
),
const SizedBox(width: 5),
Text(
'(${user?.score?.total.toString()}) ${user?.score?.average.toString()}'),
],
),
),
Text(
textAlign: TextAlign.center,
'" ${widget.evento.description} "',
style: TextStyle(
color: Colors.grey, fontStyle: FontStyle.italic),
)
],
),
),
Center(
child: Padding(
padding: const EdgeInsets.only(bottom: 30),
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFFEC2B2B),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
elevation: 0,
minimumSize: const Size(230, 60),
),
child: const Text(
'Cancelar servicio',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
),
),
],
),
);
}
}
+41 -3
View File
@@ -9,6 +9,8 @@ import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/models/score_model.dart';
import 'package:prosappco/src/screens/professional_info.dart';
import '../models/score_model2.dart';
class ProfessionalScreen extends StatefulWidget {
const ProfessionalScreen({super.key});
@@ -29,7 +31,7 @@ class Professional {
final String cityName;
final String ubicacion;
final List<String> professionalEspecializado;
final ScoreModel puntuacion;
final ScoresModel scores;
Professional({
required this.professionalRef,
@@ -38,7 +40,7 @@ class Professional {
required this.cityName,
required this.ubicacion,
required this.professionalEspecializado,
required this.puntuacion,
required this.scores,
});
String getEspecializaciones() {
@@ -56,6 +58,42 @@ class Professional {
' professionalEspecializado: ${getEspecializaciones()}\n'
'}';
}
static Future<Professional?> getProfessional(String uid) async {
var photo = '...';
final FirebaseStorage storage = FirebaseStorage.instance;
try {
DocumentSnapshot user =
await FirebaseFirestore.instance.collection('users').doc(uid).get();
Map<String, dynamic> data = user.data() as Map<String, dynamic>;
photo = await AuthenticationRepository.instance.getPhoto(user.id);
if (data['estado'] == 'activo') {
List<String> especializaciones;
especializaciones = (data['especializaciones'] as List<dynamic>)
.map((e) => e.toString())
.toList();
Professional professional = Professional(
name: data['name'],
professionName: data['profesion'],
cityName: data['city'],
professionalRef: storage.ref().child(photo),
professionalEspecializado: especializaciones,
ubicacion: data['ubicacion'] ?? '',
scores: await ScoresModel.scoreFrom(uid, true),
);
return professional;
}
} catch (e) {
print('Error al obtener profesionales: $e');
}
return null;
}
}
Future<List<Professional>> getProfessionals() async {
@@ -84,7 +122,7 @@ Future<List<Professional>> getProfessionals() async {
professionalRef: storage.ref().child(_photo),
professionalEspecializado: especializaciones,
ubicacion: data['ubicacion'] ?? '',
puntuacion: await ScoreModel.fromJson(data['puntuacion'], true),
scores: await ScoresModel.scoreTo(user.id, true),
);
professionals.add(professional);
}
+7 -8
View File
@@ -1,13 +1,13 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:prosappco/src/components/photo_view.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/models/score_model.dart';
import 'package:prosappco/src/screens/professional.dart';
import 'package:prosappco/src/screens/reputation.dart';
import '../models/score_model2.dart';
class ProfessionalInfoScreen extends StatefulWidget {
Professional professional;
@@ -153,8 +153,7 @@ class _ProfessionalInfoScreenState extends State<ProfessionalInfoScreen> {
subtitle: Row(
children: [
RatingBar.builder(
initialRating:
widget.professional.puntuacion.average,
initialRating: widget.professional.scores.average,
minRating: 1,
direction: Axis.horizontal,
allowHalfRating: true,
@@ -172,12 +171,12 @@ class _ProfessionalInfoScreenState extends State<ProfessionalInfoScreen> {
),
const SizedBox(width: 5),
Text(
'(${widget.professional.puntuacion.total.toString()}) ${widget.professional.puntuacion.average.toString()}'),
'(${widget.professional.scores.total.toString()}) ${widget.professional.scores.average.toString()}'),
],
),
),
),
..._scoresList(widget.professional.puntuacion.details),
..._scoresList(widget.professional.scores.scores),
const SizedBox(
height: 10,
),
@@ -202,11 +201,11 @@ class _ProfessionalInfoScreenState extends State<ProfessionalInfoScreen> {
);
}
List<Widget> _scoresList(List<ScoreDetailsModel> list) {
List<Widget> _scoresList(List<ScoreModel2> list) {
return list.map((e) => _scoreItem(e)).toList();
}
Widget _scoreItem(ScoreDetailsModel scoreDetails) {
Widget _scoreItem(ScoreModel2 scoreDetails) {
return ListTile(
onTap: () {},
leading: ReferencePhoto(
+2 -5
View File
@@ -341,8 +341,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
Widget build(BuildContext context) {
String city = _ciudad.toString();
return SafeArea(
child: Scaffold(
return Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
@@ -409,8 +408,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
controller: _passwordController,
obscureText: _obscureText,
decoration: InputDecoration(
prefixIcon:
const Icon(Icons.lock_outline),
prefixIcon: const Icon(Icons.lock_outline),
suffixIcon: IconButton(
icon: Icon(
_obscureText
@@ -506,7 +504,6 @@ class _ProfileScreenState extends State<ProfileScreen> {
),
),
),
),
);
}
}
+12 -23
View File
@@ -10,6 +10,7 @@ import 'package:get/get.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/banner_photo.dart';
import 'package:prosappco/src/components/drawer_professional.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/components/primary_btn.dart';
import 'package:prosappco/src/components/schedule_picker.dart';
import 'package:prosappco/src/screens/horario.dart';
@@ -258,21 +259,12 @@ class _ProfileProState extends State<ProfilePro> {
Widget build(BuildContext context) {
String address = _direccion.toString();
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
iconTheme: const IconThemeData(
color: Colors.black,
),
title: const Text(
'Perfil profesional',
style: TextStyle(
color: Colors.black,
),
),
),
drawer: DrawerProfessional(),
return Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Perfil profesional'),
body: SingleChildScrollView(
reverse: true,
child: Column(
@@ -312,8 +304,8 @@ class _ProfileProState extends State<ProfilePro> {
),
sitioValue
? Padding(
padding: const EdgeInsets.only(
left: 40, right: 40, bottom: 15),
padding:
const EdgeInsets.only(left: 40, right: 40, bottom: 15),
child: Column(
children: [
TextFormField(
@@ -341,8 +333,7 @@ class _ProfileProState extends State<ProfilePro> {
hintStyle: address == ''
? const TextStyle()
: const TextStyle(color: Colors.black87),
hintText:
address == '' ? 'Dirección' : address),
hintText: address == '' ? 'Dirección' : address),
),
const SizedBox(height: 10),
TextFormField(
@@ -444,8 +435,7 @@ class _ProfileProState extends State<ProfilePro> {
children: [
Text(timeList(_horarios?['Lunes'], context)),
Text(timeList(_horarios?['Martes'], context)),
Text(
timeList(_horarios?['Miercoles'], context)),
Text(timeList(_horarios?['Miercoles'], context)),
Text(timeList(_horarios?['Jueves'], context)),
Text(timeList(_horarios?['Viernes'], context)),
Text(timeList(_horarios?['Sabado'], context)),
@@ -470,7 +460,6 @@ class _ProfileProState extends State<ProfilePro> {
],
),
),
),
);
}
@@ -515,7 +504,7 @@ class _ProfileProState extends State<ProfilePro> {
return 'N/A';
}
if (schedule.jornadaContinua) {
return '${schedule.range1Hour1?.format(context).toString()} - ${schedule.range1Hour2?.format(context).toString()}';
return '${schedule.range1Hour1?.format(context).toString()} - ${schedule.range2Hour2?.format(context).toString()}';
} else {
return '${schedule.range1Hour1?.format(context).toString()} - ${schedule.range1Hour2?.format(context).toString()}; ${schedule.range2Hour1?.format(context).toString()} - ${schedule.range2Hour2?.format(context).toString()}';
}
+27
View File
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:prosappco/src/components/drawer_professional.dart';
class PruebaScreen extends StatelessWidget {
const PruebaScreen({super.key});
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
iconTheme: const IconThemeData(
color: Colors.black,
),
title: const Text(
'Prueba',
style: TextStyle(
color: Colors.black,
),
),
),
drawer: DrawerProfessional(),
),
);
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ class ReputationScreen extends StatelessWidget {
body: SingleChildScrollView(
child: Column(
children: [
..._scoresList(professional.puntuacion.details),
//..._scoresList(professional.puntuacion.details),
],
)),
));