puntaje pro y cliente
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
import 'package:prosappco/src/components/photo_view.dart';
|
import 'package:prosappco/src/components/photo_view.dart';
|
||||||
|
import 'package:prosappco/src/models/score_model2.dart';
|
||||||
import 'package:prosappco/src/models/user_model.dart';
|
import 'package:prosappco/src/models/user_model.dart';
|
||||||
import 'package:prosappco/src/screens/profile.dart';
|
import 'package:prosappco/src/screens/profile.dart';
|
||||||
import 'package:prosappco/src/screens/prueba.dart';
|
import 'package:prosappco/src/screens/prueba.dart';
|
||||||
@@ -17,6 +18,7 @@ class DrawerMenu extends StatefulWidget {
|
|||||||
class _DrawerMenuState extends State<DrawerMenu> {
|
class _DrawerMenuState extends State<DrawerMenu> {
|
||||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||||
UserModel? user;
|
UserModel? user;
|
||||||
|
ScoresModel? scoresModel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -27,6 +29,12 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||||||
(UserModel s) => setState(() => user = s),
|
(UserModel s) => setState(() => user = s),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scoresModel == null) {
|
||||||
|
ScoresModel.scoreFrom(uid.toString(), false).then(
|
||||||
|
(ScoresModel s) => setState(() => scoresModel = s),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -50,11 +58,6 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
// if (ModalRoute.of(context)?.settings.name != '/profile') {
|
|
||||||
// Navigator.pushNamed(context, '/profile');
|
|
||||||
// } else {
|
|
||||||
// Scaffold.of(context).openEndDrawer();
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
title: Text(user?.name ?? '',
|
title: Text(user?.name ?? '',
|
||||||
style: const TextStyle(fontWeight: FontWeight.bold)),
|
style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||||
@@ -219,7 +222,7 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||||||
subtitle: Row(
|
subtitle: Row(
|
||||||
children: [
|
children: [
|
||||||
RatingBar.builder(
|
RatingBar.builder(
|
||||||
initialRating: user?.score?.average ?? 0,
|
initialRating: scoresModel?.average ?? 0,
|
||||||
minRating: 1,
|
minRating: 1,
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
allowHalfRating: true,
|
allowHalfRating: true,
|
||||||
@@ -237,7 +240,7 @@ class _DrawerMenuState extends State<DrawerMenu> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 5),
|
const SizedBox(width: 5),
|
||||||
Text(
|
Text(
|
||||||
'(${user?.score?.total.toString()}) ${user?.score?.average.toString()}'),
|
'(${scoresModel?.total.toString()}) ${scoresModel?.average.toString()}'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,20 +1,18 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:firebase_storage/firebase_storage.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
import 'package:prosappco/src/components/photo_view.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/models/user_model.dart';
|
||||||
import 'package:prosappco/src/screens/calendar.dart';
|
import 'package:prosappco/src/screens/calendar.dart';
|
||||||
import 'package:prosappco/src/screens/professional.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.dart';
|
||||||
import 'package:prosappco/src/screens/profile_pro.dart';
|
import 'package:prosappco/src/screens/profile_pro.dart';
|
||||||
import 'package:prosappco/src/screens/reputation.dart';
|
import 'package:prosappco/src/screens/reputation.dart';
|
||||||
|
|
||||||
|
import '../models/score_model2.dart';
|
||||||
|
|
||||||
class DrawerProfessional extends StatefulWidget {
|
class DrawerProfessional extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
State<DrawerProfessional> createState() => _DrawerProfessionalState();
|
State<DrawerProfessional> createState() => _DrawerProfessionalState();
|
||||||
@@ -23,6 +21,7 @@ class DrawerProfessional extends StatefulWidget {
|
|||||||
class _DrawerProfessionalState extends State<DrawerProfessional> {
|
class _DrawerProfessionalState extends State<DrawerProfessional> {
|
||||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||||
UserModel? user;
|
UserModel? user;
|
||||||
|
ScoresModel? scoresModel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -33,6 +32,12 @@ class _DrawerProfessionalState extends State<DrawerProfessional> {
|
|||||||
(UserModel s) => setState(() => user = s),
|
(UserModel s) => setState(() => user = s),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scoresModel == null) {
|
||||||
|
ScoresModel.scoreTo(uid.toString(), false).then(
|
||||||
|
(ScoresModel s) => setState(() => scoresModel = s),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -249,7 +254,7 @@ class _DrawerProfessionalState extends State<DrawerProfessional> {
|
|||||||
subtitle: Row(
|
subtitle: Row(
|
||||||
children: [
|
children: [
|
||||||
RatingBar.builder(
|
RatingBar.builder(
|
||||||
initialRating: user?.score?.average ?? 0,
|
initialRating: scoresModel?.average ?? 0,
|
||||||
minRating: 1,
|
minRating: 1,
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
allowHalfRating: true,
|
allowHalfRating: true,
|
||||||
@@ -267,7 +272,7 @@ class _DrawerProfessionalState extends State<DrawerProfessional> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 5),
|
const SizedBox(width: 5),
|
||||||
Text(
|
Text(
|
||||||
'(${user?.score?.total.toString()}) ${user?.score?.average.toString()}'),
|
'(${scoresModel?.total.toString()}) ${scoresModel?.average.toString()}'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
||||||
import 'package:firebase_storage/firebase_storage.dart';
|
|
||||||
|
|
||||||
class ScoreModel {
|
|
||||||
final int total;
|
|
||||||
final double average;
|
|
||||||
final List<ScoreDetailsModel> details;
|
|
||||||
|
|
||||||
ScoreModel(this.total, this.average, this.details);
|
|
||||||
|
|
||||||
static Future<ScoreModel> fromJson(
|
|
||||||
Map<String, dynamic>? json, bool requiredDetails) async {
|
|
||||||
try {
|
|
||||||
if (json == null) return ScoreModel(0, 0, []);
|
|
||||||
|
|
||||||
List<ScoreDetailsModel> list = [];
|
|
||||||
if (requiredDetails) {
|
|
||||||
for (var e in (json['detalles'] as List<dynamic>)) {
|
|
||||||
list.add(await ScoreDetailsModel.fromJson(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ScoreModel(
|
|
||||||
json['total'],
|
|
||||||
json['promedio'],
|
|
||||||
list,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
print('XD 54 $e');
|
|
||||||
return ScoreModel(0, 0, []);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ScoreDetailsModel {
|
|
||||||
final String name;
|
|
||||||
final Reference? avatar;
|
|
||||||
final double score;
|
|
||||||
final String comment;
|
|
||||||
|
|
||||||
ScoreDetailsModel(this.name, this.avatar, this.score, this.comment);
|
|
||||||
|
|
||||||
static Future<ScoreDetailsModel> fromJson(Map<String, dynamic>? json) async {
|
|
||||||
final FirebaseStorage storage = FirebaseStorage.instance;
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (json == null) return ScoreDetailsModel("", null, 0, "null");
|
|
||||||
var refUser =
|
|
||||||
(json['usuario_id'] as DocumentReference<Map<String, dynamic>>);
|
|
||||||
|
|
||||||
var data = await refUser.get();
|
|
||||||
|
|
||||||
var name = data.data()?["name"] ?? "no name";
|
|
||||||
|
|
||||||
Reference? avatarRef;
|
|
||||||
String? avatar = data.data()?["photo"];
|
|
||||||
if (avatar != null) {
|
|
||||||
avatarRef = storage.ref().child(avatar);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ScoreDetailsModel(
|
|
||||||
name,
|
|
||||||
avatarRef,
|
|
||||||
(json['puntaje'] is int) ? json['puntaje'].toDouble() : json['puntaje'],
|
|
||||||
json['comentario'] ?? "ISNULL",
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
print('XD $e');
|
|
||||||
return ScoreDetailsModel("", null, 0, "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||||
import 'package:firebase_storage/firebase_storage.dart';
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
import 'package:prosappco/src/models/score_model.dart';
|
|
||||||
import 'package:prosappco/src/screens/professional.dart';
|
import 'package:prosappco/src/screens/professional.dart';
|
||||||
|
|
||||||
class UserModel {
|
class UserModel {
|
||||||
@@ -8,13 +7,13 @@ class UserModel {
|
|||||||
final String city;
|
final String city;
|
||||||
final String? state;
|
final String? state;
|
||||||
final Reference? photo;
|
final Reference? photo;
|
||||||
final ScoreModel? score;
|
|
||||||
|
|
||||||
UserModel(this.name, this.city, this.state, this.photo, this.score);
|
UserModel(this.name, this.city, this.state, this.photo);
|
||||||
|
|
||||||
static Future<UserModel> fromJson(Map<String, dynamic>? json) async {
|
static Future<UserModel> fromJson(
|
||||||
|
Map<String, dynamic>? json, String uid) async {
|
||||||
try {
|
try {
|
||||||
if (json == null) return UserModel('', '', null, null, null);
|
if (json == null) return UserModel('', '', null, null);
|
||||||
|
|
||||||
String? avatar = json['photo'];
|
String? avatar = json['photo'];
|
||||||
return UserModel(
|
return UserModel(
|
||||||
@@ -22,11 +21,10 @@ class UserModel {
|
|||||||
json['city'],
|
json['city'],
|
||||||
json['estado'],
|
json['estado'],
|
||||||
avatar != null ? storage.ref().child(avatar) : null,
|
avatar != null ? storage.ref().child(avatar) : null,
|
||||||
await ScoreModel.fromJson(json['puntuacion'], false),
|
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('XD user $e');
|
print('XD user $e');
|
||||||
return UserModel('', '', null, null, null);
|
return UserModel('', '', null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,10 +33,10 @@ class UserModel {
|
|||||||
final snapshot =
|
final snapshot =
|
||||||
await FirebaseFirestore.instance.collection('users').doc(uid).get();
|
await FirebaseFirestore.instance.collection('users').doc(uid).get();
|
||||||
final Map<String, dynamic>? data = snapshot.data();
|
final Map<String, dynamic>? data = snapshot.data();
|
||||||
return fromJson(data);
|
return fromJson(data, uid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('Error getting user: $e');
|
print('Error getting user: $e');
|
||||||
return UserModel('', '', null, null, null);
|
return UserModel('', '', null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import 'package:intl/intl.dart';
|
|||||||
import 'package:prosappco/src/components/photo_view.dart';
|
import 'package:prosappco/src/components/photo_view.dart';
|
||||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||||
import 'package:prosappco/src/models/event_model.dart';
|
import 'package:prosappco/src/models/event_model.dart';
|
||||||
|
import 'package:prosappco/src/models/score_model2.dart';
|
||||||
import 'package:prosappco/src/models/user_model.dart';
|
import 'package:prosappco/src/models/user_model.dart';
|
||||||
|
|
||||||
class CitaScreen extends StatefulWidget {
|
class CitaScreen extends StatefulWidget {
|
||||||
@@ -21,6 +22,7 @@ class _CitaScreenState extends State<CitaScreen> {
|
|||||||
@override
|
@override
|
||||||
String nombre = '';
|
String nombre = '';
|
||||||
Reference? ref_photo;
|
Reference? ref_photo;
|
||||||
|
ScoresModel? scoresModel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -31,6 +33,11 @@ class _CitaScreenState extends State<CitaScreen> {
|
|||||||
(UserModel s) => setState(() => user = s),
|
(UserModel s) => setState(() => user = s),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if (scoresModel == null) {
|
||||||
|
ScoresModel.scoreFrom(uid.toString(), false).then(
|
||||||
|
(ScoresModel s) => setState(() => scoresModel = s),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -88,7 +95,7 @@ class _CitaScreenState extends State<CitaScreen> {
|
|||||||
subtitle: Row(
|
subtitle: Row(
|
||||||
children: [
|
children: [
|
||||||
RatingBar.builder(
|
RatingBar.builder(
|
||||||
initialRating: user?.score?.average ?? 0,
|
initialRating: scoresModel?.average ?? 0,
|
||||||
minRating: 1,
|
minRating: 1,
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
allowHalfRating: true,
|
allowHalfRating: true,
|
||||||
@@ -105,7 +112,7 @@ class _CitaScreenState extends State<CitaScreen> {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 5),
|
const SizedBox(width: 5),
|
||||||
Text(
|
Text(
|
||||||
'(${user?.score?.total.toString()}) ${user?.score?.average.toString()}'),
|
'(${scoresModel?.total.toString()}) ${scoresModel?.average.toString()}'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||||
import 'package:prosappco/src/components/photo_view.dart';
|
import 'package:prosappco/src/components/photo_view.dart';
|
||||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
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 'package:prosappco/src/screens/professional_info.dart';
|
||||||
|
|
||||||
import '../models/score_model2.dart';
|
import '../models/score_model2.dart';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||||
import 'package:prosappco/src/components/photo_view.dart';
|
import 'package:prosappco/src/components/photo_view.dart';
|
||||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||||
import 'package:prosappco/src/models/score_model.dart';
|
import 'package:prosappco/src/models/score_model2.dart';
|
||||||
import 'package:prosappco/src/screens/professional.dart';
|
import 'package:prosappco/src/screens/professional.dart';
|
||||||
|
|
||||||
class ReputationScreen extends StatelessWidget {
|
class ReputationScreen extends StatelessWidget {
|
||||||
@@ -22,17 +22,17 @@ class ReputationScreen extends StatelessWidget {
|
|||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
//..._scoresList(professional.puntuacion.details),
|
..._scoresList(professional.scores.scores),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Widget> _scoresList(List<ScoreDetailsModel> list) {
|
List<Widget> _scoresList(List<ScoreModel2> list) {
|
||||||
return list.map((e) => _scoreItem(e)).toList();
|
return list.map((e) => _scoreItem(e)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _scoreItem(ScoreDetailsModel scoreDetails) {
|
Widget _scoreItem(ScoreModel2 scoreDetails) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
leading: ReferencePhoto(
|
leading: ReferencePhoto(
|
||||||
|
|||||||
Reference in New Issue
Block a user