This commit is contained in:
Felipe
2024-03-15 16:55:01 -05:00
parent a3c50cf2c8
commit e5a8221edf
9 changed files with 337 additions and 115 deletions
@@ -39,25 +39,43 @@ class ProfessionalBloc extends Bloc<ProfessionalEvent, ProfessionalState> {
on<SendProfessionalToReviewEvent>((event, emit) async {
final myUser = await _userRepository.lastUser();
if (myUser == null) return;
await _professionalRepository.saveProfessionalInfo(ProfessionalEntity(
id: event.id,
identification: event.identification,
identificationPicture: event.identificationPicture,
address: '',
profession: event.profession,
specializations: event.specializations,
specializationsPictures: event.specializationsPictures,
certificatePicture: event.certificatePicture,
latitude: '',
longitude: '',
rate: '',
location: '',
schedules: Schedules.empty,
paymentMethods: PaymentMethodEntity.empty,
));
try {
final identificationPdfUrl = await _professionalRepository
.uploadPdfCedula(event.identificationPicture, myUser.id);
_userRepository
.updateUserInfo(myUser.copyWith(proState: ProState.pending));
final certificatePdfUrl = await _professionalRepository
.uploadPdfCertificado(event.certificatePicture, myUser.id);
List<String> specializationsPdfUrls = [];
if (event.specializationsPictures.isNotEmpty) {
specializationsPdfUrls =
await _professionalRepository.uploadPdfsEspecializaciones(
event.specializationsPictures, myUser.id);
} else {
specializationsPdfUrls = [];
}
await _professionalRepository.saveProfessionalInfo(ProfessionalEntity(
id: event.id,
identification: event.identification,
identificationPicture: identificationPdfUrl,
address: '',
profession: event.profession,
specializations: event.specializations,
specializationsPictures: specializationsPdfUrls,
certificatePicture: certificatePdfUrl,
latitude: '',
longitude: '',
rate: '',
location: '',
schedules: Schedules.empty,
paymentMethods: PaymentMethodEntity.empty,
));
} catch (e) {
log('error acceso a pro ${e.toString()}');
}
// _userRepository
// .updateUserInfo(myUser.copyWith(proState: ProState.pending));
});
}
}
+1 -5
View File
@@ -7,19 +7,15 @@ part 'profile_state.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
final UserRepository _userRepository;
// final AuthBloc _authBloc; // lo nuevo
ProfileBloc({
required UserRepository userRepository,
// required AuthBloc authBloc
}) : _userRepository = userRepository,
// _authBloc = authBloc,
super(UpdateUserInfoInitial()) {
on<UpdateUserInfo>(_onUpdateUserInfo);
}
void _onUpdateUserInfo(
UpdateUserInfo event, Emitter<ProfileState> emit) async {
void _onUpdateUserInfo(UpdateUserInfo event, Emitter<ProfileState> emit) async {
emit(UpdateUserInfoLoading());
try {
final userImageUrl = event.filePicture != null
+4 -3
View File
@@ -20,15 +20,16 @@ class GeneralDrawerHeader extends StatelessWidget {
CupertinoPageRoute(
builder: (BuildContext context) {
return const ProfileScreen();
// return const CityScreen();
},
),
);
},
title: Text(user.name ?? '',
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontWeight: FontWeight.bold)),
subtitle:
Text(user.drawerLabel, style: const TextStyle(fontSize: 12)),
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),
@@ -29,7 +29,6 @@ class _ProfessionScreenState extends State<ProfessionScreen> {
void _loadProfessions() {
professionRepository.getProfessions().then((Professions element) {
setState(() {
log(element.toString());
_professions = element.professions;
_filteredProfessions = _professions;
_isLoading = false;
@@ -7,7 +7,10 @@ import 'package:image_picker/image_picker.dart';
import 'package:prosappco/blocs/auth_bloc/auth_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/blocs/profile_bloc/profile_bloc.dart';
import 'package:prosappco/screens/profession/profession_screen.dart';
import 'package:user_repository/user_repository.dart';
import 'package:file_picker/file_picker.dart';
class ProfessionalFormScreen extends StatefulWidget {
const ProfessionalFormScreen({super.key});
@@ -19,10 +22,13 @@ class ProfessionalFormScreen extends StatefulWidget {
class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
final TextEditingController _cedulaController = TextEditingController();
final TextEditingController _professionController = TextEditingController();
final TextEditingController _controller = TextEditingController();
final TextEditingController _specialityController = TextEditingController();
final List<String> _items = [];
XFile? _imageFile;
PlatformFile? _cedulaPdfFile;
PlatformFile? _certificadoPdfFile;
List<PlatformFile>? _especializacionesPdfFiles = [];
late final AuthBloc authBloc;
@@ -83,6 +89,19 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
return null;
},
),
const SizedBox(height: 10.0),
ElevatedButton(
onPressed: _pickCedulaPDF,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Cargar pdf de la cedula'),
_cedulaPdfFile != null
? const Icon(Icons.check)
: const Icon(Icons.file_upload_outlined),
],
),
),
const SizedBox(height: 20.0),
TextFormField(
controller: _professionController,
@@ -123,9 +142,22 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
return null;
},
),
const SizedBox(height: 10.0),
ElevatedButton(
onPressed: _pickCertificadoPDF,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Cargar pdf del certificado'),
_certificadoPdfFile != null
? const Icon(Icons.check)
: const Icon(Icons.file_upload_outlined),
],
),
),
const SizedBox(height: 20.0),
TextField(
controller: _controller,
controller: _specialityController,
onSubmitted: (value) {
_addItemToList();
},
@@ -151,24 +183,140 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
),
),
const SizedBox(height: 10.0),
ElevatedButton(
onPressed: _pickEspecializacionesPDF,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Expanded(
child: Text(
'Cargar pdfs de tus especializaciones',
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
),
_especializacionesPdfFiles?.isNotEmpty == true
? const Icon(Icons.check)
: const Icon(Icons.file_upload_outlined),
],
),
),
const SizedBox(height: 10.0),
Wrap(
spacing: 8.0,
runSpacing: 4.0,
children: _items
.map((item) => Chip(
label: Text(item),
backgroundColor: Theme.of(context).primaryColor,
labelStyle:
const TextStyle(color: Colors.white),
deleteIconColor: Colors.white,
backgroundColor:
Theme.of(context).colorScheme.tertiary,
labelStyle: const TextStyle(color: Colors.blue),
deleteIconColor: Colors.blue,
onDeleted: () {
_removeItemFromList(item);
},
shape: RoundedRectangleBorder(
side: const BorderSide(
color: Colors.blue, width: 0.3),
borderRadius: BorderRadius.circular(8),
),
))
.toList(),
),
const SizedBox(height: 60.0),
saveButton(state, context),
const SizedBox(height: 40),
ElevatedButton(
onPressed: () {
final userId =
context.read<MyUserBloc>().state.user!.id;
final String? cedulaPdfPath = _cedulaPdfFile?.path;
final String? certificadoPdfPath =
_certificadoPdfFile?.path;
final List<String> especializacionesPdfPaths =
_especializacionesPdfFiles
?.map((file) => file.path)
.where((file) => file != null)
.map((e) => e!)
.toList() ??
[];
if (_cedulaController.text.isEmpty ||
_professionController.text.isEmpty) {
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Llena los campos de cedula y profesión')));
return;
}
if (cedulaPdfPath == null) {
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Carga el pdf de tu cedula')));
return;
}
if (certificadoPdfPath == null) {
ScaffoldMessenger.of(context).clearSnackBars();
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text(
'Carga el pdf de tu certificado profesional')));
return;
}
context
.read<ProfessionalBloc>()
.add(SendProfessionalToReviewEvent(
id: userId,
identification: _cedulaController.text,
identificationPicture: cedulaPdfPath,
profession: _professionController.text,
certificatePicture: certificadoPdfPath,
specializations: _items,
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: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
shadowColor: Colors.grey,
// elevation: 0,
),
child: Container(
constraints: const BoxConstraints(
maxWidth: 300.0, minHeight: 50.0),
alignment: Alignment.center,
child: const Text(
'Enviar a revisión',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(height: 20),
],
),
),
@@ -181,10 +329,10 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
void _addItemToList() {
setState(() {
String newItem = _controller.text.trim();
String newItem = _specialityController.text.trim();
if (newItem.isNotEmpty) {
_items.add(newItem);
_controller.clear();
_specialityController.clear();
}
});
}
@@ -195,81 +343,44 @@ class _ProfessionalFormScreenState extends State<ProfessionalFormScreen> {
});
}
Widget saveButton(MyUserState state, BuildContext context) {
return ElevatedButton(
onPressed: () {
final userId = context.read<MyUserBloc>().state.user!.id;
context.read<ProfessionalBloc>().add(SendProfessionalToReviewEvent(
id: userId,
identification: _cedulaController.text,
identificationPicture: _cedulaController.text,
profession: _professionController.text,
certificatePicture: _professionController.text,
specializations: _items,
specializationsPictures: _items,
));
// if (isLoading) {
// return;
// }
// if (_nameController.text.isEmpty) {
// ScaffoldMessenger.of(context).clearSnackBars();
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(content: Text('Por favor, ingrese su nombre')));
// return;
// }
// if (_cityController.text.isEmpty) {
// ScaffoldMessenger.of(context).clearSnackBars();
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(content: Text('Por favor, ingrese su ciudad')));
// }
// final myUser = state.user!.copyWith(
// name: _nameController.text,
// city: _cityController.text,
// nickname: _nameController.text.trim().toLowerCase(),
// email: _emailController.text,
// phone: _phoneController.text,
// 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...')),
);
Navigator.pop(context);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
padding: const EdgeInsets.symmetric(vertical: 5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
shadowColor: Colors.grey,
// elevation: 0,
),
child: Container(
constraints: const BoxConstraints(maxWidth: 300.0, minHeight: 50.0),
alignment: Alignment.center,
child: const Text(
'Actualizar',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
Future<void> _pickCedulaPDF() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['pdf'],
);
if (result != null) {
setState(() {
_cedulaPdfFile = result.files.first;
});
}
}
Future<void> _pickCertificadoPDF() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['pdf'],
);
if (result != null) {
setState(() {
_certificadoPdfFile = result.files.first;
});
}
}
Future<void> _pickEspecializacionesPDF() async {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['pdf'],
allowMultiple: true,
);
if (result != null) {
setState(() {
_especializacionesPdfFiles = result.files;
});
}
}
Widget pictureWidget(MyUserState state, BuildContext context) {