fix: port 7 web features and repair the endless-loading screens
Root cause behind most "stuck loading" reports: the backend changed shape (schedules became an array, location_preferences a string) while the mobile parser still hard-cast to Map/int. The TypeError was swallowed by a silent catch that returned null, and screens only handled the success state, so a parse failure rendered as a permanent spinner. Same class of bug appeared across service lists via non-null map lookups and a total absence of request timeouts. Ported from prosappweb: - in-app suggestions (POST /suggestions) - policies/terms from GET /settings/policies - configurable appointment length (slot_duration_minutes) - block/unblock calendar slots (POST /services/block) - GPS city detection on the profile (Nominatim) - server-side professional search with haversine distance - retry cooldown after a rejected professional application Reliability: - parse schedules array (day_of_week 0=Mon) and string location_preferences - read times as wall clock, so 08:00 stays 08:00 across timezones - carry minutes into hours in TimeOfDay.add; a minute-based step used to loop forever and freeze the calendar (covered by test/time_slots_test.dart) - semver update check instead of string equality, which blocked every build that did not exactly match the configured version - request timeouts across all repositories - surface HTTP >= 400 instead of reporting failed writes as success - error states with retry instead of an indefinite shimmer Includes pre-existing uncommitted work from the UI redesign. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
06a89df690
commit
8631e6f729
@@ -22,6 +22,9 @@ class ProfessionalBloc extends Bloc<ProfessionalEvent, ProfessionalState> {
|
||||
bool isProModeActive = _professionalRepository.isProModeActive;
|
||||
final proInfo = _professionalRepository.lastProInfo();
|
||||
emit(LoadedModeProState(isProModeActive, proInfo));
|
||||
if (isProModeActive && proInfo == null) {
|
||||
_fetchMyProInfo();
|
||||
}
|
||||
|
||||
_professionalRepository.streamProInfo().listen((proInfo) {
|
||||
if (proInfo == null) {
|
||||
@@ -40,14 +43,33 @@ class ProfessionalBloc extends Bloc<ProfessionalEvent, ProfessionalState> {
|
||||
await _professionalRepository.switchProMode();
|
||||
});
|
||||
|
||||
on<ResetProfessionalApplicationEvent>((event, emit) async {
|
||||
emit(ResetProfessionalApplicationLoading());
|
||||
try {
|
||||
await _professionalRepository.deleteProfessionalInfo();
|
||||
emit(ResetProfessionalApplicationSuccess());
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
emit(ProfessionalStateFailure(message: e.toString()));
|
||||
}
|
||||
});
|
||||
|
||||
on<UpdateProfessionalEvent>((event, emit) async {
|
||||
final proInfo = _professionalRepository.lastProInfo();
|
||||
emit(LoadedModeProState(event.isProModeActive, proInfo));
|
||||
if (event.isProModeActive && proInfo == null) {
|
||||
await _fetchMyProInfo();
|
||||
}
|
||||
});
|
||||
|
||||
on<SendProfessionalToReviewEvent>((event, emit) async {
|
||||
emit(SendProfessionalToReviewLoading());
|
||||
final myUser = await _userRepository.lastUser();
|
||||
if (myUser == null) return;
|
||||
if (myUser == null) {
|
||||
emit(const SendProfessionalToReviewFailure(
|
||||
message: 'No se pudo identificar tu usuario'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final identificationPdfUrl = await _professionalRepository
|
||||
.uploadPdfCedula(event.identificationPicture, myUser.id);
|
||||
@@ -83,10 +105,18 @@ class ProfessionalBloc extends Bloc<ProfessionalEvent, ProfessionalState> {
|
||||
schedules: Schedules.empty,
|
||||
paymentMethods: PaymentMethodEntity.empty,
|
||||
));
|
||||
|
||||
emit(SendProfessionalToReviewSuccess());
|
||||
} catch (e) {
|
||||
log('error acceso a pro ${e.toString()}');
|
||||
emit(SendProfessionalToReviewFailure(message: e.toString()));
|
||||
}
|
||||
// _userRepository.updateUserInfo(myUser.copyWith(proState: ProState.pending));
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _fetchMyProInfo() async {
|
||||
final myUser = await _userRepository.lastUser();
|
||||
if (myUser == null) return;
|
||||
await _professionalRepository.updateFromFirebase(userId: myUser.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,10 @@ class SwitchProModeEvent extends ProfessionalEvent {
|
||||
const SwitchProModeEvent();
|
||||
}
|
||||
|
||||
class ResetProfessionalApplicationEvent extends ProfessionalEvent {
|
||||
const ResetProfessionalApplicationEvent();
|
||||
}
|
||||
|
||||
class SendProfessionalToReviewEvent extends ProfessionalEvent {
|
||||
final String id;
|
||||
final String identification;
|
||||
|
||||
@@ -17,6 +17,23 @@ class ProfessionalStateFailure extends ProfessionalState {
|
||||
|
||||
class ProfessionalStateProcess extends ProfessionalState {}
|
||||
|
||||
class ResetProfessionalApplicationLoading extends ProfessionalState {}
|
||||
|
||||
class ResetProfessionalApplicationSuccess extends ProfessionalState {}
|
||||
|
||||
class SendProfessionalToReviewLoading extends ProfessionalState {}
|
||||
|
||||
class SendProfessionalToReviewSuccess extends ProfessionalState {}
|
||||
|
||||
class SendProfessionalToReviewFailure extends ProfessionalState {
|
||||
final String? message;
|
||||
|
||||
const SendProfessionalToReviewFailure({this.message});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class LoadedModeProState extends ProfessionalState {
|
||||
final bool isProModeActive;
|
||||
final ProfessionalEntity? proInfo;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:professional_repository/professional_repository.dart';
|
||||
@@ -24,27 +26,76 @@ class ProfessionalListBloc
|
||||
emit(ProfessionalListLoading());
|
||||
final users = await _userRepository.getUsersProfessionalActive();
|
||||
|
||||
final professionals =
|
||||
await _firebaseProfessionalRepository.getProfessionalInfo();
|
||||
final hasSearchParams = event.search != null ||
|
||||
event.city != null ||
|
||||
event.lat != null ||
|
||||
event.lng != null;
|
||||
|
||||
final professionalInfoMap = {for (var doc in professionals) doc.id: doc};
|
||||
if (!hasSearchParams) {
|
||||
final professionals =
|
||||
await _firebaseProfessionalRepository.getProfessionalInfo();
|
||||
|
||||
final usersMap = users
|
||||
.map((user) => UserProfessional(
|
||||
myUser: user,
|
||||
professionalInfo: professionalInfoMap[user.id]!,
|
||||
final professionalInfoMap = {for (var doc in professionals) doc.id: doc};
|
||||
|
||||
final usersMap = users
|
||||
.where((user) => professionalInfoMap.containsKey(user.id))
|
||||
.map((user) => UserProfessional(
|
||||
myUser: user,
|
||||
professionalInfo: professionalInfoMap[user.id]!,
|
||||
))
|
||||
.toList();
|
||||
|
||||
emit(ProfessionalListSuccess(users: usersMap));
|
||||
return;
|
||||
}
|
||||
|
||||
final usersDir = {for (var u in users) u.id: u};
|
||||
|
||||
final professionals = await _firebaseProfessionalRepository.searchProfessionals(
|
||||
search: event.search,
|
||||
city: event.city,
|
||||
lat: event.lat,
|
||||
lng: event.lng,
|
||||
);
|
||||
|
||||
final usersMap = professionals
|
||||
.where((p) => usersDir.containsKey(p.id))
|
||||
.map((p) => UserProfessional(
|
||||
myUser: usersDir[p.id]!,
|
||||
professionalInfo: p,
|
||||
distanceKm: (event.lat != null && event.lng != null)
|
||||
? _haversineKm(event.lat!, event.lng!, p.latitude, p.longitude)
|
||||
: null,
|
||||
))
|
||||
.toList();
|
||||
|
||||
emit(ProfessionalListSuccess(users: usersMap));
|
||||
}
|
||||
|
||||
double? _haversineKm(double lat1, double lng1, double lat2, double lng2) {
|
||||
if (lat2 == 0.0 && lng2 == 0.0) return null;
|
||||
const r = 6371.0;
|
||||
final dLat = (lat2 - lat1) * math.pi / 180;
|
||||
final dLng = (lng2 - lng1) * math.pi / 180;
|
||||
final a = math.sin(dLat / 2) * math.sin(dLat / 2) +
|
||||
math.cos(lat1 * math.pi / 180) *
|
||||
math.cos(lat2 * math.pi / 180) *
|
||||
math.sin(dLng / 2) *
|
||||
math.sin(dLng / 2);
|
||||
return r * 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a));
|
||||
}
|
||||
}
|
||||
|
||||
class UserProfessional {
|
||||
final MyUser myUser;
|
||||
final ProfessionalEntity professionalInfo;
|
||||
final double? distanceKm;
|
||||
|
||||
UserProfessional({required this.myUser, required this.professionalInfo});
|
||||
UserProfessional({
|
||||
required this.myUser,
|
||||
required this.professionalInfo,
|
||||
this.distanceKm,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
@@ -8,8 +8,18 @@ abstract class ProfessionalListEvent extends Equatable {
|
||||
}
|
||||
|
||||
class ProfessionalListFetch extends ProfessionalListEvent {
|
||||
const ProfessionalListFetch();
|
||||
final String? search;
|
||||
final String? city;
|
||||
final double? lat;
|
||||
final double? lng;
|
||||
|
||||
const ProfessionalListFetch({this.search, this.city, this.lat, this.lng});
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object> get props => [
|
||||
search ?? '',
|
||||
city ?? '',
|
||||
lat ?? 0,
|
||||
lng ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ class ProfessionalProfileBloc
|
||||
event.longitude,
|
||||
event.schedules,
|
||||
event.paymentMethods,
|
||||
slotDurationMinutes: event.slotDurationMinutes,
|
||||
);
|
||||
|
||||
emit(const UpdateProfessionalInfoSuccess());
|
||||
|
||||
@@ -28,6 +28,7 @@ class UpdateProfessionalProfileInfo extends ProfessionalProfileEvent {
|
||||
final double longitude;
|
||||
final Schedules schedules;
|
||||
final PaymentMethodEntity paymentMethods;
|
||||
final int slotDurationMinutes;
|
||||
|
||||
const UpdateProfessionalProfileInfo({
|
||||
required this.address,
|
||||
@@ -39,6 +40,7 @@ class UpdateProfessionalProfileInfo extends ProfessionalProfileEvent {
|
||||
required this.longitude,
|
||||
required this.schedules,
|
||||
required this.paymentMethods,
|
||||
this.slotDurationMinutes = 120,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -51,6 +53,7 @@ class UpdateProfessionalProfileInfo extends ProfessionalProfileEvent {
|
||||
latitude,
|
||||
longitude,
|
||||
schedules,
|
||||
paymentMethods
|
||||
paymentMethods,
|
||||
slotDurationMinutes,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||
_professionalRepository = professionRepository,
|
||||
super(CreateServiceInitial()) {
|
||||
on<CreateService>(_onCreateService);
|
||||
on<BlockSlot>(_onBlockSlot);
|
||||
on<LoadService>(_onLoadService);
|
||||
on<UpdateServiceStatus>(_onUpdateServiceStatus);
|
||||
on<LoadServicesForUser>(_onLoadServicesForUser);
|
||||
@@ -72,6 +73,17 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onBlockSlot(BlockSlot event, Emitter<ServiceState> emit) async {
|
||||
try {
|
||||
emit(CreateServiceLoading());
|
||||
final serviceId = await _serviceRepository.blockSlot(event.day, event.hour1);
|
||||
emit(CreateServiceSuccess(serviceId));
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
emit(CreateServiceFailure());
|
||||
}
|
||||
}
|
||||
|
||||
void _onLoadService(LoadService event, Emitter<ServiceState> emit) async {
|
||||
try {
|
||||
final serviceStream = _serviceRepository.getService(event.serviceId);
|
||||
@@ -108,7 +120,11 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||
|
||||
final professionsDir = {for (var e in professionsList) e.id: e};
|
||||
|
||||
final servicesInfo = services.map((e) {
|
||||
final servicesInfo = services
|
||||
.where((e) =>
|
||||
usersDir.containsKey(e.professionalId) &&
|
||||
professionsDir.containsKey(e.professionalId))
|
||||
.map((e) {
|
||||
return ServiceInfoUI(
|
||||
service: e,
|
||||
user: usersDir[e.professionalId]!,
|
||||
@@ -141,7 +157,9 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||
|
||||
final usersDir = {for (var e in users) e.id: e};
|
||||
|
||||
final servicesInfo = services.map((e) {
|
||||
final servicesInfo = services
|
||||
.where((e) => usersDir.containsKey(e.userId))
|
||||
.map((e) {
|
||||
return ServiceInfoUI(
|
||||
service: e,
|
||||
user: usersDir[e.userId]!,
|
||||
@@ -180,7 +198,11 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||
|
||||
final professionsDir = {for (var e in professionsList) e.id: e};
|
||||
|
||||
final servicesInfo = services.map((e) {
|
||||
final servicesInfo = services
|
||||
.where((e) =>
|
||||
usersDir.containsKey(e.professionalId) &&
|
||||
professionsDir.containsKey(e.professionalId))
|
||||
.map((e) {
|
||||
return ServiceInfoUI(
|
||||
service: e,
|
||||
user: usersDir[e.professionalId]!,
|
||||
@@ -213,7 +235,9 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||
|
||||
final usersDir = {for (var e in users) e.id: e};
|
||||
|
||||
final servicesInfo = services.map((e) {
|
||||
final servicesInfo = services
|
||||
.where((e) => usersDir.containsKey(e.userId))
|
||||
.map((e) {
|
||||
return ServiceInfoUI(
|
||||
service: e,
|
||||
user: usersDir[e.userId]!,
|
||||
@@ -246,7 +270,9 @@ class ServiceBloc extends Bloc<ServiceEvent, ServiceState> {
|
||||
|
||||
final usersDir = {for (var e in users) e.id: e};
|
||||
|
||||
final servicesInfo = services.map((e) {
|
||||
final servicesInfo = services
|
||||
.where((e) => usersDir.containsKey(e.userId))
|
||||
.map((e) {
|
||||
return ServiceInfoUI(
|
||||
service: e,
|
||||
user: usersDir[e.userId]!,
|
||||
|
||||
@@ -26,6 +26,16 @@ class UpdateServiceStatus extends ServiceEvent {
|
||||
List<Object> get props => [serviceId, newStatus];
|
||||
}
|
||||
|
||||
class BlockSlot extends ServiceEvent {
|
||||
final String day;
|
||||
final TimeOfDay hour1;
|
||||
|
||||
const BlockSlot({required this.day, required this.hour1});
|
||||
|
||||
@override
|
||||
List<Object> get props => [day, hour1];
|
||||
}
|
||||
|
||||
class LoadServicesForUser extends ServiceEvent {
|
||||
final String userId;
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ class SignUpBloc extends Bloc<SignUpEvent, SignUpState> {
|
||||
await _userRepository.setUserData(user);
|
||||
emit(SignUpSuccess());
|
||||
} catch (e) {
|
||||
emit(SignUpFailure());
|
||||
final msg = e.toString().replaceFirst('Exception: ', '');
|
||||
emit(SignUpFailure(message: msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,12 @@ class SignUpInitial extends SignUpState {}
|
||||
|
||||
class SignUpSuccess extends SignUpState {}
|
||||
|
||||
class SignUpFailure extends SignUpState {}
|
||||
class SignUpFailure extends SignUpState {
|
||||
final String message;
|
||||
const SignUpFailure({this.message = 'Error al registrarse. Intenta de nuevo.'});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
class SignUpProcess extends SignUpState {}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:suggestion_repository/suggestion_repository.dart';
|
||||
|
||||
part 'suggestion_event.dart';
|
||||
part 'suggestion_state.dart';
|
||||
|
||||
class SuggestionBloc extends Bloc<SuggestionEvent, SuggestionState> {
|
||||
final ApiSuggestionRepository _suggestionRepository;
|
||||
|
||||
SuggestionBloc({required ApiSuggestionRepository suggestionRepository})
|
||||
: _suggestionRepository = suggestionRepository,
|
||||
super(SuggestionInitial()) {
|
||||
on<SubmitSuggestion>(_onSubmitSuggestion);
|
||||
}
|
||||
|
||||
void _onSubmitSuggestion(
|
||||
SubmitSuggestion event, Emitter<SuggestionState> emit) async {
|
||||
emit(SuggestionLoading());
|
||||
try {
|
||||
await _suggestionRepository.createSuggestion(event.message);
|
||||
emit(SuggestionSuccess());
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
emit(SuggestionFailure(message: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
part of 'suggestion_bloc.dart';
|
||||
|
||||
abstract class SuggestionEvent extends Equatable {
|
||||
const SuggestionEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class SubmitSuggestion extends SuggestionEvent {
|
||||
final String message;
|
||||
|
||||
const SubmitSuggestion({required this.message});
|
||||
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
part of 'suggestion_bloc.dart';
|
||||
|
||||
abstract class SuggestionState extends Equatable {
|
||||
const SuggestionState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class SuggestionInitial extends SuggestionState {}
|
||||
|
||||
class SuggestionLoading extends SuggestionState {}
|
||||
|
||||
class SuggestionSuccess extends SuggestionState {}
|
||||
|
||||
class SuggestionFailure extends SuggestionState {
|
||||
final String? message;
|
||||
|
||||
const SuggestionFailure({this.message});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
+336
-308
@@ -12,7 +12,6 @@ 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/dropwdon.dart';
|
||||
import 'package:prosappco/screens/lists/professional_score_list_screen.dart';
|
||||
import 'package:prosappco/screens/lists/professional_service_history_list_screen.dart';
|
||||
import 'package:prosappco/screens/lists/professional_service_list_screen.dart';
|
||||
@@ -25,23 +24,22 @@ 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/profile/profile_screen.dart';
|
||||
import 'package:prosappco/screens/web/web_view_screen.dart';
|
||||
import 'package:prosappco/screens/suggestions/suggestion_screen.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
const _kPro = Color(0xFF0D9488);
|
||||
const _kUser = Color(0xFF1565C0);
|
||||
|
||||
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';
|
||||
final Uri uri = Uri.parse(url);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,8 +51,9 @@ class GeneralDrawer extends StatelessWidget {
|
||||
builder: (context, userState) {
|
||||
return BlocBuilder<ProfessionalBloc, ProfessionalState>(
|
||||
builder: (context, professionalState) {
|
||||
final isProMode = _isProModeActive(professionalState);
|
||||
return Drawer(
|
||||
backgroundColor: Theme.of(context).colorScheme.secondary,
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
@@ -71,111 +70,100 @@ class GeneralDrawer extends StatelessWidget {
|
||||
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(),
|
||||
if (isProMode)
|
||||
GeneralDrawerItem(
|
||||
leading: Icons.person_outline_rounded,
|
||||
label: 'Perfil profesional',
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const ProfessionalProfileScreen(),
|
||||
),
|
||||
),
|
||||
),
|
||||
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(),
|
||||
),
|
||||
);
|
||||
},
|
||||
onTap: () => isProMode
|
||||
? Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const ProfessionalServiceListScreen()),
|
||||
)
|
||||
: Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const UserServiceListScreen()),
|
||||
),
|
||||
),
|
||||
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(),
|
||||
),
|
||||
);
|
||||
},
|
||||
onTap: () => isProMode
|
||||
? Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const ProfessionalServiceHistoryListScreen()),
|
||||
)
|
||||
: Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const UserServiceHistoryListScreen()),
|
||||
),
|
||||
),
|
||||
shouldProModeActive(context, professionalState)
|
||||
? GeneralDrawerItem(
|
||||
onTap: () {
|
||||
if (professionalState
|
||||
is LoadedModeProState) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
ProfessionalCalendarScreen(
|
||||
userProfessional:
|
||||
professionalState.proInfo!,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
label: 'Calendario',
|
||||
leading: Icons.calendar_month_outlined,
|
||||
)
|
||||
: const SizedBox(),
|
||||
if (isProMode)
|
||||
GeneralDrawerItem(
|
||||
leading: Icons.calendar_month_outlined,
|
||||
label: 'Calendario',
|
||||
onTap: () {
|
||||
if (professionalState
|
||||
is LoadedModeProState &&
|
||||
professionalState.proInfo != null) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
ProfessionalCalendarScreen(
|
||||
userProfessional:
|
||||
professionalState.proInfo!,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context)
|
||||
.clearSnackBars();
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(
|
||||
content: Text(
|
||||
'Cargando tu información de profesional, intenta de nuevo en un momento'),
|
||||
));
|
||||
}
|
||||
},
|
||||
),
|
||||
GeneralDrawerItem(
|
||||
leading: Icons.settings_outlined,
|
||||
label: 'Configuración',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
const ConfigurationScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const ConfigurationScreen()),
|
||||
),
|
||||
),
|
||||
GeneralDrawerItem(
|
||||
leading: Icons.help_outline,
|
||||
label: 'Soporte',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
const ConfigurationSupportScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const ConfigurationSupportScreen()),
|
||||
),
|
||||
),
|
||||
GeneralDrawerItem(
|
||||
leading: Icons.campaign_outlined,
|
||||
@@ -187,137 +175,45 @@ class GeneralDrawer extends StatelessWidget {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return WebViewScreen(
|
||||
label: 'Sugerencias',
|
||||
link:
|
||||
'https://admin.prosapp.co/sugerencias');
|
||||
},
|
||||
builder: (_) => const SuggestionScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
Container(
|
||||
color: const Color(0xFF2BA4EC),
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
trailing: shouldProModeActive(context, professionalState)
|
||||
? FutureBuilder(builder: (context, AsyncSnapshot<int> snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data! < 1) {
|
||||
return const SizedBox();
|
||||
}
|
||||
final int notificationCount = snapshot.data!;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
notificationCount > 9
|
||||
? '+9'
|
||||
: notificationCount.toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
future: Injector.appInstance
|
||||
.get<ApiServiceRepository>()
|
||||
.countPendingServicesForProfessional(
|
||||
ApiUserRepository.currentUserId ?? ''),
|
||||
)
|
||||
: const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.white,
|
||||
size: 25,
|
||||
),
|
||||
title: Text(
|
||||
shouldProModeActive(context, professionalState)
|
||||
? 'Solicitudes'
|
||||
: 'Solicitar servicio',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
// CTA item — go to main action
|
||||
_CtaItem(
|
||||
isProMode: isProMode,
|
||||
professionalState: professionalState,
|
||||
),
|
||||
// Rating row
|
||||
DrawerReputation(builder: (reputation) {
|
||||
final isProModeActive =
|
||||
(professionalState is LoadedModeProState) &&
|
||||
professionalState.isProModeActive;
|
||||
|
||||
final total = isProModeActive
|
||||
final total = isProMode
|
||||
? reputation.totalPro
|
||||
: reputation.total;
|
||||
|
||||
final average = isProModeActive
|
||||
final average = isProMode
|
||||
? reputation.averagePro
|
||||
: reputation.average;
|
||||
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
final isProModeActive = (professionalState is LoadedModeProState) && professionalState.isProModeActive;
|
||||
isProModeActive ? Navigator.push(context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) {
|
||||
return const ProfessionalScoreListScreen();
|
||||
}))
|
||||
: Navigator.push(context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) {
|
||||
return const UserScoreListScreen();
|
||||
}));
|
||||
},
|
||||
trailing: const Icon(Icons.keyboard_arrow_right,
|
||||
color: Colors.black),
|
||||
title: 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()})',
|
||||
),
|
||||
],
|
||||
),
|
||||
return _RatingRow(
|
||||
average: average,
|
||||
total: total,
|
||||
isProMode: isProMode,
|
||||
professionalState: professionalState,
|
||||
);
|
||||
}),
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 0.5,
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
padding: const EdgeInsets.only(top: 10, bottom: 4),
|
||||
child: Text(
|
||||
'Prosapp ® todos los derechos reservados',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.grey[700],
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.4),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -336,7 +232,11 @@ class GeneralDrawer extends StatelessWidget {
|
||||
const SizedBox(height: 15),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: buttonOfState(context, professionalState),
|
||||
child: _ModeButton(
|
||||
professionalState: professionalState,
|
||||
userState: userState,
|
||||
isProMode: isProMode,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
],
|
||||
@@ -349,145 +249,273 @@ 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;
|
||||
bool _isProModeActive(ProfessionalState state) =>
|
||||
(state is LoadedModeProState) ? state.isProModeActive : false;
|
||||
}
|
||||
|
||||
if (parteFraccionaria >= 3) {
|
||||
parteFraccionaria = 5;
|
||||
} else {
|
||||
parteFraccionaria = 0;
|
||||
}
|
||||
// CTA tile navigating to solicitudes / solicitar servicio
|
||||
class _CtaItem extends StatelessWidget {
|
||||
final bool isProMode;
|
||||
final ProfessionalState professionalState;
|
||||
_CtaItem(
|
||||
{required this.isProMode, required this.professionalState});
|
||||
|
||||
// Unir la parte entera y fraccionaria y convertirlo nuevamente a double
|
||||
double resultado = double.parse('$parteEntera.$parteFraccionaria');
|
||||
return resultado;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: isProMode
|
||||
? _kPro.withOpacity(0.1)
|
||||
: _kUser.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: isProMode
|
||||
? _kPro.withOpacity(0.25)
|
||||
: _kUser.withOpacity(0.25)),
|
||||
),
|
||||
child: ListTile(
|
||||
onTap: () => Navigator.pop(context),
|
||||
leading: Icon(
|
||||
isProMode ? Icons.inbox_outlined : Icons.search_rounded,
|
||||
color: isProMode ? _kPro : _kUser,
|
||||
),
|
||||
title: Text(
|
||||
isProMode ? 'Solicitudes' : 'Solicitar servicio',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: isProMode ? _kPro : _kUser,
|
||||
),
|
||||
),
|
||||
trailing: isProMode
|
||||
? FutureBuilder<int>(
|
||||
future: Injector.appInstance
|
||||
.get<ApiServiceRepository>()
|
||||
.countPendingServicesForProfessional(
|
||||
ApiUserRepository.currentUserId ?? ''),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data! < 1) {
|
||||
return Icon(Icons.keyboard_arrow_right,
|
||||
color: _kPro.withOpacity(0.5));
|
||||
}
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
snapshot.data! > 9
|
||||
? '+9'
|
||||
: snapshot.data!.toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
: Icon(Icons.keyboard_arrow_right,
|
||||
color: _kUser.withOpacity(0.5)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RatingRow extends StatelessWidget {
|
||||
final double average;
|
||||
final int total;
|
||||
final bool isProMode;
|
||||
final ProfessionalState professionalState;
|
||||
_RatingRow(
|
||||
{required this.average,
|
||||
required this.total,
|
||||
required this.isProMode,
|
||||
required this.professionalState});
|
||||
|
||||
double _calcRating(double avg) {
|
||||
final parts = avg.toString().split('.');
|
||||
final frac = parts.length > 1 ? int.parse(parts[1]) : 0;
|
||||
return double.parse(
|
||||
'${parts[0]}.${frac >= 3 ? 5 : 0}');
|
||||
}
|
||||
|
||||
buttonOfState(BuildContext context, ProfessionalState state) {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
onTap: () {
|
||||
isProMode
|
||||
? Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) => const ProfessionalScoreListScreen()))
|
||||
: Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) => const UserScoreListScreen()));
|
||||
},
|
||||
leading: Icon(Icons.star_outline_rounded,
|
||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.6)),
|
||||
trailing: Icon(Icons.keyboard_arrow_right,
|
||||
color: Theme.of(context).colorScheme.onSurface.withOpacity(0.4)),
|
||||
title: Row(
|
||||
children: [
|
||||
RatingBar.builder(
|
||||
initialRating: _calcRating(average),
|
||||
minRating: 1,
|
||||
direction: Axis.horizontal,
|
||||
allowHalfRating: true,
|
||||
itemCount: 5,
|
||||
itemSize: 20,
|
||||
maxRating: 5,
|
||||
itemBuilder: (_, __) => const Icon(Icons.star,
|
||||
color: Color(0xFF1565C0)),
|
||||
onRatingUpdate: (_) {},
|
||||
ignoreGestures: true,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'${average.toStringAsFixed(1)} ($total)',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.7)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ModeButton extends StatelessWidget {
|
||||
final ProfessionalState professionalState;
|
||||
final MyUserState userState;
|
||||
final bool isProMode;
|
||||
|
||||
_ModeButton({
|
||||
required this.professionalState,
|
||||
required this.userState,
|
||||
required this.isProMode,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.7,
|
||||
child: ElevatedButton(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
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) {
|
||||
if (userState.status == MyUserStatus.success) {
|
||||
final user = userState.user!;
|
||||
if (user.name != null &&
|
||||
user.city != null &&
|
||||
user.phone != null) {
|
||||
switch (user.proState) {
|
||||
case ProState.active: Navigator.pop(context);
|
||||
|
||||
context.read<ProfessionalBloc>().add(const SwitchProModeEvent());
|
||||
|
||||
case ProState.active:
|
||||
Navigator.pop(context);
|
||||
context
|
||||
.read<ProfessionalBloc>()
|
||||
.add(const SwitchProModeEvent());
|
||||
break;
|
||||
case ProState.inactive:
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const ProfessionalFormScreen(),
|
||||
),
|
||||
builder: (_) => const ProfessionalFormScreen()),
|
||||
);
|
||||
break;
|
||||
case ProState.pending:
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const ProfessionalPendingScreen(),
|
||||
),
|
||||
builder: (_) =>
|
||||
const ProfessionalPendingScreen()),
|
||||
);
|
||||
break;
|
||||
case ProState.denied:
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const ProfessionalDeniedScreen(),
|
||||
),
|
||||
builder: (_) =>
|
||||
const ProfessionalDeniedScreen()),
|
||||
);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
final missing = <String>[
|
||||
if (user.name == null) 'nombre',
|
||||
if (user.city == null) 'ciudad',
|
||||
if (user.phone == null) 'teléfono',
|
||||
];
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('Por favor, completa tu perfil'),
|
||||
));
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
'Completa tu perfil: falta ${missing.join(', ')}')),
|
||||
);
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => const ProfileScreen(),
|
||||
),
|
||||
builder: (_) => const ProfileScreen()),
|
||||
);
|
||||
}
|
||||
} else {}
|
||||
}
|
||||
},
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
padding: const EdgeInsets.symmetric(vertical: 15),
|
||||
icon: const Icon(Icons.swap_horiz, size: 20),
|
||||
label: Text(
|
||||
isProMode ? 'Cambiar a modo cliente' : 'Cambiar a modo profesional',
|
||||
style: const TextStyle(fontSize: 15),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor:
|
||||
isProMode ? _kPro : _kUser,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
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),
|
||||
),
|
||||
),
|
||||
),
|
||||
(state is LoadedModeProState)
|
||||
? Visibility(
|
||||
visible: !state.isProModeActive,
|
||||
child: Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: FutureBuilder(
|
||||
builder: (context, AsyncSnapshot<int> snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data! < 1) {
|
||||
return const SizedBox();
|
||||
}
|
||||
final int notificationCount = snapshot.data!;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
notificationCount > 9
|
||||
? '+9'
|
||||
: notificationCount.toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
future: Injector.appInstance
|
||||
.get<ApiServiceRepository>()
|
||||
.countPendingServicesForProfessional(
|
||||
ApiUserRepository.currentUserId ?? ''),
|
||||
if (!isProMode && professionalState is LoadedModeProState)
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: FutureBuilder<int>(
|
||||
future: Injector.appInstance
|
||||
.get<ApiServiceRepository>()
|
||||
.countPendingServicesForProfessional(
|
||||
ApiUserRepository.currentUserId ?? ''),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData || snapshot.data! < 1) {
|
||||
return const SizedBox();
|
||||
}
|
||||
return Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
)
|
||||
: const SizedBox(),
|
||||
child: Text(
|
||||
snapshot.data! > 9 ? '+9' : snapshot.data!.toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
shouldProModeActive(BuildContext context, ProfessionalState state) {
|
||||
return (state is LoadedModeProState) ? state.isProModeActive : false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,98 +12,139 @@ class GeneralDrawerHeader extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<MyUserBloc, MyUserState>(
|
||||
builder: (context, state) {
|
||||
if (state.status == MyUserStatus.success) {
|
||||
final user = state.user!;
|
||||
builder: (context, userState) {
|
||||
if (userState.status == MyUserStatus.success) {
|
||||
final user = userState.user!;
|
||||
return BlocBuilder<ProfessionalBloc, ProfessionalState>(
|
||||
builder: (context, state) {
|
||||
return ListTile(
|
||||
builder: (context, proState) {
|
||||
final isProMode = (proState is LoadedModeProState) &&
|
||||
proState.isProModeActive;
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
shouldProModeActive(context, state)
|
||||
isProMode
|
||||
? Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const ProfessionalProfileScreen();
|
||||
},
|
||||
builder: (_) => const ProfessionalProfileScreen(),
|
||||
),
|
||||
)
|
||||
: Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const ProfileScreen();
|
||||
},
|
||||
builder: (_) => const ProfileScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
title: Text(user.name ?? '',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
subtitle: Text(user.drawerLabel,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 12)),
|
||||
leading: pictureWidget(user.picture, context),
|
||||
trailing:
|
||||
const Icon(Icons.keyboard_arrow_right, color: Colors.black),
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
20,
|
||||
MediaQuery.of(context).padding.top + 20,
|
||||
20,
|
||||
16),
|
||||
child: Row(
|
||||
children: [
|
||||
_avatar(user.picture),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
user.name ?? '',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
_modePill(isProMode),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.4),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (state.status == MyUserStatus.failure) {
|
||||
return const Text('Error obteniendo datos del usuario');
|
||||
} else if (userState.status == MyUserStatus.failure) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('Error obteniendo datos del usuario'),
|
||||
);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(24),
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
shouldProModeActive(BuildContext context, ProfessionalState state) {
|
||||
return (state is LoadedModeProState) ? state.isProModeActive : false;
|
||||
Widget _modePill(bool isProMode) {
|
||||
final color =
|
||||
isProMode ? const Color(0xFF0D9488) : const Color(0xFF1565C0);
|
||||
final icon = isProMode ? Icons.badge_outlined : Icons.person_outline;
|
||||
final label = isProMode ? 'Profesional' : 'Cliente';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, color: Colors.white, size: 12),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 11,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget pictureWidget(String? pictureUrl, BuildContext context) {
|
||||
Widget _avatar(String? pictureUrl) {
|
||||
ImageProvider<Object>? imageProvider;
|
||||
|
||||
if (pictureUrl != null && pictureUrl.isNotEmpty) {
|
||||
imageProvider = NetworkImage(pictureUrl);
|
||||
}
|
||||
|
||||
return Hero(
|
||||
tag: 'picture-profile',
|
||||
child: pictureContainerWidget(
|
||||
imageProvider,
|
||||
child: Container(
|
||||
width: 52,
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: const Color(0xFF1565C0).withOpacity(0.3), width: 2),
|
||||
image: imageProvider == null
|
||||
? null
|
||||
: DecorationImage(image: imageProvider, fit: BoxFit.cover),
|
||||
),
|
||||
child: imageProvider == null
|
||||
? Icon(CupertinoIcons.person,
|
||||
color: Colors.grey.shade500, size: 28)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget pictureContainerWidget(ImageProvider<Object>? imageProvider) {
|
||||
final image = imageProvider == null
|
||||
? null
|
||||
: DecorationImage(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.contain,
|
||||
);
|
||||
|
||||
final widget = image == null
|
||||
? Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 40,
|
||||
)
|
||||
: null;
|
||||
|
||||
return Container(
|
||||
width: 60,
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
image: image,
|
||||
),
|
||||
child: widget,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,28 +20,23 @@ class GeneralDrawerItem extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final onSurface = Theme.of(context).colorScheme.onSurface;
|
||||
return ListTile(
|
||||
onTap: onTap == null ? null : () => onTap!(),
|
||||
leading: leading == null
|
||||
? null
|
||||
: Icon(
|
||||
leading,
|
||||
color: Colors.black,
|
||||
),
|
||||
: Icon(leading, color: color ?? onSurface.withOpacity(0.75)),
|
||||
trailing: trailing
|
||||
? const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
)
|
||||
? Icon(Icons.keyboard_arrow_right, color: onSurface.withOpacity(0.4))
|
||||
: null,
|
||||
title: Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 15, color: color),
|
||||
style: TextStyle(fontSize: 15, color: color ?? onSurface),
|
||||
),
|
||||
subtitle: subtitle == null
|
||||
? null
|
||||
: Text(subtitle ?? "", style: const TextStyle(color: Colors.black54)),
|
||||
// dense: true,
|
||||
: Text(subtitle!,
|
||||
style: TextStyle(color: onSurface.withOpacity(0.55))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,11 @@ import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
|
||||
import 'package:prosappco/blocs/setting_bloc/setting_bloc.dart';
|
||||
import 'package:prosappco/blocs/sign_up_bloc/sign_up_bloc.dart';
|
||||
import 'package:prosappco/blocs/sing_in_bloc/sign_in_bloc.dart';
|
||||
import 'package:prosappco/blocs/suggestion_bloc/suggestion_bloc.dart';
|
||||
import 'package:prosappco/local_notifications/local_notifications.dart';
|
||||
import 'package:score_repository/score_repository.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:suggestion_repository/suggestion_repository.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
import 'package:city_repository/city_repository.dart';
|
||||
import 'package:setting_repository/setting_repository.dart';
|
||||
@@ -42,6 +44,7 @@ class AppDI {
|
||||
injector.registerSingleton(() => ApiServiceRepository());
|
||||
injector.registerSingleton(() => ApiChatRepository());
|
||||
injector.registerSingleton(() => ApiScoreRepository());
|
||||
injector.registerSingleton(() => ApiSuggestionRepository());
|
||||
|
||||
injector.registerSingleton<AuthenticationBloc>((() =>
|
||||
AuthenticationBloc(myUserRepository: injector.get<UserRepository>())));
|
||||
@@ -105,5 +108,11 @@ class AppDI {
|
||||
userRepository: injector.get<UserRepository>(),
|
||||
),
|
||||
);
|
||||
|
||||
injector.registerDependency<SuggestionBloc>(
|
||||
() => SuggestionBloc(
|
||||
suggestionRepository: injector.get<ApiSuggestionRepository>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,12 @@ class _SignUpScreenState extends State<SignUpScreen> {
|
||||
signUpRequired = true;
|
||||
});
|
||||
} else if (state is SignUpFailure) {
|
||||
return;
|
||||
setState(() {
|
||||
signUpRequired = false;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(state.message)),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Column(
|
||||
|
||||
@@ -110,7 +110,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
),
|
||||
subtitle: widget.service.userId ==
|
||||
ApiUserRepository.currentUserId ?? ''
|
||||
(ApiUserRepository.currentUserId ?? '')
|
||||
? GeneralReputation(
|
||||
userId: widget.service.professionalId,
|
||||
builder: (context, reputation) {
|
||||
@@ -339,7 +339,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
List<Widget> _messagesList(List<MessageEntity> messages) {
|
||||
return messages
|
||||
.map(
|
||||
(e) => e.ownerId != ApiUserRepository.currentUserId ?? ''
|
||||
(e) => e.ownerId != (ApiUserRepository.currentUserId ?? '')
|
||||
? ListTile(
|
||||
title: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:prosappco/components/general_drawer_item.dart';
|
||||
import 'package:prosappco/screens/web/web_view_screen.dart';
|
||||
import 'package:prosappco/screens/configuration/policy_text_screen.dart';
|
||||
import 'package:setting_repository/setting_repository.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
class ConfigurationAboutScreen extends StatefulWidget {
|
||||
@@ -37,15 +35,24 @@ class _ConfigurationAboutScreenState extends State<ConfigurationAboutScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _launchURL(String url) async {
|
||||
if (await canLaunch(url)) {
|
||||
await launch(url, forceSafariVC: false, forceWebView: false);
|
||||
} else {
|
||||
throw 'No se pudo abrir el enlace $url';
|
||||
Future<void> _openPolicy(String title, String Function(PoliciesEntity) pick) async {
|
||||
try {
|
||||
final policies = await settingRepository.getPolicies();
|
||||
if (!mounted) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) => PolicyTextScreen(title: title, content: pick(policies)),
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('No se pudo cargar el contenido')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -56,44 +63,18 @@ class _ConfigurationAboutScreenState extends State<ConfigurationAboutScreen> {
|
||||
children: [
|
||||
GeneralDrawerItem(
|
||||
label: 'Políticas de privacidad',
|
||||
onTap: () {
|
||||
if (kIsWeb) {
|
||||
_launchURL(settings?.politicasPrivacidad ?? '');
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return WebViewScreen(
|
||||
label: 'Políticas de privacidad',
|
||||
link: settings?.politicasPrivacidad ?? '',
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
onTap: () => _openPolicy(
|
||||
'Políticas de privacidad',
|
||||
(p) => p.privacy,
|
||||
),
|
||||
trailing: true,
|
||||
),
|
||||
GeneralDrawerItem(
|
||||
label: 'Términos y condiciones',
|
||||
onTap: () {
|
||||
if (kIsWeb) {
|
||||
_launchURL(settings?.terminosCondiciones ?? '');
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return WebViewScreen(
|
||||
label: 'Términos y condiciones',
|
||||
link: settings?.terminosCondiciones ?? '',
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
onTap: () => _openPolicy(
|
||||
'Términos y condiciones',
|
||||
(p) => p.terms,
|
||||
),
|
||||
trailing: true,
|
||||
),
|
||||
Platform.isIOS
|
||||
|
||||
@@ -1,130 +1,3 @@
|
||||
// import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
// import 'package:firebase_auth/firebase_auth.dart';
|
||||
// import 'package:flutter/cupertino.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:prosappco/src/components/pop_appbar.dart';
|
||||
// import 'package:prosappco/src/presentation/screens/about.dart';
|
||||
|
||||
// class ConfigurationScreen extends StatefulWidget {
|
||||
// const ConfigurationScreen({super.key});
|
||||
|
||||
// @override
|
||||
// State<ConfigurationScreen> createState() => _ConfigurationScreenState();
|
||||
// }
|
||||
|
||||
// class _ConfigurationScreenState extends State<ConfigurationScreen> {
|
||||
// late final FirebaseAuth _auth;
|
||||
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// _auth = FirebaseAuth.instance;
|
||||
// }
|
||||
|
||||
// Future<void> deleteAccount() async {
|
||||
// try {
|
||||
// final currentUser = _auth.currentUser;
|
||||
|
||||
// if (currentUser != null) {
|
||||
// final uid = currentUser.uid;
|
||||
|
||||
// await FirebaseFirestore.instance.collection('users').doc(uid).delete();
|
||||
|
||||
// await currentUser.delete();
|
||||
|
||||
// await _auth.signOut();
|
||||
|
||||
// Get.snackbar(
|
||||
// 'Cuenta Eliminada',
|
||||
// 'Tu cuenta ha sido eliminada con éxito.',
|
||||
// snackPosition: SnackPosition.BOTTOM,
|
||||
// );
|
||||
// }
|
||||
// } catch (e) {
|
||||
// Get.snackbar(
|
||||
// 'Error al Eliminar Cuenta',
|
||||
// 'Hubo un error al eliminar tu cuenta. Por favor, inténtalo de nuevo más tarde.',
|
||||
// snackPosition: SnackPosition.BOTTOM,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<void> _showDeleteAccountConfirmationDialog(
|
||||
// BuildContext context) async {
|
||||
// return showDialog(
|
||||
// context: context,
|
||||
// builder: (BuildContext context) {
|
||||
// return AlertDialog(
|
||||
// title: const Text('Eliminar Cuenta'),
|
||||
// content: const Text(
|
||||
// '¿Estás seguro de que deseas eliminar tu cuenta? Esta acción no se puede deshacer.'),
|
||||
// actions: [
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// Navigator.of(context).pop();
|
||||
// },
|
||||
// child: const Text('Cancelar'),
|
||||
// ),
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// deleteAccount();
|
||||
// Navigator.of(context).pop();
|
||||
// },
|
||||
// child: const Text(
|
||||
// 'Eliminar',
|
||||
// style:
|
||||
// TextStyle(color: Colors.red, fontWeight: FontWeight.w600),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: PopAppbar(
|
||||
// onPressed: () {
|
||||
// Navigator.pop(context);
|
||||
// },
|
||||
// label: 'Configuración'),
|
||||
// body: ListView(
|
||||
// children: [
|
||||
// ListTile(
|
||||
// onTap: () {
|
||||
// Navigator.push(
|
||||
// context,
|
||||
// CupertinoPageRoute(
|
||||
// builder: (BuildContext context) {
|
||||
// return const AboutScreen();
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// title: const Text('Acerca de la aplicación'),
|
||||
// trailing: const Icon(
|
||||
// Icons.keyboard_arrow_right,
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// ),
|
||||
// ListTile(
|
||||
// onTap: () {
|
||||
// _showDeleteAccountConfirmationDialog(context);
|
||||
// },
|
||||
// title: const Text(
|
||||
// 'Eliminar cuenta',
|
||||
// style: TextStyle(color: Colors.red),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
@@ -132,9 +5,10 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:prosappco/blocs/setting_bloc/setting_bloc.dart';
|
||||
import 'package:prosappco/components/general_drawer_item.dart';
|
||||
import 'package:prosappco/screens/configuration/configuration_about_screen.dart';
|
||||
|
||||
const _kPrimary = Color(0xFF1565C0);
|
||||
|
||||
class ConfigurationScreen extends StatelessWidget {
|
||||
const ConfigurationScreen({super.key});
|
||||
|
||||
@@ -153,38 +27,41 @@ class ConfigurationScreen extends StatelessWidget {
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Configuración'),
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
GeneralDrawerItem(
|
||||
const SizedBox(height: 8),
|
||||
_ConfigItem(
|
||||
icon: Icons.info_outline_rounded,
|
||||
label: 'Acerca de la aplicación',
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const ConfigurationAboutScreen();
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
trailing: true,
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) => const ConfigurationAboutScreen(),
|
||||
),
|
||||
),
|
||||
),
|
||||
GeneralDrawerItem(
|
||||
_ConfigItem(
|
||||
icon: Icons.logout_rounded,
|
||||
label: 'Cerrar sesión',
|
||||
onTap: () {
|
||||
try {
|
||||
settingBloc.add(SettingLogoutRequest());
|
||||
} catch (e) {
|
||||
log('xd conigura ${e.toString()}');
|
||||
log('logout error: ${e.toString()}');
|
||||
}
|
||||
},
|
||||
),
|
||||
GeneralDrawerItem(
|
||||
const Divider(height: 1),
|
||||
_ConfigItem(
|
||||
icon: Icons.delete_outline_rounded,
|
||||
label: 'Eliminar cuenta',
|
||||
onTap: () {},
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
)
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -192,3 +69,39 @@ class ConfigurationScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ConfigItem extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Color? color;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _ConfigItem({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.onTap,
|
||||
this.color,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final onSurface = Theme.of(context).colorScheme.onSurface;
|
||||
final c = color ?? onSurface;
|
||||
return ListTile(
|
||||
onTap: onTap,
|
||||
leading: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: c.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(icon, color: c, size: 20),
|
||||
),
|
||||
title: Text(label, style: TextStyle(color: c, fontWeight: FontWeight.w500)),
|
||||
trailing: color == null
|
||||
? Icon(Icons.keyboard_arrow_right, color: onSurface.withOpacity(0.35))
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,13 +81,17 @@ class _ConfigurationSupportScreenState
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 30, left: 35, right: 35),
|
||||
child: Text(
|
||||
'${settings?.tituloSoporte}',
|
||||
settings == null
|
||||
? 'Cargando...'
|
||||
: (settings?.tituloSoporte ?? 'Soporte'),
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 30, horizontal: 35),
|
||||
child: Text(settings?.parrafoSoporte ?? 'Cargando...'),
|
||||
child: Text(
|
||||
settings == null ? 'Cargando...' : (settings?.parrafoSoporte ?? ''),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PolicyTextScreen extends StatelessWidget {
|
||||
final String title;
|
||||
final String content;
|
||||
|
||||
const PolicyTextScreen({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.content,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(title)),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
content,
|
||||
style: const TextStyle(fontSize: 14, height: 1.5),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import 'package:prosappco/components/general_drawer.dart';
|
||||
import 'package:prosappco/screens/lists/professional_pending_service_list.dart';
|
||||
import 'package:prosappco/screens/user/user_map_screen.dart';
|
||||
|
||||
const _kPrimary = Color(0xFF1565C0);
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@@ -15,19 +17,20 @@ class HomeScreen extends StatelessWidget {
|
||||
return SafeArea(
|
||||
child: shouldProModeActive(context, state)
|
||||
? Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
drawer: GeneralDrawer(),
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
drawer: const GeneralDrawer(),
|
||||
appBar: AppBar(
|
||||
title: const Text('Solicitudes'),
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
body: ProfessionalPendingServiceListScreen(),
|
||||
body: const ProfessionalPendingServiceListScreen(),
|
||||
)
|
||||
: Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
drawer: GeneralDrawer(),
|
||||
body: const Center(
|
||||
child: UserMapScreen(),
|
||||
),
|
||||
backgroundColor: Theme.of(context).colorScheme.surface,
|
||||
drawer: const GeneralDrawer(),
|
||||
body: const UserMapScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:intl_phone_field/helpers.dart';
|
||||
import 'package:profession_repository/profession_repository.dart';
|
||||
@@ -34,6 +37,11 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
|
||||
|
||||
bool _isLoading = true;
|
||||
|
||||
double? _lat;
|
||||
double? _lng;
|
||||
bool _isLocating = false;
|
||||
Timer? _debounce;
|
||||
|
||||
late final ProfessionalListBloc bloc;
|
||||
|
||||
@override
|
||||
@@ -46,6 +54,56 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
|
||||
_loadProfessions();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onSearchChanged(String value) {
|
||||
_debounce?.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 450), () {
|
||||
bloc.add(ProfessionalListFetch(
|
||||
search: value.isEmpty ? null : value,
|
||||
lat: _lat,
|
||||
lng: _lng,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _useMyLocation() async {
|
||||
setState(() => _isLocating = true);
|
||||
try {
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) throw Exception('Location services disabled');
|
||||
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
throw Exception('Location permission denied');
|
||||
}
|
||||
|
||||
final position = await Geolocator.getCurrentPosition();
|
||||
_lat = position.latitude;
|
||||
_lng = position.longitude;
|
||||
bloc.add(ProfessionalListFetch(
|
||||
search: _searchController.text.isEmpty ? null : _searchController.text,
|
||||
lat: _lat,
|
||||
lng: _lng,
|
||||
));
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('No se pudo obtener tu ubicación')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _isLocating = false);
|
||||
}
|
||||
}
|
||||
|
||||
void _loadSettings() {
|
||||
settingRepository.getSettings().then(
|
||||
(value) => setState(() {
|
||||
@@ -134,14 +192,30 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
|
||||
setState(() {
|
||||
_searchController.text = value;
|
||||
});
|
||||
_onSearchChanged(value);
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Busca un profesional',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: _isLocating
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(14),
|
||||
child: SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child:
|
||||
CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
)
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.my_location_outlined),
|
||||
tooltip: 'Usar mi ubicación',
|
||||
onPressed: _useMyLocation,
|
||||
),
|
||||
enabledBorder: const UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey),
|
||||
),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
focusedBorder: const UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
@@ -174,7 +248,7 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
|
||||
.toLowerCase()
|
||||
.contains(removeDiacritics(_searchController.text.toLowerCase())))
|
||||
.where((user) =>
|
||||
user.myUser.id != ApiUserRepository.currentUserId ?? '')
|
||||
user.myUser.id != (ApiUserRepository.currentUserId ?? ''))
|
||||
.where(
|
||||
(user) => user.professionalInfo.profession == _selectedProfession)
|
||||
.toList();
|
||||
@@ -226,7 +300,7 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
|
||||
);
|
||||
},
|
||||
child: filteredUsers[index].professionalInfo.rate.isEmpty ||
|
||||
settings?.tarifas == false
|
||||
settings?.tarifas != true
|
||||
? const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
color: Colors.black,
|
||||
@@ -295,7 +369,10 @@ class _ProfessionalListScreenState extends State<ProfessionalListScreen> {
|
||||
],
|
||||
),
|
||||
subtitle: Text(
|
||||
_disponibilidad(filteredUsers[index].professionalInfo),
|
||||
_disponibilidad(filteredUsers[index].professionalInfo) +
|
||||
(filteredUsers[index].distanceKm != null
|
||||
? ' · ${filteredUsers[index].distanceKm!.toStringAsFixed(1)} km'
|
||||
: ''),
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.blue,
|
||||
|
||||
@@ -66,6 +66,11 @@ class _ProfessionalPendingServiceListScreenState
|
||||
_RequestCard(info: serviceState.services[index]),
|
||||
);
|
||||
}
|
||||
if (serviceState is CreateServiceFailure) {
|
||||
return _errorState(context, () => serviceBloc.add(
|
||||
LoadPendingServicesForProfessional(
|
||||
ApiUserRepository.currentUserId ?? '')));
|
||||
}
|
||||
return _shimmerList();
|
||||
},
|
||||
),
|
||||
@@ -73,6 +78,37 @@ class _ProfessionalPendingServiceListScreenState
|
||||
);
|
||||
}
|
||||
|
||||
Widget _errorState(BuildContext context, VoidCallback onRetry) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: context.subtle.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child:
|
||||
Icon(Icons.error_outline, size: 36, color: context.subtle),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No se pudo cargar la información',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text('Revisa tu conexión e inténtalo de nuevo.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 13, color: context.subtle, height: 1.5)),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(onPressed: onRetry, child: const Text('Reintentar')),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
|
||||
@@ -78,6 +78,12 @@ class _ProfessionalServiceHistoryListScreenState
|
||||
},
|
||||
);
|
||||
}
|
||||
if (serviceState is CreateServiceFailure) {
|
||||
return _errorState(
|
||||
context,
|
||||
() => serviceBloc.add(LoadServicesHistoryForProfessional(
|
||||
ApiUserRepository.currentUserId ?? '')));
|
||||
}
|
||||
return _shimmerList();
|
||||
},
|
||||
),
|
||||
@@ -86,6 +92,34 @@ class _ProfessionalServiceHistoryListScreenState
|
||||
}
|
||||
}
|
||||
|
||||
Widget _errorState(BuildContext context, VoidCallback onRetry) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 72, height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: subtle.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child: Icon(Icons.error_outline, size: 36, color: subtle),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No se pudo cargar la información',
|
||||
style: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w700, color: muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text('Revisa tu conexión e inténtalo de nuevo.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: subtle, height: 1.5)),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(onPressed: onRetry, child: const Text('Reintentar')),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
|
||||
@@ -78,6 +78,12 @@ class _ProfessionalServiceListScreenState
|
||||
},
|
||||
);
|
||||
}
|
||||
if (serviceState is CreateServiceFailure) {
|
||||
return _errorState(
|
||||
context,
|
||||
() => serviceBloc.add(LoadServicesForProfessional(
|
||||
ApiUserRepository.currentUserId ?? '')));
|
||||
}
|
||||
return _shimmerList();
|
||||
},
|
||||
),
|
||||
@@ -86,6 +92,34 @@ class _ProfessionalServiceListScreenState
|
||||
}
|
||||
}
|
||||
|
||||
Widget _errorState(BuildContext context, VoidCallback onRetry) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 72, height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: subtle.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child: Icon(Icons.error_outline, size: 36, color: subtle),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No se pudo cargar la información',
|
||||
style: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w700, color: muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text('Revisa tu conexión e inténtalo de nuevo.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: subtle, height: 1.5)),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(onPressed: onRetry, child: const Text('Reintentar')),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
|
||||
@@ -78,6 +78,12 @@ class _UserServiceHistoryListScreenState
|
||||
},
|
||||
);
|
||||
}
|
||||
if (serviceState is CreateServiceFailure) {
|
||||
return _errorState(
|
||||
context,
|
||||
() => serviceBloc.add(LoadServicesHistoryForUser(
|
||||
ApiUserRepository.currentUserId ?? '')));
|
||||
}
|
||||
return _shimmerList();
|
||||
},
|
||||
),
|
||||
@@ -86,6 +92,34 @@ class _UserServiceHistoryListScreenState
|
||||
}
|
||||
}
|
||||
|
||||
Widget _errorState(BuildContext context, VoidCallback onRetry) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 72, height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: subtle.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child: Icon(Icons.error_outline, size: 36, color: subtle),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No se pudo cargar la información',
|
||||
style: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w700, color: muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text('Revisa tu conexión e inténtalo de nuevo.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: subtle, height: 1.5)),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(onPressed: onRetry, child: const Text('Reintentar')),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
|
||||
@@ -75,6 +75,10 @@ class _UserServiceListScreenState extends State<UserServiceListScreen> {
|
||||
},
|
||||
);
|
||||
}
|
||||
if (serviceState is CreateServiceFailure) {
|
||||
return _errorState(context, () => serviceBloc.add(
|
||||
LoadServicesForUser(ApiUserRepository.currentUserId ?? '')));
|
||||
}
|
||||
return _shimmerList();
|
||||
},
|
||||
),
|
||||
@@ -83,6 +87,34 @@ class _UserServiceListScreenState extends State<UserServiceListScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget _errorState(BuildContext context, VoidCallback onRetry) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||
Container(
|
||||
width: 72, height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: subtle.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child: Icon(Icons.error_outline, size: 36, color: subtle),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No se pudo cargar la información',
|
||||
style: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.w700, color: muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text('Revisa tu conexión e inténtalo de nuevo.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: subtle, height: 1.5)),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(onPressed: onRetry, child: const Text('Reintentar')),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
final subtle = Theme.of(context).colorScheme.onSurface.withOpacity(0.35);
|
||||
final muted = Theme.of(context).colorScheme.onSurface.withOpacity(0.55);
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:intl/intl.dart';
|
||||
import 'package:professional_repository/professional_repository.dart';
|
||||
import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
|
||||
import 'package:prosappco/screens/service/professional_service_screen.dart';
|
||||
import 'package:prosappco/utils/time_of_day_extension.dart';
|
||||
import 'package:prosappco/utils/time_of_day_utils.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
@@ -44,6 +45,7 @@ class _ProfessionalCalendarScreenState
|
||||
List<ServiceEntity>? _services;
|
||||
CalendarFormat _calendarFormat = CalendarFormat.month;
|
||||
bool isLoading = false;
|
||||
bool _loadFailed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -54,9 +56,17 @@ class _ProfessionalCalendarScreenState
|
||||
}
|
||||
|
||||
void _loadServices() {
|
||||
setState(() => _loadFailed = false);
|
||||
serviceRepository
|
||||
.getServicesForProfessionalforCalendar(widget.userProfessional.id)
|
||||
.then((services) => setState(() => _services = services));
|
||||
.then((services) {
|
||||
if (!mounted) return;
|
||||
setState(() => _services = services);
|
||||
}).catchError((e) {
|
||||
if (!mounted) return;
|
||||
// Never fall back to an empty list: booked slots would render as free.
|
||||
setState(() => _loadFailed = true);
|
||||
});
|
||||
}
|
||||
|
||||
void _onDaySelected(DateTime day, DateTime focusedDay) {
|
||||
@@ -87,18 +97,33 @@ class _ProfessionalCalendarScreenState
|
||||
child: BlocConsumer<ServiceBloc, ServiceState>(
|
||||
listener: (context, state) {
|
||||
if (state is CreateServiceLoading) isLoading = true;
|
||||
if (state is CreateServiceFailure) isLoading = false;
|
||||
if (state is CreateServiceFailure) {
|
||||
isLoading = false;
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('No se pudo completar la acción')),
|
||||
);
|
||||
}
|
||||
if (state is CreateServiceSuccess || state is ServiceStatusUpdated) {
|
||||
isLoading = false;
|
||||
_loadServices();
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
_calendarCard(context),
|
||||
_dayHeader(context, schedule, slots.length, occupied, available),
|
||||
if (slots.isEmpty)
|
||||
_emptyState(context)
|
||||
else
|
||||
..._slotCards(context, slots, state),
|
||||
if (_loadFailed)
|
||||
_loadErrorState(context)
|
||||
else ...[
|
||||
_dayHeader(
|
||||
context, schedule, slots.length, occupied, available),
|
||||
if (slots.isEmpty)
|
||||
_emptyState(context)
|
||||
else
|
||||
..._slotCards(context, slots, state),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -337,9 +362,7 @@ class _ProfessionalCalendarScreenState
|
||||
for (final event in _services!) {
|
||||
if (today.toString() == event.day && time == event.range1Hour1) {
|
||||
if (event.userId == event.professionalId) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(const SnackBar(content: Text('Horario ocupado por ti')));
|
||||
_confirmUnblock(event.id!, time);
|
||||
} else {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -353,6 +376,35 @@ class _ProfessionalCalendarScreenState
|
||||
}
|
||||
}
|
||||
|
||||
void _confirmUnblock(String serviceId, TimeOfDay time) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('Desbloquear horario'),
|
||||
content: Text(
|
||||
'¿Quieres liberar el horario de las '
|
||||
'${ScheduleEntity.getFormatTime(time)} '
|
||||
'del ${DateFormat('dd-MM-yyyy').format(today)}?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
context
|
||||
.read<ServiceBloc>()
|
||||
.add(UpdateServiceStatus(serviceId, ServiceStatus.cancelled));
|
||||
},
|
||||
child: const Text('Desbloquear'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onAvailable(BuildContext context, TimeOfDay time, ServiceState state) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -387,7 +439,8 @@ class _ProfessionalCalendarScreenState
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
description: '',
|
||||
range1Hour1: time,
|
||||
range1Hour2: time.replacing(hour: time.hour + 2),
|
||||
range1Hour2: time.add(
|
||||
minute: widget.userProfessional.slotDurationMinutes),
|
||||
rate: '0',
|
||||
location: ServiceLocationPreferences.office,
|
||||
status: ServiceStatus.selfBooked,
|
||||
@@ -395,11 +448,61 @@ class _ProfessionalCalendarScreenState
|
||||
},
|
||||
child: const Text('Reservar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
context.read<ServiceBloc>().add(
|
||||
BlockSlot(day: today.toString(), hour1: time),
|
||||
);
|
||||
},
|
||||
child: const Text('Bloquear horario'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _loadErrorState(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 24),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadowSm,
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 2))
|
||||
],
|
||||
),
|
||||
child: Column(children: [
|
||||
Container(
|
||||
width: 64,
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
color: _kOccupied.withOpacity(0.1), shape: BoxShape.circle),
|
||||
child: const Icon(Icons.wifi_off_outlined,
|
||||
size: 32, color: _kOccupied),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('No se pudo cargar tu agenda',
|
||||
style: TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.muted)),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'No mostramos horarios para evitar que reserves\nsobre una cita ya agendada.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 13, color: context.subtle, height: 1.5)),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(
|
||||
onPressed: _loadServices, child: const Text('Reintentar')),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _emptyState(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 12, 16, 0),
|
||||
@@ -451,13 +554,17 @@ class _ProfessionalCalendarScreenState
|
||||
if (s == null || !s.enabled || s.range1Hour1 == null || s.range2Hour2 == null) {
|
||||
return [];
|
||||
}
|
||||
final stepMinutes = widget.userProfessional.slotDurationMinutes;
|
||||
if (s.continuousDay) {
|
||||
return TimeOfDayUtils.genRanges(s.range1Hour1!, s.range2Hour2!);
|
||||
return TimeOfDayUtils.genRanges(s.range1Hour1!, s.range2Hour2!,
|
||||
stepMinutes: stepMinutes);
|
||||
}
|
||||
if (s.range1Hour2 == null || s.range2Hour1 == null) return [];
|
||||
return [
|
||||
...TimeOfDayUtils.genRanges(s.range1Hour1!, s.range1Hour2!),
|
||||
...TimeOfDayUtils.genRanges(s.range2Hour1!, s.range2Hour2!),
|
||||
...TimeOfDayUtils.genRanges(s.range1Hour1!, s.range1Hour2!,
|
||||
stepMinutes: stepMinutes),
|
||||
...TimeOfDayUtils.genRanges(s.range2Hour1!, s.range2Hour2!,
|
||||
stepMinutes: stepMinutes),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,101 +1,225 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:prosappco/blocs/authentication_bloc/authentication_bloc.dart';
|
||||
import 'package:prosappco/blocs/my_user_bloc/my_user_bloc.dart';
|
||||
import 'package:prosappco/blocs/professional_bloc/professional_bloc.dart';
|
||||
import 'package:prosappco/screens/professional/professional_form_screen.dart';
|
||||
import 'package:setting_repository/setting_repository.dart';
|
||||
|
||||
class ProfessionalDeniedScreen extends StatelessWidget {
|
||||
class ProfessionalDeniedScreen extends StatefulWidget {
|
||||
const ProfessionalDeniedScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ProfessionalDeniedScreen> createState() =>
|
||||
_ProfessionalDeniedScreenState();
|
||||
}
|
||||
|
||||
class _ProfessionalDeniedScreenState extends State<ProfessionalDeniedScreen> {
|
||||
final settingRepository = Injector.appInstance.get<SettingRepository>();
|
||||
SettingEntity? _settings;
|
||||
bool _loadingSettings = true;
|
||||
bool _isResetting = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
settingRepository.getSettings().then((value) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_settings = value;
|
||||
_loadingSettings = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _confirmRetry() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('Volver a registrarme'),
|
||||
content: const Text(
|
||||
'Esta acción reiniciará tu solicitud de profesional y no se puede deshacer. '
|
||||
'¿Deseas continuar?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(dialogContext);
|
||||
context
|
||||
.read<ProfessionalBloc>()
|
||||
.add(const ResetProfessionalApplicationEvent());
|
||||
},
|
||||
child: const Text('Continuar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 88,
|
||||
height: 88,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFEBEE),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.cancel_outlined, color: Color(0xFFE53935), size: 48),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'Solicitud rechazada',
|
||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Color(0xFF1A1A2E)),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Tu solicitud para convertirte en profesional no fue aprobada. Esto puede deberse a información incompleta o documentación no válida.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey, height: 1.5),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF3E0),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: const Color(0xFFFFCC02).withOpacity(0.4)),
|
||||
),
|
||||
return BlocListener<ProfessionalBloc, ProfessionalState>(
|
||||
listener: (context, state) {
|
||||
if (state is ResetProfessionalApplicationLoading) {
|
||||
setState(() => _isResetting = true);
|
||||
} else if (state is ResetProfessionalApplicationSuccess) {
|
||||
setState(() => _isResetting = false);
|
||||
Navigator.of(context).pushReplacement(
|
||||
CupertinoPageRoute(builder: (_) => const ProfessionalFormScreen()),
|
||||
);
|
||||
} else if (state is ProfessionalStateFailure) {
|
||||
setState(() => _isResetting = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('No se pudo reiniciar la solicitud')),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<MyUserBloc, MyUserState>(
|
||||
builder: (context, myUserState) {
|
||||
final rejectedAt = myUserState.user?.rejectedAt;
|
||||
// Backend currently ships rejection_wait_days = 0 (no cooldown).
|
||||
// 7 is only the fallback when /settings could not be read.
|
||||
final waitDays = _settings?.rejectionWaitDays?.toInt() ?? 7;
|
||||
|
||||
// Fail-open, same as the web: if we cannot tell when the rejection
|
||||
// happened, assume the wait already elapsed. Locking someone out of
|
||||
// re-applying forever is worse than letting them retry early.
|
||||
final daysElapsed = rejectedAt != null
|
||||
? DateTime.now().difference(rejectedAt).inDays
|
||||
: waitDays;
|
||||
|
||||
final daysLeft = (waitDays - daysElapsed).clamp(0, waitDays);
|
||||
final canRetry = !_loadingSettings && daysLeft == 0;
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28, vertical: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline, color: Color(0xFFF57C00), size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('¿Qué puedo hacer?', style: TextStyle(fontWeight: FontWeight.w600, color: Color(0xFFF57C00))),
|
||||
],
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 88,
|
||||
height: 88,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFEBEE),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.cancel_outlined,
|
||||
color: Color(0xFFE53935), size: 48),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
const Text(
|
||||
'Solicitud rechazada',
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF1A1A2E)),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const Text(
|
||||
'Tu solicitud para convertirte en profesional no fue aprobada. Esto puede deberse a información incompleta o documentación no válida.',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey, height: 1.5),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFFFF3E0),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: const Color(0xFFFFCC02).withOpacity(0.4)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline,
|
||||
color: Color(0xFFF57C00), size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('¿Qué puedo hacer?',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFFF57C00))),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
_BulletPoint(text: 'Verifica que todos tus datos sean correctos'),
|
||||
_BulletPoint(
|
||||
text: 'Asegúrate de haber adjuntado los documentos requeridos'),
|
||||
_BulletPoint(
|
||||
text: 'Vuelve a registrarte como profesional con la información actualizada'),
|
||||
_BulletPoint(text: 'Contacta a soporte si crees que fue un error'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: (canRetry && !_isResetting) ? _confirmRetry : null,
|
||||
icon: _isResetting
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Icon(Icons.refresh),
|
||||
label: const Text('Volver a registrarme'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF42A4EF),
|
||||
foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: Colors.grey.shade300,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!canRetry && !_loadingSettings) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Podrás volver a intentarlo en $daysLeft día${daysLeft == 1 ? '' : 's'}',
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => context
|
||||
.read<AuthenticationBloc>()
|
||||
.add(AuthenticationLogoutRequested()),
|
||||
icon: const Icon(Icons.logout),
|
||||
label: const Text('Cerrar sesión'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.grey,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
side: const BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
_BulletPoint(text: 'Verifica que todos tus datos sean correctos'),
|
||||
_BulletPoint(text: 'Asegúrate de haber adjuntado los documentos requeridos'),
|
||||
_BulletPoint(text: 'Vuelve a registrarte como profesional con la información actualizada'),
|
||||
_BulletPoint(text: 'Contacta a soporte si crees que fue un error'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('Volver a registrarme'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF42A4EF),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => context.read<AuthenticationBloc>().add(AuthenticationLogoutRequested()),
|
||||
icon: const Icon(Icons.logout),
|
||||
label: const Text('Cerrar sesión'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.grey,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
side: const BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
PlatformFile? _certificadoPdfFile;
|
||||
List<PlatformFile>? _especializacionesPdfFiles = [];
|
||||
|
||||
bool _isSubmitting = false;
|
||||
|
||||
late final AuthBloc authBloc;
|
||||
|
||||
@override
|
||||
@@ -50,7 +52,37 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<AuthBloc>(
|
||||
create: (context) => authBloc,
|
||||
child: Scaffold(
|
||||
child: BlocListener<ProfessionalBloc, ProfessionalState>(
|
||||
listener: (context, professionalState) {
|
||||
if (professionalState is SendProfessionalToReviewLoading) {
|
||||
setState(() => _isSubmitting = true);
|
||||
} else if (professionalState is SendProfessionalToReviewSuccess) {
|
||||
setState(() => _isSubmitting = false);
|
||||
|
||||
// The picture upload only runs once the application actually landed.
|
||||
final user = context.read<MyUserBloc>().state.user;
|
||||
if (user != null) {
|
||||
context.read<ProfileBloc>().add(UpdateUserInfo(
|
||||
myUser: user.copyWith(proState: ProState.pending),
|
||||
filePicture: _imageFile?.path));
|
||||
}
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Información enviada a revisión')),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
} else if (professionalState is SendProfessionalToReviewFailure) {
|
||||
setState(() => _isSubmitting = false);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'No se pudo enviar tu solicitud. Revisa tu conexión e inténtalo de nuevo.')),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Perfil profesional'),
|
||||
),
|
||||
@@ -247,9 +279,20 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
horizontal: 15,
|
||||
),
|
||||
child: FilledButton(
|
||||
onPressed: () {
|
||||
onPressed: _isSubmitting
|
||||
? null
|
||||
: () {
|
||||
final userId =
|
||||
context.read<MyUserBloc>().state.user!.id;
|
||||
context.read<MyUserBloc>().state.user?.id;
|
||||
|
||||
if (userId == null) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'No se pudo identificar tu usuario, vuelve a iniciar sesión')));
|
||||
return;
|
||||
}
|
||||
|
||||
final String? cedulaPdfPath = _cedulaPdfFile?.path;
|
||||
final String? certificadoPdfPath =
|
||||
@@ -300,20 +343,6 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
specializationsPictures:
|
||||
especializacionesPdfPaths,
|
||||
));
|
||||
|
||||
final myUser =
|
||||
state.user!.copyWith(proState: ProState.pending);
|
||||
|
||||
context.read<ProfileBloc>().add(UpdateUserInfo(
|
||||
myUser: myUser, filePicture: _imageFile?.path));
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Información enviada a revisión')),
|
||||
);
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
@@ -325,19 +354,27 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: double.infinity,
|
||||
child: const Text(
|
||||
'Enviar a revisión',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
child: _isSubmitting
|
||||
? const SizedBox(
|
||||
height: 22,
|
||||
width: 22,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Text(
|
||||
'Enviar a revisión',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
)),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ class _ProfessionalProfileScreenState
|
||||
final _rateController = TextEditingController();
|
||||
|
||||
Schedules schedules = Schedules.empty;
|
||||
int _slotDurationMinutes = 120;
|
||||
bool isInit = false;
|
||||
bool _isSaving = false;
|
||||
|
||||
double _longitudeController = 0;
|
||||
double _latitudeController = 0;
|
||||
@@ -78,7 +80,28 @@ class _ProfessionalProfileScreenState
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
return BlocListener<ProfessionalProfileBloc, ProfessionalProfileState>(
|
||||
listener: (context, saveState) {
|
||||
if (saveState is UpdateProfessionalInfoLoading) {
|
||||
setState(() => _isSaving = true);
|
||||
} else if (saveState is UpdateProfessionalInfoSuccess) {
|
||||
setState(() => _isSaving = false);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Información actualizada correctamente')),
|
||||
);
|
||||
} else if (saveState is UpdateProfessionalInfoFailure) {
|
||||
setState(() => _isSaving = false);
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'No se pudo guardar. Revisa tu conexión e inténtalo de nuevo.')),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: context.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text('Perfil Profesional'),
|
||||
@@ -102,9 +125,32 @@ class _ProfessionalProfileScreenState
|
||||
);
|
||||
}
|
||||
}
|
||||
if (state is ProfessionalStateFailure) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 40, color: context.subtle),
|
||||
const SizedBox(height: 12),
|
||||
const Text('No se pudo cargar tu perfil profesional'),
|
||||
const SizedBox(height: 16),
|
||||
OutlinedButton(
|
||||
onPressed: () => context
|
||||
.read<ProfessionalBloc>()
|
||||
.add(const UpdateProfessionalEvent(isProModeActive: true)),
|
||||
child: const Text('Reintentar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const Center(child: Text('Vuelve atrás'));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -128,6 +174,7 @@ class _ProfessionalProfileScreenState
|
||||
deliveryValue = true;
|
||||
}
|
||||
_rateController.text = proInfo.rate;
|
||||
_slotDurationMinutes = proInfo.slotDurationMinutes;
|
||||
loadFinish = true;
|
||||
}
|
||||
|
||||
@@ -261,23 +308,39 @@ class _ProfessionalProfileScreenState
|
||||
color: _kPrimary)),
|
||||
),
|
||||
),
|
||||
child: _scheduleRows(context),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_slotDurationDropdown(context),
|
||||
const SizedBox(height: 8),
|
||||
_scheduleRows(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: ElevatedButton(
|
||||
onPressed: _save,
|
||||
onPressed: _isSaving ? null : _save,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
disabledBackgroundColor: _kPrimary.withOpacity(0.5),
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 0,
|
||||
),
|
||||
child: const Text('Guardar cambios',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
||||
child: _isSaving
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: Colors.white),
|
||||
)
|
||||
: const Text('Guardar cambios',
|
||||
style:
|
||||
TextStyle(fontSize: 16, fontWeight: FontWeight.w700)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
@@ -481,6 +544,37 @@ class _ProfessionalProfileScreenState
|
||||
]);
|
||||
}
|
||||
|
||||
Widget _slotDurationDropdown(BuildContext context) {
|
||||
const options = [15, 20, 30, 45, 60, 90, 120];
|
||||
final value = options.contains(_slotDurationMinutes)
|
||||
? _slotDurationMinutes
|
||||
: 120;
|
||||
return DropdownButtonFormField<int>(
|
||||
value: value,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Duración de cada cita',
|
||||
prefixIcon: Icon(Icons.timer_outlined, color: context.muted),
|
||||
filled: true,
|
||||
fillColor: context.isDark
|
||||
? Colors.white.withOpacity(0.05)
|
||||
: Colors.black.withOpacity(0.04),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
),
|
||||
items: options
|
||||
.map((m) => DropdownMenuItem(
|
||||
value: m,
|
||||
child: Text(m < 60 ? '$m min' : '${m ~/ 60}h${m % 60 == 0 ? '' : ' ${m % 60}min'}'),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (v) {
|
||||
if (v != null) setState(() => _slotDurationMinutes = v);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _scheduleRows(BuildContext context) {
|
||||
final days = <_DayEntry>[
|
||||
_DayEntry('Lunes', schedules.monday),
|
||||
@@ -585,14 +679,12 @@ class _ProfessionalProfileScreenState
|
||||
schedules: schedules,
|
||||
ratePreferences: rateValue,
|
||||
rate: _rateController.text,
|
||||
slotDurationMinutes: _slotDurationMinutes,
|
||||
));
|
||||
context.read<ProfessionalProfileBloc>().add(
|
||||
UpdateProfessionalBannerInfo(fileBanner: _imageFile?.path));
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Información actualizada correctamente')),
|
||||
);
|
||||
if (_imageFile != null) {
|
||||
context.read<ProfessionalProfileBloc>().add(
|
||||
UpdateProfessionalBannerInfo(fileBanner: _imageFile!.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'dart:io';
|
||||
import 'package:city_repository/city_repository.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:intl_phone_field/helpers.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
@@ -15,6 +18,19 @@ import 'package:prosappco/screens/profile/components/profile_item.dart';
|
||||
import 'package:prosappco/screens/profile/profile_register_email_screen.dart';
|
||||
import 'package:prosappco/screens/profile/profile_register_phone_screen.dart';
|
||||
import 'package:prosappco/screens/profile/profile_update_password_screen.dart';
|
||||
import 'package:prosappco/utils/nominatim_geocoder.dart';
|
||||
|
||||
const _kPrimary = Color(0xFF1565C0);
|
||||
|
||||
extension _Th on BuildContext {
|
||||
ThemeData get _t => Theme.of(this);
|
||||
Color get onSurface => _t.colorScheme.onSurface;
|
||||
Color get muted => _t.colorScheme.onSurface.withOpacity(0.55);
|
||||
Color get card => _t.cardColor;
|
||||
bool get isDark => _t.brightness == Brightness.dark;
|
||||
Color get shadowSm =>
|
||||
isDark ? Colors.transparent : Colors.black.withOpacity(0.05);
|
||||
}
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
const ProfileScreen({super.key});
|
||||
@@ -27,14 +43,13 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
final TextEditingController _nameController = TextEditingController();
|
||||
final TextEditingController _cityController = TextEditingController();
|
||||
final TextEditingController _emailController = TextEditingController();
|
||||
final TextEditingController _newEmailController = TextEditingController();
|
||||
final TextEditingController _phoneController = TextEditingController();
|
||||
final TextEditingController _birthdayController = TextEditingController();
|
||||
final TextEditingController _genderController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
|
||||
XFile? _imageFile;
|
||||
bool isLoading = false;
|
||||
bool _isLocating = false;
|
||||
|
||||
late final AuthBloc authBloc;
|
||||
|
||||
@@ -49,44 +64,97 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
_nameController.dispose();
|
||||
_cityController.dispose();
|
||||
_emailController.dispose();
|
||||
_newEmailController.dispose();
|
||||
_phoneController.dispose();
|
||||
_birthdayController.dispose();
|
||||
_genderController.dispose();
|
||||
_passwordController.dispose();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _useMyLocation() async {
|
||||
setState(() => _isLocating = true);
|
||||
try {
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) throw Exception('Location services disabled');
|
||||
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
throw Exception('Location permission denied');
|
||||
}
|
||||
|
||||
final position = await Geolocator.getCurrentPosition();
|
||||
final cityName = await NominatimGeocoder.reverseGeocodeCity(
|
||||
position.latitude, position.longitude);
|
||||
|
||||
if (cityName == null) throw Exception('City not resolved');
|
||||
|
||||
final cities =
|
||||
await Injector.appInstance.get<CityRepository>().getCities();
|
||||
final normalized = removeDiacritics(cityName.toLowerCase().trim());
|
||||
|
||||
CityUi? match;
|
||||
for (final c in cities) {
|
||||
if (removeDiacritics(c.cityName.toLowerCase().trim()) == normalized) {
|
||||
match = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (match == null) {
|
||||
for (final c in cities) {
|
||||
final cName = removeDiacritics(c.cityName.toLowerCase());
|
||||
if (cName.contains(normalized) || normalized.contains(cName)) {
|
||||
match = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
if (match != null) {
|
||||
setState(() => _cityController.text = match!.cityName);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text(
|
||||
'No encontramos tu ciudad en la lista, selecciónala manualmente'),
|
||||
));
|
||||
}
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('No se pudo obtener tu ubicación, selecciona tu ciudad manualmente'),
|
||||
));
|
||||
} finally {
|
||||
if (mounted) setState(() => _isLocating = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<AuthBloc>(
|
||||
create: (context) => authBloc,
|
||||
create: (_) => authBloc,
|
||||
child: BlocListener<ProfileBloc, ProfileState>(
|
||||
listener: (context, state) {
|
||||
if (state is UpdateUserInfoLoading) {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
setState(() => isLoading = true);
|
||||
} else if (state is UpdateUserInfoSuccess) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('Información actualizada'),
|
||||
));
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Información actualizada')));
|
||||
setState(() => isLoading = false);
|
||||
} else if (state is UpdateUserInfoFailure) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
||||
content: Text('Error al actualizar la información'),
|
||||
));
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Error al actualizar')));
|
||||
setState(() => isLoading = false);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Perfil'),
|
||||
title: const Text('Mi perfil'),
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
body: BlocBuilder<MyUserBloc, MyUserState>(
|
||||
builder: (context, state) {
|
||||
@@ -102,195 +170,21 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 40, vertical: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
pictureWidget(state, context),
|
||||
const SizedBox(height: 30),
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Nombre',
|
||||
prefixIcon: Icon(Icons.person),
|
||||
hintText: 'Nombre (obligatorio)',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su nombre';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
TextFormField(
|
||||
controller: _cityController,
|
||||
readOnly: true,
|
||||
onTap: () async {
|
||||
final cityName = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const CityListScreen();
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
if (cityName != null) {
|
||||
_cityController.text = cityName;
|
||||
}
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Ciudad',
|
||||
prefixIcon: Icon(Icons.near_me_rounded),
|
||||
hintText: 'Selecciona tu ciudad',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0),
|
||||
)),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(color: Colors.red),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderSide: BorderSide(
|
||||
color: Colors.red, width: 2.0),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Por favor, ingrese su nombre';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
_birthdayController.text.isEmpty &&
|
||||
_genderController.text.isEmpty
|
||||
? Column(
|
||||
children: [
|
||||
const SizedBox(height: 20.0),
|
||||
BirthdayPicker(
|
||||
onDateSelected: (birthDay) {
|
||||
_birthdayController.text =
|
||||
DateFormat('dd/MM/yyyy')
|
||||
.format(birthDay);
|
||||
},
|
||||
controller: _birthdayController,
|
||||
),
|
||||
const SizedBox(height: 20.0),
|
||||
GenderDropdown(
|
||||
controller: _genderController,
|
||||
),
|
||||
],
|
||||
)
|
||||
: const SizedBox(),
|
||||
const SizedBox(height: 20),
|
||||
ProfileItem(
|
||||
title: 'Configurar inicio de sesión con correo',
|
||||
subtitle: _emailController.text,
|
||||
leading: Icons.email_rounded,
|
||||
onTap: () {
|
||||
if (state.user!.name == null ||
|
||||
state.user!.name == '') {
|
||||
ScaffoldMessenger.of(context)
|
||||
.clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Por favor, ingrese su nombre')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.user!.city == null ||
|
||||
state.user!.city == '') {
|
||||
ScaffoldMessenger.of(context)
|
||||
.clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Por favor, ingrese su ciudad')));
|
||||
return;
|
||||
}
|
||||
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => _emailController
|
||||
.text.isEmpty
|
||||
? ProfileRegisterEmailScreen()
|
||||
: ProfileUpdatePasswordScreen(
|
||||
email: _emailController.text)),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ProfileItem(
|
||||
title:
|
||||
'Configurar inicio de sesión con celular',
|
||||
subtitle: _phoneController.text,
|
||||
leading: Icons.phone_iphone_rounded,
|
||||
onTap: () {
|
||||
if (state.user!.name == null ||
|
||||
state.user!.name == '') {
|
||||
ScaffoldMessenger.of(context)
|
||||
.clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Por favor, ingrese su nombre')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (state.user!.city == null ||
|
||||
state.user!.city == '') {
|
||||
ScaffoldMessenger.of(context)
|
||||
.clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Por favor, ingrese su nombre')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_phoneController.text.isEmpty) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
const ProfileRegisterPhoneScreen(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_avatarSection(state, context),
|
||||
const SizedBox(height: 8),
|
||||
_formSection(state, context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 0.5,
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
horizontal: 15,
|
||||
),
|
||||
child: saveButton(state, context),
|
||||
vertical: 12, horizontal: 16),
|
||||
child: _saveButton(state, context),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -304,29 +198,220 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget saveButton(MyUserState state, BuildContext context) {
|
||||
Widget _avatarSection(MyUserState state, BuildContext context) {
|
||||
return Container(
|
||||
color: _kPrimary,
|
||||
padding: const EdgeInsets.only(bottom: 28),
|
||||
child: Center(
|
||||
child: Stack(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final picker = ImagePicker();
|
||||
final image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxHeight: 500,
|
||||
maxWidth: 500,
|
||||
imageQuality: 40,
|
||||
);
|
||||
if (image != null) setState(() => _imageFile = image);
|
||||
},
|
||||
child: Hero(
|
||||
tag: 'picture-profile',
|
||||
child: _avatarContainer(state),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.15), blurRadius: 4)
|
||||
],
|
||||
),
|
||||
child:
|
||||
const Icon(Icons.camera_alt_outlined, size: 16, color: _kPrimary),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _avatarContainer(MyUserState state) {
|
||||
ImageProvider<Object>? imageProvider;
|
||||
if (_imageFile?.path != null && _imageFile!.path.isNotEmpty) {
|
||||
imageProvider = FileImage(File(_imageFile!.path));
|
||||
} else if (state.user?.picture != null &&
|
||||
state.user!.picture!.isNotEmpty) {
|
||||
imageProvider = NetworkImage(state.user!.picture!);
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: 96,
|
||||
height: 96,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 3),
|
||||
image: imageProvider == null
|
||||
? null
|
||||
: DecorationImage(image: imageProvider, fit: BoxFit.cover),
|
||||
),
|
||||
child: imageProvider == null
|
||||
? const Icon(CupertinoIcons.person, color: Colors.white70, size: 44)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _formSection(MyUserState state, BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
_field(
|
||||
controller: _nameController,
|
||||
label: 'Nombre',
|
||||
icon: Icons.person_outline_rounded,
|
||||
validator: (v) =>
|
||||
(v == null || v.isEmpty) ? 'Ingresa tu nombre' : null,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
controller: _cityController,
|
||||
readOnly: true,
|
||||
onTap: () async {
|
||||
final cityName = await Navigator.push<String>(
|
||||
context,
|
||||
CupertinoPageRoute(builder: (_) => const CityListScreen()),
|
||||
);
|
||||
if (cityName != null) _cityController.text = cityName;
|
||||
},
|
||||
decoration: _inputDeco(
|
||||
'Ciudad',
|
||||
Icons.location_city_outlined,
|
||||
hint: 'Selecciona tu ciudad',
|
||||
suffixIcon: _isLocating
|
||||
? const Padding(
|
||||
padding: EdgeInsets.all(12),
|
||||
child: SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
),
|
||||
)
|
||||
: IconButton(
|
||||
icon: const Icon(Icons.my_location_outlined),
|
||||
tooltip: 'Usar mi ubicación',
|
||||
onPressed: _useMyLocation,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_birthdayController.text.isEmpty &&
|
||||
_genderController.text.isEmpty) ...[
|
||||
const SizedBox(height: 14),
|
||||
BirthdayPicker(
|
||||
onDateSelected: (d) => _birthdayController.text =
|
||||
DateFormat('dd/MM/yyyy').format(d),
|
||||
controller: _birthdayController,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
GenderDropdown(controller: _genderController),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [BoxShadow(color: context.shadowSm, blurRadius: 8)],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
ProfileItem(
|
||||
title: 'Inicio de sesión con correo',
|
||||
subtitle: _emailController.text,
|
||||
leading: Icons.email_outlined,
|
||||
onTap: () {
|
||||
if (!_validateProfile(state, context)) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) => _emailController.text.isEmpty
|
||||
? ProfileRegisterEmailScreen()
|
||||
: ProfileUpdatePasswordScreen(
|
||||
email: _emailController.text),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Divider(
|
||||
height: 1,
|
||||
thickness: 0.5,
|
||||
color: context.onSurface.withOpacity(0.08)),
|
||||
ProfileItem(
|
||||
title: 'Inicio de sesión con celular',
|
||||
subtitle: _phoneController.text,
|
||||
leading: Icons.phone_iphone_rounded,
|
||||
onTap: () {
|
||||
if (!_validateProfile(state, context)) return;
|
||||
if (_phoneController.text.isEmpty) {
|
||||
Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (_) =>
|
||||
const ProfileRegisterPhoneScreen()),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _validateProfile(MyUserState state, BuildContext context) {
|
||||
if (state.user!.name == null || state.user!.name == '') {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Por favor, ingresa tu nombre')));
|
||||
return false;
|
||||
}
|
||||
if (state.user!.city == null || state.user!.city == '') {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Por favor, ingresa tu ciudad')));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget _saveButton(MyUserState state, BuildContext context) {
|
||||
return ElevatedButton(
|
||||
onPressed: () {
|
||||
if (isLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLoading) return;
|
||||
if (_nameController.text.isEmpty) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Por favor, ingrese su nombre')));
|
||||
|
||||
const SnackBar(content: Text('Por favor, ingresa tu nombre')));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_cityController.text.isEmpty) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Por favor, ingrese su ciudad')));
|
||||
|
||||
const SnackBar(content: Text('Por favor, ingresa tu ciudad')));
|
||||
return;
|
||||
}
|
||||
|
||||
final myUser = state.user!.copyWith(
|
||||
name: _nameController.text,
|
||||
city: _cityController.text,
|
||||
@@ -336,102 +421,62 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
birthday: _birthdayController.text,
|
||||
gender: _genderController.text,
|
||||
);
|
||||
|
||||
context
|
||||
.read<ProfileBloc>()
|
||||
.add(UpdateUserInfo(myUser: myUser, filePicture: _imageFile?.path));
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Información actualizada...')),
|
||||
);
|
||||
|
||||
const SnackBar(content: Text('Actualizando información...')));
|
||||
Navigator.pop(context);
|
||||
},
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 15),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
elevation: 0,
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
child: isLoading
|
||||
? const CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
)
|
||||
: const Text(
|
||||
'Actualizar',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
child: isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: Colors.white))
|
||||
: const Text('Guardar cambios',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
);
|
||||
}
|
||||
|
||||
static InputDecoration _inputDeco(String label, IconData icon,
|
||||
{String? hint, Widget? suffixIcon}) {
|
||||
return InputDecoration(
|
||||
labelText: label,
|
||||
hintText: hint,
|
||||
prefixIcon: Icon(icon),
|
||||
suffixIcon: suffixIcon,
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: _kPrimary, width: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget pictureWidget(MyUserState state, BuildContext context) {
|
||||
final pictureUrl = state.user?.picture;
|
||||
final pathImageFile = _imageFile?.path;
|
||||
|
||||
ImageProvider<Object>? imageProvider;
|
||||
|
||||
if (pathImageFile != null && pathImageFile.isNotEmpty) {
|
||||
imageProvider = FileImage(File(pathImageFile));
|
||||
} else if (pictureUrl != null && pictureUrl.isNotEmpty) {
|
||||
imageProvider = NetworkImage(pictureUrl);
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxHeight: 500,
|
||||
maxWidth: 500,
|
||||
imageQuality: 40,
|
||||
);
|
||||
|
||||
if (image != null) {
|
||||
setState(() {
|
||||
_imageFile = image;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: Hero(
|
||||
tag: 'picture-profile',
|
||||
child: pictureContainerWidget(imageProvider),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget pictureContainerWidget(ImageProvider<Object>? imageProvider) {
|
||||
final image = imageProvider == null
|
||||
? null
|
||||
: DecorationImage(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.contain,
|
||||
);
|
||||
|
||||
final widget = image == null
|
||||
? Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 40,
|
||||
)
|
||||
: null;
|
||||
|
||||
return Container(
|
||||
width: 120,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
image: image,
|
||||
),
|
||||
child: widget,
|
||||
Widget _field({
|
||||
required TextEditingController controller,
|
||||
required String label,
|
||||
required IconData icon,
|
||||
String? Function(String?)? validator,
|
||||
}) {
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
decoration: _inputDeco(label, icon),
|
||||
validator: validator,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+275
-328
@@ -10,9 +10,21 @@ import 'package:score_repository/score_repository.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:user_repository/user_repository.dart';
|
||||
|
||||
const _kPrimary = Color(0xFF1565C0);
|
||||
|
||||
extension _Th on BuildContext {
|
||||
ThemeData get _t => Theme.of(this);
|
||||
Color get bg => _t.scaffoldBackgroundColor;
|
||||
Color get card => _t.cardColor;
|
||||
Color get onSurface => _t.colorScheme.onSurface;
|
||||
Color get muted => _t.colorScheme.onSurface.withOpacity(0.55);
|
||||
bool get isDark => _t.brightness == Brightness.dark;
|
||||
Color get shadowSm =>
|
||||
isDark ? Colors.transparent : Colors.black.withOpacity(0.05);
|
||||
}
|
||||
|
||||
class ScoreScreen extends StatefulWidget {
|
||||
final ServiceEntity service;
|
||||
|
||||
const ScoreScreen({Key? key, required this.service}) : super(key: key);
|
||||
|
||||
@override
|
||||
@@ -21,7 +33,7 @@ class ScoreScreen extends StatefulWidget {
|
||||
|
||||
class _ScoreScreenState extends State<ScoreScreen> {
|
||||
double _rating = 1.0;
|
||||
TextEditingController commentController = TextEditingController();
|
||||
final TextEditingController _commentController = TextEditingController();
|
||||
late Future<List<dynamic>> _userInfoFuture;
|
||||
late bool isProfessional;
|
||||
late String userId;
|
||||
@@ -29,12 +41,9 @@ class _ScoreScreenState extends State<ScoreScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_userInfoFuture = _getUserAndProfessionalInfo(widget.service);
|
||||
_userInfoFuture = _getUserInfo(widget.service);
|
||||
isProfessional =
|
||||
ApiUserRepository.currentUserId ?? '' == widget.service.userId
|
||||
? true
|
||||
: false;
|
||||
|
||||
(ApiUserRepository.currentUserId ?? '') == widget.service.userId;
|
||||
userId =
|
||||
isProfessional ? widget.service.professionalId : widget.service.userId;
|
||||
}
|
||||
@@ -42,10 +51,14 @@ class _ScoreScreenState extends State<ScoreScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => Injector.appInstance.get<ScoreBloc>(),
|
||||
create: (_) => Injector.appInstance.get<ScoreBloc>(),
|
||||
child: Scaffold(
|
||||
backgroundColor: context.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text('Calificación'),
|
||||
title: const Text('Calificar servicio'),
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
@@ -53,311 +66,42 @@ class _ScoreScreenState extends State<ScoreScreen> {
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
FutureBuilder(
|
||||
FutureBuilder<List<dynamic>>(
|
||||
future: _userInfoFuture,
|
||||
builder:
|
||||
(context, AsyncSnapshot<List<dynamic>> snapshot) {
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState ==
|
||||
ConnectionState.waiting) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator());
|
||||
} else {
|
||||
if (snapshot.hasError) {
|
||||
return Center(
|
||||
child:
|
||||
Text('Error inesperado: ${snapshot.error}'),
|
||||
);
|
||||
} else {
|
||||
final userInfo = snapshot.data![0] as MyUser;
|
||||
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 95,
|
||||
height: 95,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
image: userInfo.picture == null
|
||||
? null
|
||||
: DecorationImage(
|
||||
image: NetworkImage(
|
||||
userInfo.picture!),
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
child: userInfo.picture == null
|
||||
? Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 50,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'${userInfo.name}',
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 15,
|
||||
)
|
||||
],
|
||||
),
|
||||
GeneralReputation(
|
||||
userId: userId,
|
||||
builder: (BuildContext context,
|
||||
ReputationEntity reputation) {
|
||||
final double average;
|
||||
|
||||
if (isProfessional) {
|
||||
average = reputation.averagePro;
|
||||
} else {
|
||||
average = reputation.average;
|
||||
}
|
||||
|
||||
return Positioned(
|
||||
top: 3,
|
||||
right:
|
||||
MediaQuery.of(context).size.width *
|
||||
0.3,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 3,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius:
|
||||
BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black
|
||||
.withOpacity(0.1),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 2,
|
||||
offset: const Offset(
|
||||
0,
|
||||
1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.star,
|
||||
color: Colors.yellow,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Flexible(
|
||||
child: Text(
|
||||
average.toStringAsFixed(2),
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.symmetric(horizontal: 15),
|
||||
// child: ListTile(
|
||||
// leading: Container(
|
||||
// width: 60,
|
||||
// height: 60,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.grey.shade300,
|
||||
// shape: BoxShape.circle,
|
||||
// image: userInfo.picture == null
|
||||
// ? null
|
||||
// : DecorationImage(
|
||||
// image: NetworkImage(
|
||||
// userInfo.picture ?? ''),
|
||||
// fit: BoxFit.contain,
|
||||
// ),
|
||||
// ),
|
||||
// child: userInfo.picture == null
|
||||
// ? Icon(
|
||||
// CupertinoIcons.person,
|
||||
// color: Colors.grey.shade400,
|
||||
// size: 40,
|
||||
// )
|
||||
// : null,
|
||||
// ),
|
||||
// title: Text(
|
||||
// userInfo.name ?? '',
|
||||
// overflow: TextOverflow.ellipsis,
|
||||
// style: const TextStyle(
|
||||
// fontSize: 15,
|
||||
// fontWeight: FontWeight.w600,
|
||||
// ),
|
||||
// ),
|
||||
// subtitle: const Text(
|
||||
// 'Rating: 5.0',
|
||||
// style: TextStyle(
|
||||
// fontSize: 13,
|
||||
// color: Colors.blue,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
}
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(40),
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
if (snapshot.hasError) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text('Error: ${snapshot.error}'),
|
||||
);
|
||||
}
|
||||
final userInfo = snapshot.data![0] as MyUser;
|
||||
return _profileHeader(context, userInfo);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Text(
|
||||
'Califica el servicio',
|
||||
style:
|
||||
TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
RatingBar.builder(
|
||||
initialRating: _rating,
|
||||
minRating: 1,
|
||||
direction: Axis.horizontal,
|
||||
allowHalfRating: true,
|
||||
itemCount: 5,
|
||||
itemSize: 40,
|
||||
glow: false,
|
||||
maxRating: 5,
|
||||
itemPadding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
itemBuilder: (context, _) => const Icon(
|
||||
Icons.star,
|
||||
color: Color(0xFF2BA4EC),
|
||||
),
|
||||
onRatingUpdate: (rating) {
|
||||
setState(() {
|
||||
_rating = rating;
|
||||
});
|
||||
},
|
||||
ignoreGestures: false,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
customMessage(_rating),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Color(0xFF2BA4EC),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 40, vertical: 40),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Comentario',
|
||||
style: TextStyle(
|
||||
fontSize: 20, fontWeight: FontWeight.w600),
|
||||
),
|
||||
TextFormField(
|
||||
maxLines: null,
|
||||
maxLength: 400,
|
||||
keyboardType: TextInputType.multiline,
|
||||
controller: commentController,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
_ratingSection(context),
|
||||
_commentSection(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
height: 1,
|
||||
thickness: 0.5,
|
||||
),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
BlocProvider<ServiceBloc>(
|
||||
create: (context) => Injector.appInstance.get<ServiceBloc>(),
|
||||
create: (_) => Injector.appInstance.get<ServiceBloc>(),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
horizontal: 15,
|
||||
),
|
||||
vertical: 12, horizontal: 16),
|
||||
child: BlocBuilder<ServiceBloc, ServiceState>(
|
||||
builder: (context, serviceState) {
|
||||
return FilledButton(
|
||||
onPressed: () {
|
||||
final CommentEntity comment = widget.service.userId ==
|
||||
ApiUserRepository.currentUserId ?? ''
|
||||
? CommentEntity(
|
||||
serviceId: widget.service.id!,
|
||||
authorId:
|
||||
ApiUserRepository.currentUserId ?? '',
|
||||
isFromUser: true,
|
||||
score: _rating,
|
||||
destinationId: widget.service.professionalId,
|
||||
content: commentController.text.trim(),
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
)
|
||||
: CommentEntity(
|
||||
serviceId: widget.service.id!,
|
||||
authorId:
|
||||
ApiUserRepository.currentUserId ?? '',
|
||||
isFromUser: false,
|
||||
score: _rating,
|
||||
destinationId: widget.service.userId,
|
||||
content: commentController.text.trim(),
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
);
|
||||
|
||||
BlocProvider.of<ScoreBloc>(context)
|
||||
.add(SendScoreEvent(comment: comment));
|
||||
|
||||
if (widget.service.userId ==
|
||||
ApiUserRepository.currentUserId ?? '') {
|
||||
context.read<ServiceBloc>().add(
|
||||
UpdateProfessionalScored(widget.service.id!));
|
||||
} else {
|
||||
context
|
||||
.read<ServiceBloc>()
|
||||
.add(UpdateUserScored(widget.service.id!));
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
padding: const EdgeInsets.symmetric(vertical: 15),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: double.infinity,
|
||||
child: const Text(
|
||||
'Enviar calificación',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return _sendButton(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -368,38 +112,241 @@ class _ScoreScreenState extends State<ScoreScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
String customMessage(double rating) {
|
||||
if (rating > 4.0) {
|
||||
return '¡Excelente! 👏🌟';
|
||||
}
|
||||
|
||||
if (rating < 2.0) {
|
||||
return '¡Malo! 😔❌';
|
||||
}
|
||||
|
||||
if (rating <= 4.0 && rating >= 3.0) {
|
||||
return '¡Bueno! 👍😊';
|
||||
}
|
||||
|
||||
if (rating < 3.0 && rating >= 2.0) {
|
||||
return '¡Regular! 😐🔄';
|
||||
}
|
||||
|
||||
return '';
|
||||
Widget _profileHeader(BuildContext context, MyUser user) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadowSm,
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 2))
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 84,
|
||||
height: 84,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: _kPrimary.withOpacity(0.25), width: 3),
|
||||
color: Colors.grey.shade200,
|
||||
image: user.picture != null && user.picture!.isNotEmpty
|
||||
? DecorationImage(
|
||||
image: NetworkImage(user.picture!),
|
||||
fit: BoxFit.cover)
|
||||
: null,
|
||||
),
|
||||
child: user.picture == null || user.picture!.isEmpty
|
||||
? Icon(CupertinoIcons.person,
|
||||
color: Colors.grey.shade500, size: 38)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(user.name ?? '',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.onSurface)),
|
||||
],
|
||||
),
|
||||
GeneralReputation(
|
||||
userId: userId,
|
||||
builder: (_, ReputationEntity reputation) {
|
||||
final average = isProfessional
|
||||
? reputation.averagePro
|
||||
: reputation.average;
|
||||
return Positioned(
|
||||
top: 0,
|
||||
right: MediaQuery.of(context).size.width * 0.18,
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: context.shadowSm,
|
||||
blurRadius: 6,
|
||||
spreadRadius: 1)
|
||||
],
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
const Icon(Icons.star, color: Colors.amber, size: 14),
|
||||
const SizedBox(width: 3),
|
||||
Text(average.toStringAsFixed(1),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: context.onSurface)),
|
||||
]),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<dynamic>> _getUserAndProfessionalInfo(
|
||||
ServiceEntity service) async {
|
||||
Widget _ratingSection(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: context.shadowSm, blurRadius: 8)],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text('¿Cómo fue el servicio?',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.onSurface)),
|
||||
const SizedBox(height: 14),
|
||||
RatingBar.builder(
|
||||
initialRating: _rating,
|
||||
minRating: 1,
|
||||
direction: Axis.horizontal,
|
||||
allowHalfRating: true,
|
||||
itemCount: 5,
|
||||
itemSize: 42,
|
||||
glow: false,
|
||||
maxRating: 5,
|
||||
itemPadding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
itemBuilder: (_, __) =>
|
||||
const Icon(Icons.star_rounded, color: _kPrimary),
|
||||
onRatingUpdate: (r) => setState(() => _rating = r),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_ratingMessage(_rating),
|
||||
style:
|
||||
TextStyle(fontSize: 14, color: _kPrimary, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _commentSection(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.fromLTRB(16, 12, 16, 16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [BoxShadow(color: context.shadowSm, blurRadius: 8)],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Comentario (opcional)',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: context.onSurface)),
|
||||
const SizedBox(height: 10),
|
||||
TextFormField(
|
||||
controller: _commentController,
|
||||
maxLines: 4,
|
||||
maxLength: 400,
|
||||
keyboardType: TextInputType.multiline,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Cuéntanos tu experiencia...',
|
||||
hintStyle: TextStyle(color: context.muted, fontSize: 13),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: _kPrimary, width: 2),
|
||||
),
|
||||
contentPadding: const EdgeInsets.all(12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _sendButton(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
final isUser = widget.service.userId ==
|
||||
(ApiUserRepository.currentUserId ?? '');
|
||||
final comment = CommentEntity(
|
||||
serviceId: widget.service.id!,
|
||||
authorId: ApiUserRepository.currentUserId ?? '',
|
||||
isFromUser: isUser,
|
||||
score: _rating,
|
||||
destinationId: isUser
|
||||
? widget.service.professionalId
|
||||
: widget.service.userId,
|
||||
content: _commentController.text.trim(),
|
||||
createdAt: DateTime.now().toIso8601String(),
|
||||
);
|
||||
BlocProvider.of<ScoreBloc>(context)
|
||||
.add(SendScoreEvent(comment: comment));
|
||||
if (isUser) {
|
||||
context
|
||||
.read<ServiceBloc>()
|
||||
.add(UpdateProfessionalScored(widget.service.id!));
|
||||
} else {
|
||||
context
|
||||
.read<ServiceBloc>()
|
||||
.add(UpdateUserScored(widget.service.id!));
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
icon: const Icon(Icons.send_rounded, size: 18),
|
||||
label: const Text('Enviar calificación',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _ratingMessage(double rating) {
|
||||
if (rating > 4.0) return '¡Excelente!';
|
||||
if (rating < 2.0) return 'Necesita mejorar';
|
||||
if (rating >= 3.0) return '¡Bien!';
|
||||
return 'Regular';
|
||||
}
|
||||
|
||||
Future<List<dynamic>> _getUserInfo(ServiceEntity service) async {
|
||||
final userRepo = Injector.appInstance.get<UserRepository>();
|
||||
|
||||
final MyUser? userInfo;
|
||||
|
||||
if (ApiUserRepository.currentUserId ?? '' == service.userId) {
|
||||
userInfo = await userRepo.getMyUser(service.professionalId);
|
||||
} else {
|
||||
userInfo = await userRepo.getMyUser(service.userId);
|
||||
}
|
||||
|
||||
final currentId = ApiUserRepository.currentUserId ?? '';
|
||||
final targetId =
|
||||
currentId == service.userId ? service.professionalId : service.userId;
|
||||
final userInfo = await userRepo.getMyUser(targetId);
|
||||
return [userInfo];
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injector/injector.dart';
|
||||
import 'package:prosappco/blocs/suggestion_bloc/suggestion_bloc.dart';
|
||||
|
||||
const _kPrimary = Color(0xFF1565C0);
|
||||
|
||||
class SuggestionScreen extends StatefulWidget {
|
||||
const SuggestionScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SuggestionScreen> createState() => _SuggestionScreenState();
|
||||
}
|
||||
|
||||
class _SuggestionScreenState extends State<SuggestionScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _messageController = TextEditingController();
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_messageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<SuggestionBloc>(
|
||||
create: (_) => Injector.appInstance.get<SuggestionBloc>(),
|
||||
child: BlocListener<SuggestionBloc, SuggestionState>(
|
||||
listener: (context, state) {
|
||||
if (state is SuggestionLoading) {
|
||||
setState(() => _isLoading = true);
|
||||
} else if (state is SuggestionSuccess) {
|
||||
setState(() => _isLoading = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('¡Gracias por tu sugerencia!')),
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
} else if (state is SuggestionFailure) {
|
||||
setState(() => _isLoading = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('No se pudo enviar la sugerencia'),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(title: const Text('Sugerencias')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'¿Tienes una idea o algo que podamos mejorar? '
|
||||
'Cuéntanos.',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
controller: _messageController,
|
||||
minLines: 5,
|
||||
maxLines: 8,
|
||||
maxLength: 1000,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Escribe tu sugerencia aquí...',
|
||||
alignLabelWithHint: true,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide:
|
||||
const BorderSide(color: _kPrimary, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (v) => (v == null || v.trim().isEmpty)
|
||||
? 'Escribe un mensaje'
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
onPressed: _isLoading
|
||||
? null
|
||||
: () {
|
||||
if (_formKey.currentState?.validate() != true) {
|
||||
return;
|
||||
}
|
||||
context.read<SuggestionBloc>().add(
|
||||
SubmitSuggestion(
|
||||
message: _messageController.text.trim(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: _isLoading
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('Enviar'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -195,6 +195,7 @@ class UserCalendarScreenState extends State<UserCalendarScreen> {
|
||||
List<TimeOfDay> ranges = TimeOfDayUtils.genRanges(
|
||||
schedule.range1Hour1!,
|
||||
schedule.range2Hour2!,
|
||||
stepMinutes: widget.userProfessional.professionalInfo.slotDurationMinutes,
|
||||
);
|
||||
|
||||
return rangesItemList(ranges, _services, today);
|
||||
@@ -215,10 +216,12 @@ class UserCalendarScreenState extends State<UserCalendarScreen> {
|
||||
List<TimeOfDay> ranges1 = TimeOfDayUtils.genRanges(
|
||||
schedule.range1Hour1!,
|
||||
schedule.range1Hour2!,
|
||||
stepMinutes: widget.userProfessional.professionalInfo.slotDurationMinutes,
|
||||
);
|
||||
List<TimeOfDay> ranges2 = TimeOfDayUtils.genRanges(
|
||||
schedule.range2Hour1!,
|
||||
schedule.range2Hour2!,
|
||||
stepMinutes: widget.userProfessional.professionalInfo.slotDurationMinutes,
|
||||
);
|
||||
|
||||
return [
|
||||
|
||||
@@ -19,8 +19,11 @@ import 'package:prosappco/blocs/service_bloc/service_bloc.dart';
|
||||
import 'package:prosappco/constansts.dart';
|
||||
import 'package:prosappco/local_notifications/local_notifications.dart';
|
||||
import 'package:prosappco/screens/lists/professional_list_screen.dart';
|
||||
import 'package:prosappco/screens/profile/profile_screen.dart';
|
||||
import 'package:prosappco/screens/user/user_service_screen.dart';
|
||||
import 'package:prosappco/utils/nominatim_geocoder.dart';
|
||||
import 'package:prosappco/utils/time_of_day_extension.dart';
|
||||
import 'package:prosappco/utils/version_utils.dart';
|
||||
import 'package:service_repository/service_repository.dart';
|
||||
import 'package:setting_repository/setting_repository.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
@@ -42,7 +45,7 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
|
||||
final settingRepository = Injector.appInstance.get<SettingRepository>();
|
||||
SettingEntity? settings;
|
||||
late String appVersion;
|
||||
String appVersion = '';
|
||||
|
||||
final DateFormat formatter = DateFormat('dd/MM/yyyy');
|
||||
|
||||
@@ -125,7 +128,7 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
|
||||
void _checkForUpdate(SettingEntity settings) {
|
||||
if (Platform.isAndroid) {
|
||||
if (appVersion != settings.versionAndroid) {
|
||||
if (isUpdateRequired(appVersion, settings.versionAndroid)) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
@@ -165,7 +168,7 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
}
|
||||
}
|
||||
if (Platform.isIOS) {
|
||||
if (appVersion != settings.versionIos) {
|
||||
if (isUpdateRequired(appVersion, settings.versionIos)) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
@@ -377,9 +380,16 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
state.user?.phone == null) {
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'Por favor completa tu perfil y agrega tu celular'),
|
||||
SnackBar(
|
||||
content: const Text('Por favor completa tu perfil y agrega tu celular'),
|
||||
action: SnackBarAction(
|
||||
label: 'Ir al perfil',
|
||||
onPressed: () {
|
||||
Navigator.push(context, CupertinoPageRoute(
|
||||
builder: (context) => const ProfileScreen(),
|
||||
));
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
@@ -552,7 +562,10 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
description: _observationController.text,
|
||||
range1Hour1: horaSeleccionada!,
|
||||
range1Hour2:
|
||||
horaSeleccionada!.add(hour: 2),
|
||||
horaSeleccionada!.add(
|
||||
minute: profesionalSeleccionado!
|
||||
.professionalInfo
|
||||
.slotDurationMinutes),
|
||||
rate: profesionalSeleccionado!
|
||||
.professionalInfo.rate,
|
||||
location: serviceLocationPreference!,
|
||||
@@ -577,7 +590,10 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
description: _observationController.text,
|
||||
range1Hour1: horaSeleccionada!,
|
||||
range1Hour2:
|
||||
horaSeleccionada!.add(hour: 2),
|
||||
horaSeleccionada!.add(
|
||||
minute: profesionalSeleccionado!
|
||||
.professionalInfo
|
||||
.slotDurationMinutes),
|
||||
rate: '0',
|
||||
location: serviceLocationPreference!,
|
||||
),
|
||||
@@ -600,7 +616,10 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
description: _observationController.text,
|
||||
range1Hour1: horaSeleccionada!,
|
||||
range1Hour2:
|
||||
horaSeleccionada!.add(hour: 2),
|
||||
horaSeleccionada!.add(
|
||||
minute: profesionalSeleccionado!
|
||||
.professionalInfo
|
||||
.slotDurationMinutes),
|
||||
rate: profesionalSeleccionado!
|
||||
.professionalInfo.rate,
|
||||
location: serviceLocationPreference!,
|
||||
@@ -620,7 +639,10 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
description: _observationController.text,
|
||||
range1Hour1: horaSeleccionada!,
|
||||
range1Hour2:
|
||||
horaSeleccionada!.add(hour: 2),
|
||||
horaSeleccionada!.add(
|
||||
minute: profesionalSeleccionado!
|
||||
.professionalInfo
|
||||
.slotDurationMinutes),
|
||||
rate: '0',
|
||||
location: serviceLocationPreference!,
|
||||
),
|
||||
@@ -745,6 +767,25 @@ class _UserMapScreenState extends State<UserMapScreen> {
|
||||
);
|
||||
});
|
||||
|
||||
_animateCameraToPosition(_currentP!);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
await _locateByUserCity();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _locateByUserCity() async {
|
||||
try {
|
||||
final city = Injector.appInstance.get<MyUserBloc>().state.user?.city;
|
||||
if (city == null || city.isEmpty) return;
|
||||
|
||||
final coords = await NominatimGeocoder.forwardGeocodeCity(city);
|
||||
if (coords == null) return;
|
||||
|
||||
setState(() {
|
||||
_currentP = LatLng(coords.$1, coords.$2);
|
||||
});
|
||||
|
||||
_animateCameraToPosition(_currentP!);
|
||||
} catch (e) {
|
||||
log(e.toString());
|
||||
|
||||
@@ -1,204 +1,279 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:prosappco/blocs/professional_list_bloc/professional_list_bloc.dart';
|
||||
|
||||
class UserViewProfileScreen extends StatelessWidget {
|
||||
UserProfessional userProfessional;
|
||||
const _kPrimary = Color(0xFF1565C0);
|
||||
|
||||
UserViewProfileScreen({
|
||||
extension _Th on BuildContext {
|
||||
ThemeData get _t => Theme.of(this);
|
||||
Color get bg => _t.scaffoldBackgroundColor;
|
||||
Color get card => _t.cardColor;
|
||||
Color get onSurface => _t.colorScheme.onSurface;
|
||||
Color get muted => _t.colorScheme.onSurface.withOpacity(0.55);
|
||||
Color get subtle => _t.colorScheme.onSurface.withOpacity(0.35);
|
||||
bool get isDark => _t.brightness == Brightness.dark;
|
||||
Color get shadowSm =>
|
||||
isDark ? Colors.transparent : Colors.black.withOpacity(0.05);
|
||||
}
|
||||
|
||||
class UserViewProfileScreen extends StatelessWidget {
|
||||
final UserProfessional userProfessional;
|
||||
|
||||
const UserViewProfileScreen({
|
||||
super.key,
|
||||
required this.userProfessional,
|
||||
});
|
||||
|
||||
final double bannerHeight = 200;
|
||||
final double profileHeight = 160;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Perfil Profesional'),
|
||||
),
|
||||
body: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
buildTop(),
|
||||
buildContent(),
|
||||
backgroundColor: context.bg,
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
_SliverHeader(userProfessional: userProfessional),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
_nameSection(context),
|
||||
const SizedBox(height: 16),
|
||||
if (userProfessional
|
||||
.professionalInfo.specializations.isNotEmpty)
|
||||
_sectionCard(
|
||||
context,
|
||||
icon: Icons.stars_outlined,
|
||||
title: 'Especialidades',
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: userProfessional
|
||||
.professionalInfo.specializations
|
||||
.map((s) => _Chip(label: s))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
if (userProfessional.professionalInfo.specializations.isNotEmpty)
|
||||
const SizedBox(height: 12),
|
||||
if (userProfessional.professionalInfo.rate.isNotEmpty)
|
||||
_sectionCard(
|
||||
context,
|
||||
icon: Icons.payments_outlined,
|
||||
title: 'Tarifa de consulta',
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
_formatCurrency(
|
||||
int.tryParse(userProfessional
|
||||
.professionalInfo.rate) ??
|
||||
0),
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.onSurface),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text('por consulta',
|
||||
style: TextStyle(
|
||||
fontSize: 12, color: context.muted)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (userProfessional.professionalInfo.rate.isNotEmpty)
|
||||
const SizedBox(height: 12),
|
||||
if (userProfessional.professionalInfo.paymentMethods.datafono ||
|
||||
userProfessional.professionalInfo.paymentMethods.nequi ||
|
||||
userProfessional
|
||||
.professionalInfo.paymentMethods.transferencia)
|
||||
_sectionCard(
|
||||
context,
|
||||
icon: Icons.credit_card_outlined,
|
||||
title: 'Métodos de pago',
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
if (userProfessional
|
||||
.professionalInfo.paymentMethods.datafono)
|
||||
_Chip(label: 'Datafono', icon: Icons.point_of_sale_outlined),
|
||||
if (userProfessional
|
||||
.professionalInfo.paymentMethods.nequi)
|
||||
_Chip(label: 'Nequi', icon: Icons.phone_android_outlined),
|
||||
if (userProfessional
|
||||
.professionalInfo.paymentMethods.transferencia)
|
||||
_Chip(
|
||||
label: 'Transferencia',
|
||||
icon: Icons.account_balance_outlined),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Stack buildTop() {
|
||||
final top = bannerHeight - profileHeight / 2;
|
||||
final bottom = profileHeight / 2;
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: bottom),
|
||||
child: buildBannerImage(),
|
||||
),
|
||||
Positioned(
|
||||
top: top,
|
||||
child: buildProfileImage(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
buildContent() {
|
||||
Widget _nameSection(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
userProfessional.myUser.name ?? '',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: context.onSurface),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${userProfessional.professionalInfo.profession}, ${userProfessional.myUser.city ?? ''}',
|
||||
'${userProfessional.professionalInfo.profession} · ${userProfessional.myUser.city ?? ''}',
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(fontSize: 18, color: Colors.black54),
|
||||
style: TextStyle(fontSize: 14, color: context.muted),
|
||||
),
|
||||
const Divider(),
|
||||
const Text(
|
||||
'Especialidades:',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
userProfessional.professionalInfo.specializations.isEmpty
|
||||
? const Text(
|
||||
'No posee especialidades',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 15, color: Colors.black45),
|
||||
)
|
||||
: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
children: userProfessional.professionalInfo.specializations
|
||||
.map((specialization) {
|
||||
return Chip(
|
||||
label: Text(specialization),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
Visibility(
|
||||
visible: userProfessional.professionalInfo.rate.isNotEmpty,
|
||||
child: const Divider(),
|
||||
),
|
||||
Visibility(
|
||||
visible: userProfessional.professionalInfo.rate.isNotEmpty,
|
||||
child: const Text(
|
||||
'Tarifa:',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
Visibility(
|
||||
visible: userProfessional.professionalInfo.rate.isNotEmpty,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
children: [
|
||||
Chip(label: Text('\$${userProfessional.professionalInfo.rate}')),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Divider(),
|
||||
const Text(
|
||||
'Metodos de pago recibidos:',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
userProfessional.professionalInfo.paymentMethods.datafono ||
|
||||
userProfessional.professionalInfo.paymentMethods.nequi ||
|
||||
userProfessional.professionalInfo.paymentMethods.transferencia
|
||||
? Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
alignment: WrapAlignment.center,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: userProfessional
|
||||
.professionalInfo.paymentMethods.datafono,
|
||||
child: const Chip(label: Text('Datafono')),
|
||||
),
|
||||
Visibility(
|
||||
visible:
|
||||
userProfessional.professionalInfo.paymentMethods.nequi,
|
||||
child: const Chip(label: Text('Nequi')),
|
||||
),
|
||||
Visibility(
|
||||
visible: userProfessional
|
||||
.professionalInfo.paymentMethods.transferencia,
|
||||
child: const Chip(label: Text('Transferencia Bancaria')),
|
||||
),
|
||||
],
|
||||
)
|
||||
: const Text(
|
||||
'No hay metodos de pago registrados',
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 15, color: Colors.black45),
|
||||
),
|
||||
const Divider(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Container buildProfileImage() {
|
||||
Widget _sectionCard(BuildContext context,
|
||||
{required IconData icon,
|
||||
required String title,
|
||||
required Widget child}) {
|
||||
return Container(
|
||||
width: 155,
|
||||
height: 155,
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: Colors.white,
|
||||
width: 5,
|
||||
),
|
||||
color: context.card,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [
|
||||
BoxShadow(color: context.shadowSm, blurRadius: 10)
|
||||
],
|
||||
),
|
||||
child: Container(
|
||||
width: 150,
|
||||
height: 150,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(width: 0),
|
||||
image: userProfessional.myUser.picture == null
|
||||
? null
|
||||
: DecorationImage(
|
||||
image: NetworkImage(userProfessional.myUser.picture ?? ''),
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
child: userProfessional.myUser.picture == null
|
||||
? Icon(
|
||||
CupertinoIcons.person,
|
||||
color: Colors.grey.shade400,
|
||||
size: 40,
|
||||
)
|
||||
: null,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: _kPrimary),
|
||||
const SizedBox(width: 7),
|
||||
Text(title,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _kPrimary)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
child,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Container buildBannerImage() {
|
||||
return Container(
|
||||
color: Colors.grey,
|
||||
child: Image.network(
|
||||
userProfessional.professionalInfo.bannerPicture,
|
||||
fit: BoxFit.cover,
|
||||
width: double.infinity,
|
||||
height: bannerHeight,
|
||||
String _formatCurrency(int n) {
|
||||
final formatter =
|
||||
NumberFormat.currency(locale: 'es_CO', decimalDigits: 0, symbol: '');
|
||||
return '\$${formatter.format(n)}';
|
||||
}
|
||||
}
|
||||
|
||||
class _SliverHeader extends StatelessWidget {
|
||||
final UserProfessional userProfessional;
|
||||
const _SliverHeader({required this.userProfessional});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SliverAppBar(
|
||||
expandedHeight: 220,
|
||||
pinned: true,
|
||||
backgroundColor: _kPrimary,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
collapseMode: CollapseMode.parallax,
|
||||
background: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Banner
|
||||
Image.network(
|
||||
userProfessional.professionalInfo.bannerPicture,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) =>
|
||||
Container(color: _kPrimary.withOpacity(0.6)),
|
||||
),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withOpacity(0.45),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
// Avatar centered at bottom
|
||||
Positioned(
|
||||
bottom: 12,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 82,
|
||||
height: 82,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 3),
|
||||
color: Colors.grey.shade300,
|
||||
image: userProfessional.myUser.picture == null
|
||||
? null
|
||||
: DecorationImage(
|
||||
image: NetworkImage(
|
||||
userProfessional.myUser.picture!),
|
||||
fit: BoxFit.cover),
|
||||
),
|
||||
child: userProfessional.myUser.picture == null
|
||||
? Icon(CupertinoIcons.person,
|
||||
color: Colors.grey.shade400, size: 40)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Chip extends StatelessWidget {
|
||||
final String label;
|
||||
final IconData? icon;
|
||||
const _Chip({required this.label, this.icon});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: _kPrimary.withOpacity(0.07),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: _kPrimary.withOpacity(0.2)),
|
||||
),
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
||||
if (icon != null) ...[
|
||||
Icon(icon, size: 13, color: _kPrimary),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Text(label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _kPrimary)),
|
||||
]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class NominatimGeocoder {
|
||||
static Future<String?> reverseGeocodeCity(double lat, double lng) async {
|
||||
final uri = Uri.parse(
|
||||
'https://nominatim.openstreetmap.org/reverse'
|
||||
'?format=json&lat=$lat&lon=$lng&zoom=10&addressdetails=1',
|
||||
);
|
||||
final res = await http.get(
|
||||
uri,
|
||||
headers: {'User-Agent': 'ProsApp/1.0 (prosapp.co)'},
|
||||
);
|
||||
final data = jsonDecode(res.body) as Map<String, dynamic>;
|
||||
final address = data['address'] as Map<String, dynamic>?;
|
||||
return address?['city'] as String? ??
|
||||
address?['town'] as String? ??
|
||||
address?['municipality'] as String? ??
|
||||
address?['county'] as String?;
|
||||
}
|
||||
|
||||
static Future<(double lat, double lng)?> forwardGeocodeCity(
|
||||
String cityName) async {
|
||||
final uri = Uri.parse(
|
||||
'https://nominatim.openstreetmap.org/search'
|
||||
'?format=json&limit=1&q=${Uri.encodeQueryComponent(cityName)}',
|
||||
);
|
||||
final res = await http.get(
|
||||
uri,
|
||||
headers: {'User-Agent': 'ProsApp/1.0 (prosapp.co)'},
|
||||
);
|
||||
final data = jsonDecode(res.body) as List;
|
||||
if (data.isEmpty) return null;
|
||||
final first = data.first as Map<String, dynamic>;
|
||||
final lat = double.tryParse(first['lat']?.toString() ?? '');
|
||||
final lng = double.tryParse(first['lon']?.toString() ?? '');
|
||||
if (lat == null || lng == null) return null;
|
||||
return (lat, lng);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
extension TimeOfDayExtension on TimeOfDay {
|
||||
/// Adds the given offset, carrying minutes into hours.
|
||||
///
|
||||
/// Without the carry, adding a minute-based step (e.g. 45) would leave the
|
||||
/// hour untouched and produce values like "8:90", which makes [isBefore]
|
||||
/// loops run forever. The hour is intentionally NOT wrapped at 24 so that
|
||||
/// comparisons against an end-of-day bound still terminate.
|
||||
TimeOfDay add({int hour = 0, int minute = 0}) {
|
||||
return replacing(hour: this.hour + hour, minute: this.minute + minute);
|
||||
final totalMinutes = (this.hour + hour) * 60 + this.minute + minute;
|
||||
return TimeOfDay(hour: totalMinutes ~/ 60, minute: totalMinutes % 60);
|
||||
}
|
||||
|
||||
int compareTo(TimeOfDay other) {
|
||||
|
||||
@@ -2,13 +2,14 @@ import 'package:flutter/material.dart';
|
||||
import 'package:prosappco/utils/time_of_day_extension.dart';
|
||||
|
||||
class TimeOfDayUtils {
|
||||
static List<TimeOfDay> genRanges(TimeOfDay timeStart, TimeOfDay timeEnd) {
|
||||
static List<TimeOfDay> genRanges(TimeOfDay timeStart, TimeOfDay timeEnd,
|
||||
{int stepMinutes = 30}) {
|
||||
final step = stepMinutes.clamp(5, 480);
|
||||
List<TimeOfDay> ranges = [];
|
||||
TimeOfDay current = timeStart;
|
||||
while (current.isBefore(timeEnd)) {
|
||||
ranges.add(current);
|
||||
// Sumar 2 horas al objeto DateTime
|
||||
current = current.add(hour: 2);
|
||||
current = current.add(minute: step);
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/// Compares dotted numeric versions, e.g. "1.0.14" vs "1.0.2".
|
||||
///
|
||||
/// Returns a negative number when [a] is older than [b], 0 when they are
|
||||
/// equivalent, and a positive number when [a] is newer. Missing segments count
|
||||
/// as 0, so "1.0" and "1.0.0" are equivalent. Returns null when either side
|
||||
/// cannot be parsed.
|
||||
int? compareVersions(String? a, String? b) {
|
||||
final left = _segments(a);
|
||||
final right = _segments(b);
|
||||
if (left == null || right == null) return null;
|
||||
|
||||
final length = left.length > right.length ? left.length : right.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
final l = i < left.length ? left[i] : 0;
|
||||
final r = i < right.length ? right[i] : 0;
|
||||
if (l != r) return l - r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// Whether [current] is strictly older than [minimum].
|
||||
///
|
||||
/// Deliberately fails open: a missing or unparseable value returns false, so a
|
||||
/// backend misconfiguration can never lock users out of the app behind the
|
||||
/// blocking "you must update" dialog. Equal or newer versions are fine too — a
|
||||
/// build ahead of the configured minimum is not out of date.
|
||||
bool isUpdateRequired(String? current, String? minimum) {
|
||||
final result = compareVersions(current, minimum);
|
||||
if (result == null) return false;
|
||||
return result < 0;
|
||||
}
|
||||
|
||||
List<int>? _segments(String? version) {
|
||||
if (version == null) return null;
|
||||
final trimmed = version.trim();
|
||||
if (trimmed.isEmpty) return null;
|
||||
|
||||
// Tolerate build suffixes such as "1.0.14+14" or "1.0.14-beta".
|
||||
final core = trimmed.split(RegExp(r'[+\-]')).first;
|
||||
final parts = core.split('.');
|
||||
final segments = <int>[];
|
||||
for (final part in parts) {
|
||||
final value = int.tryParse(part.trim());
|
||||
if (value == null) return null;
|
||||
segments.add(value);
|
||||
}
|
||||
return segments.isEmpty ? null : segments;
|
||||
}
|
||||
Reference in New Issue
Block a user