403 lines
17 KiB
Dart
403 lines
17 KiB
Dart
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';
|
|
import 'package:prosappco/screens/configuration/configuration_support_screen.dart';
|
|
import 'package:prosappco/screens/lists/professional_list_screen.dart';
|
|
import 'package:prosappco/screens/lists/professional_service_history_list_screen.dart';
|
|
import 'package:prosappco/screens/lists/professional_service_list_screen.dart';
|
|
import 'package:prosappco/screens/lists/user_service_history_list_screen.dart';
|
|
import 'package:prosappco/screens/lists/user_service_list_screen.dart';
|
|
import 'package:prosappco/screens/professional/professional_calendar_screen.dart';
|
|
import 'package:prosappco/screens/professional/professional_denied_screen.dart';
|
|
import 'package:prosappco/screens/professional/professional_form_screen.dart';
|
|
import 'package:prosappco/screens/professional/professional_pending_screen.dart';
|
|
import 'package:prosappco/screens/professional/professional_profile_screen.dart';
|
|
import 'package:prosappco/screens/professional/professional_services_screen.dart';
|
|
import 'package:prosappco/screens/profile/profile_screen.dart';
|
|
import 'package:prosappco/screens/user/user_history_services_screen.dart';
|
|
import 'package:prosappco/screens/web/web_view_screen.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
import 'package:user_repository/user_repository.dart';
|
|
|
|
class GeneralDrawer extends StatelessWidget {
|
|
const GeneralDrawer({super.key});
|
|
|
|
Future<void> _irSugerencias() async {
|
|
const url = 'https://admin.prosapp.co/sugerencias';
|
|
|
|
final Uri _url = Uri.parse(url);
|
|
|
|
if (await canLaunchUrl(_url)) {
|
|
await launchUrl(_url);
|
|
} else {
|
|
throw 'No se pudo abrir la URL $url';
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<MyUserBloc, MyUserState>(
|
|
builder: (context, userState) {
|
|
return BlocBuilder<ProfessionalBloc, ProfessionalState>(
|
|
builder: (context, professionalState) {
|
|
return Drawer(
|
|
backgroundColor: Theme.of(context).colorScheme.secondary,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
const GeneralDrawerHeader(),
|
|
Divider(
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.onSurface
|
|
.withOpacity(0.1),
|
|
thickness: 0.5,
|
|
height: 1,
|
|
),
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
shouldProModeActive(context, professionalState)
|
|
? GeneralDrawerItem(
|
|
leading: Icons.person_outline_rounded,
|
|
label: 'Perfil profesional',
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const ProfessionalProfileScreen(),
|
|
),
|
|
);
|
|
},
|
|
)
|
|
: const SizedBox(),
|
|
GeneralDrawerItem(
|
|
leading: Icons.checklist_outlined,
|
|
label: 'Mis servicios',
|
|
onTap: () {
|
|
shouldProModeActive(context, professionalState)
|
|
? Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const ProfessionalServiceListScreen(),
|
|
// const UserServicesScreen(),
|
|
),
|
|
)
|
|
: Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const UserServiceListScreen(),
|
|
// const UserServicesScreen(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
GeneralDrawerItem(
|
|
leading: Icons.access_time_outlined,
|
|
label: 'Historial',
|
|
onTap: () {
|
|
shouldProModeActive(context, professionalState)
|
|
? Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const ProfessionalServiceHistoryListScreen(),
|
|
),
|
|
)
|
|
: Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const UserServiceHistoryListScreen(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
shouldProModeActive(context, professionalState)
|
|
? GeneralDrawerItem(
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const ProfessionalCalendarScreen(),
|
|
),
|
|
);
|
|
},
|
|
label: 'Calendario',
|
|
leading: Icons.calendar_month_outlined,
|
|
)
|
|
: const SizedBox(),
|
|
GeneralDrawerItem(
|
|
leading: Icons.settings_outlined,
|
|
label: 'Configuración',
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const ConfigurationScreen(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
GeneralDrawerItem(
|
|
leading: Icons.help_outline,
|
|
label: 'Soporte',
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) =>
|
|
const ConfigurationSupportScreen(),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
GeneralDrawerItem(
|
|
leading: Icons.campaign_outlined,
|
|
label: 'Sugerencias',
|
|
onTap: () {
|
|
if (kIsWeb) {
|
|
_irSugerencias();
|
|
} else {
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (BuildContext context) {
|
|
return WebViewScreen(
|
|
label: 'Sugerencias',
|
|
link:
|
|
'https://admin.prosapp.co/sugerencias');
|
|
},
|
|
),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
Container(
|
|
color: const Color(0xFF2BA4EC),
|
|
child: ListTile(
|
|
onTap: () {
|
|
shouldProModeActive(context, professionalState)
|
|
? Navigator.pop(context)
|
|
: Navigator.pop(context);
|
|
},
|
|
trailing: const Icon(
|
|
Icons.keyboard_arrow_right,
|
|
color: Colors.white,
|
|
),
|
|
title: Text(
|
|
shouldProModeActive(context, professionalState)
|
|
? 'Solicitudes'
|
|
: 'Solicitar servicio',
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
color: Colors.white,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
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(
|
|
'Prosapp ® todos los derechos reservados',
|
|
style: TextStyle(
|
|
fontSize: 10,
|
|
color: Colors.grey[700],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Divider(
|
|
color: Theme.of(context)
|
|
.colorScheme
|
|
.onSurface
|
|
.withOpacity(0.1),
|
|
thickness: 0.5,
|
|
height: 1,
|
|
),
|
|
const SizedBox(height: 15),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: buttonOfState(context, professionalState),
|
|
),
|
|
const SizedBox(height: 15),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
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: () {
|
|
final myUserState = context.read<MyUserBloc>().state;
|
|
if (myUserState.status == MyUserStatus.success) {
|
|
final user = myUserState.user!;
|
|
|
|
if (user.name != null &&
|
|
user.email != null &&
|
|
user.city != null &&
|
|
user.phone != null) {
|
|
switch (user.proState) {
|
|
case ProState.active:
|
|
Navigator.pop(context);
|
|
|
|
context
|
|
.read<ProfessionalBloc>()
|
|
.add(const SwitchProModeEvent());
|
|
|
|
break;
|
|
case ProState.inactive:
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => const ProfessionalFormScreen(),
|
|
),
|
|
);
|
|
break;
|
|
case ProState.pending:
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => const ProfessionalPendingScreen(),
|
|
),
|
|
);
|
|
break;
|
|
case ProState.denied:
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => const ProfessionalDeniedScreen(),
|
|
),
|
|
);
|
|
break;
|
|
}
|
|
} else {
|
|
ScaffoldMessenger.of(context).clearSnackBars();
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
content: Text('Por favor, completa tu perfil'),
|
|
));
|
|
|
|
Navigator.push(
|
|
context,
|
|
CupertinoPageRoute(
|
|
builder: (context) => const ProfileScreen(),
|
|
),
|
|
);
|
|
}
|
|
} else {}
|
|
},
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
padding: const EdgeInsets.symmetric(vertical: 15),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
),
|
|
child: (state is LoadedModeProState)
|
|
? Text(
|
|
state.isProModeActive ? 'Modo cliente' : 'Modo profesional',
|
|
style: const TextStyle(color: Colors.white, fontSize: 18),
|
|
)
|
|
: const Text(
|
|
'Modo profesional',
|
|
style: TextStyle(color: Colors.white, fontSize: 18),
|
|
),
|
|
|
|
// const CircularProgressIndicator(
|
|
// color: Colors.white,
|
|
// ),
|
|
);
|
|
}
|
|
|
|
shouldProModeActive(BuildContext context, ProfessionalState state) {
|
|
return (state is LoadedModeProState) ? state.isProModeActive : false;
|
|
}
|
|
}
|