info de comentarios

This commit is contained in:
Juan Felipe Duarte
2023-04-17 12:47:27 -05:00
parent 672e7fc32f
commit e48d0a49d7
3 changed files with 39 additions and 17 deletions
+34 -12
View File
@@ -1,3 +1,6 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
class ScoreModel {
final int total;
final double average;
@@ -5,17 +8,19 @@ class ScoreModel {
ScoreModel(this.total, this.average, this.details);
factory ScoreModel.fromJson(Map<String, dynamic>? json) {
static Future<ScoreModel> fromJson(Map<String, dynamic>? json) async {
try {
if (json == null) return ScoreModel(0, 0, []);
List<ScoreDetailsModel> list = [];
for (var e in (json['detalles'] as List<dynamic>)) {
list.add(await ScoreDetailsModel.fromJson(e));
}
return ScoreModel(
json['total'],
json['promedio'],
(json['detalles'] as List<dynamic>?)
?.map((e) => ScoreDetailsModel.fromJson(e))
.toList() ??
[],
list,
);
} catch (e) {
print('XD 54 $e');
@@ -25,23 +30,40 @@ class ScoreModel {
}
class ScoreDetailsModel {
final String userId;
final String name;
final Reference? avatar;
final double score;
final String comment;
ScoreDetailsModel(this.userId, this.score, this.comment);
ScoreDetailsModel(this.name, this.avatar, this.score, this.comment);
static Future<ScoreDetailsModel> fromJson(Map<String, dynamic?>? json) async {
final FirebaseStorage storage = FirebaseStorage.instance;
factory ScoreDetailsModel.fromJson(Map<String, dynamic>? json) {
try {
if (json == null) return ScoreDetailsModel("no user", 0, "");
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(
json['usuario_id'],
name,
avatarRef,
(json['puntaje'] is int) ? json['puntaje'].toDouble() : json['puntaje'],
json['comentario'],
json['comentario'] ?? "ISNULL",
);
} catch (e) {
print('XD $e');
return ScoreDetailsModel("no user", 0, "");
return ScoreDetailsModel("", null, 0, "");
}
}
}
+1 -1
View File
@@ -84,7 +84,7 @@ Future<List<Professional>> getProfessionals() async {
professionalRef: storage.ref().child(_photo),
professionalEspecializado: especializaciones,
ubicacion: data['ubicacion'],
puntuacion: ScoreModel.fromJson(data['puntuacion']),
puntuacion: await ScoreModel.fromJson(data['puntuacion']),
);
professionals.add(professional);
}
+4 -4
View File
@@ -223,7 +223,7 @@ class _ProfessionalInfoScreenState extends State<ProfessionalInfoScreen> {
return ListTile(
onTap: () {},
leading: ReferencePhoto(
ref: widget.professional.professionalRef,
ref: scoreDetails.avatar,
size: 50,
sizeCircle: 50,
sizeIcon: 35,
@@ -258,9 +258,9 @@ class _ProfessionalInfoScreenState extends State<ProfessionalInfoScreen> {
child: Text.rich(
TextSpan(
children: [
const TextSpan(
text: 'name, ',
style: TextStyle(fontSize: 15, color: Colors.black),
TextSpan(
text: '${scoreDetails.name}, ',
style: const TextStyle(fontSize: 15, color: Colors.black),
),
TextSpan(
text: '"${scoreDetails.comment}"',