puntacion
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:prosappco/blocs/score_bloc/score_bloc.dart';
|
||||
import 'package:score_repository/score_repository.dart';
|
||||
|
||||
class DrawerReputation extends StatelessWidget {
|
||||
final Widget Function(ReputationEntity) builder;
|
||||
|
||||
const DrawerReputation({super.key, required this.builder});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ScoreBloc, ScoreState>(builder: (context, state) {
|
||||
if (state is ScoreSuccess) {
|
||||
return builder(state.reputation);
|
||||
} else if (state is ScoreFailure) {
|
||||
return const Center(child: Text('Error'));
|
||||
} else {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/professional_bloc/professional_bloc.dart';
|
||||
import 'package:prosappco/components/drawer_reputation.dart';
|
||||
import 'package:prosappco/components/general_drawer_header.dart';
|
||||
import 'package:prosappco/components/general_drawer_item.dart';
|
||||
import 'package:prosappco/screens/configuration/configuration_screen.dart';
|
||||
@@ -209,6 +214,51 @@ class GeneralDrawer extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
DrawerReputation(builder: (reputation) {
|
||||
final isProModeActive =
|
||||
(professionalState is LoadedModeProState) &&
|
||||
professionalState.isProModeActive;
|
||||
|
||||
final total = isProModeActive
|
||||
? reputation.totalPro
|
||||
: reputation.total;
|
||||
|
||||
final average = isProModeActive
|
||||
? reputation.averagePro
|
||||
: reputation.average;
|
||||
|
||||
return ListTile(
|
||||
onTap: () {},
|
||||
trailing: const Icon(Icons.keyboard_arrow_right,
|
||||
color: Colors.black),
|
||||
title: const Text(
|
||||
'Reputación',
|
||||
style: TextStyle(color: Colors.black),
|
||||
),
|
||||
subtitle: Row(
|
||||
children: [
|
||||
RatingBar.builder(
|
||||
initialRating: calculoRating(average),
|
||||
minRating: 1,
|
||||
direction: Axis.horizontal,
|
||||
allowHalfRating: true,
|
||||
itemCount: 5,
|
||||
itemSize: 25,
|
||||
maxRating: 5,
|
||||
itemBuilder: (context, _) => const Icon(
|
||||
Icons.star,
|
||||
color: Color(0xFF2BA4EC),
|
||||
),
|
||||
onRatingUpdate: (rating) {},
|
||||
ignoreGestures: true,
|
||||
),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
'${average.toStringAsFixed(1)} (${total.toString()})',
|
||||
),
|
||||
],
|
||||
));
|
||||
}),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
@@ -246,6 +296,23 @@ class GeneralDrawer extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
double calculoRating(double average) {
|
||||
String numeroString = average.toString();
|
||||
List<String> partes = numeroString.split('.');
|
||||
int parteEntera = int.parse(partes[0]);
|
||||
int parteFraccionaria = partes.length > 1 ? int.parse(partes[1]) : 0;
|
||||
|
||||
if (parteFraccionaria >= 3) {
|
||||
parteFraccionaria = 5;
|
||||
} else {
|
||||
parteFraccionaria = 0;
|
||||
}
|
||||
|
||||
// Unir la parte entera y fraccionaria y convertirlo nuevamente a double
|
||||
double resultado = double.parse('$parteEntera.$parteFraccionaria');
|
||||
return resultado;
|
||||
}
|
||||
|
||||
buttonOfState(BuildContext context, ProfessionalState state) {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:score_repository/score_repository.dart';
|
||||
|
||||
class GeneralReputation extends StatelessWidget {
|
||||
final String userId;
|
||||
final Widget Function(BuildContext, ReputationEntity) builder;
|
||||
|
||||
const GeneralReputation({
|
||||
super.key,
|
||||
required this.userId,
|
||||
required this.builder,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final repository = Injector.appInstance.get<FirebaseScoreRepository>();
|
||||
return FutureBuilder(
|
||||
future: repository.getReputationByUserId(userId),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError) {
|
||||
return Text('Error: ${snapshot.error}');
|
||||
} else {
|
||||
final reputation = snapshot.data!;
|
||||
return builder(context, reputation);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user