From 381cedf3ace0f6628b25b29f623697dff65a6697 Mon Sep 17 00:00:00 2001 From: Felipe Date: Mon, 31 Jul 2023 18:16:05 -0500 Subject: [PATCH] cedula y certificado --- lib/src/components/drawer_professional.dart | 9 +-- lib/src/screens/professional_profile.dart | 76 +++++++++------------ 2 files changed, 34 insertions(+), 51 deletions(-) diff --git a/lib/src/components/drawer_professional.dart b/lib/src/components/drawer_professional.dart index bb1054b..09700b5 100644 --- a/lib/src/components/drawer_professional.dart +++ b/lib/src/components/drawer_professional.dart @@ -132,7 +132,7 @@ class _DrawerProfessionalState extends State { Navigator.of(context).push( CupertinoPageRoute( builder: (BuildContext context) { - return MyServicesProScreen(); + return const MyServicesProScreen(); }, ), ); @@ -226,7 +226,7 @@ class _DrawerProfessionalState extends State { Navigator.of(context).push( CupertinoPageRoute( builder: (BuildContext context) { - return MessagesScreen(); + return const MessagesScreen(); }, ), ); @@ -304,14 +304,11 @@ class _DrawerProfessionalState extends State { color: Colors.white, child: ListTile( onTap: () async { - var professional = - await Professional.getProfessional(uid!); - Navigator.push( context, CupertinoPageRoute( builder: (BuildContext context) { - return ReputationProScreen(); + return const ReputationProScreen(); }, ), ); diff --git a/lib/src/screens/professional_profile.dart b/lib/src/screens/professional_profile.dart index c662639..145477c 100644 --- a/lib/src/screens/professional_profile.dart +++ b/lib/src/screens/professional_profile.dart @@ -1,16 +1,16 @@ import 'dart:io'; - import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:firebase_storage/firebase_storage.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:intl/intl.dart'; import 'package:prosappco/src/authentication/authentication_repository.dart'; import 'package:prosappco/src/components/photo_view.dart'; import 'package:prosappco/src/components/pop_appbar.dart'; import 'package:prosappco/src/controllers/info_%20professional.dart'; import 'package:prosappco/src/services/select_image_profile.dart'; +import 'package:file_picker/file_picker.dart'; class ProfessionalProfileScreen extends StatefulWidget { const ProfessionalProfileScreen({super.key}); @@ -62,6 +62,20 @@ class ProfessionalProfileScreenState extends State { } } + Future getPdf() async { + FilePickerResult? result = await FilePicker.platform.pickFiles( + type: FileType.custom, + allowedExtensions: ['pdf'], + ); + + if (result != null) { + File file = File(result.files.single.path!); + return file; + } else { + return null; + } + } + Future _showChoiceDialog(BuildContext context) async { return showDialog( context: context, @@ -115,21 +129,6 @@ class ProfessionalProfileScreenState extends State { content: SingleChildScrollView( child: ListBody( children: [ - GestureDetector( - child: const Text( - textAlign: TextAlign.center, - "Tomar foto", - style: TextStyle(color: Color(0xFF2BA4EC)), - ), - onTap: () async { - final imagen = await getImage(1); - setState(() { - image_cedula = File(imagen[0]!.path); - }); - Navigator.of(context).pop(); - }, - ), - const Divider(color: Colors.black54), GestureDetector( child: const Text( textAlign: TextAlign.center, @@ -137,9 +136,9 @@ class ProfessionalProfileScreenState extends State { style: TextStyle(color: Color(0xFF2BA4EC)), ), onTap: () async { - final imagen = await getImage(2); + final imagen = await getPdf(); setState(() { - image_cedula = File(imagen[0]!.path); + image_cedula = File(imagen!.path); }); Navigator.of(context).pop(); }, @@ -160,21 +159,6 @@ class ProfessionalProfileScreenState extends State { content: SingleChildScrollView( child: ListBody( children: [ - GestureDetector( - child: const Text( - textAlign: TextAlign.center, - "Tomar foto", - style: TextStyle(color: Color(0xFF2BA4EC)), - ), - onTap: () async { - final imagen = await getImage(1); - setState(() { - image_certificado = File(imagen[0]!.path); - }); - Navigator.of(context).pop(); - }, - ), - const Divider(color: Colors.black54), GestureDetector( child: const Text( textAlign: TextAlign.center, @@ -182,9 +166,9 @@ class ProfessionalProfileScreenState extends State { style: TextStyle(color: Color(0xFF2BA4EC)), ), onTap: () async { - final imagen = await getImage(2); + final imagen = await getPdf(); setState(() { - image_certificado = File(imagen[0]!.path); + image_certificado = File(imagen!.path); }); Navigator.of(context).pop(); }, @@ -198,14 +182,13 @@ class ProfessionalProfileScreenState extends State { } Future uploadCedula(File image) async { - final String namefile = image.path.split('/').last; + final now = DateTime.now(); + final formattedDate = DateFormat('HHmmssddMMyyyy').format(now); + final milliseconds = (now.microsecondsSinceEpoch / 1000).round(); + final random = 'c$formattedDate$milliseconds'; - Reference ref = storage - .ref() - .child('users') - .child(uid!) - .child('cedula') - .child(namefile); + Reference ref = + storage.ref().child('users').child(uid!).child('cedula').child(random); final UploadTask uploadTask = ref.putFile(image); @@ -240,14 +223,17 @@ class ProfessionalProfileScreenState extends State { } Future uploadCertificado(File image) async { - final String namefile = image.path.split('/').last; + final now = DateTime.now(); + final formattedDate = DateFormat('HHmmssddMMyyyy').format(now); + final milliseconds = (now.microsecondsSinceEpoch / 1000).round(); + final random = 'f$formattedDate$milliseconds'; Reference ref = storage .ref() .child('users') .child(uid!) .child('certificado_profesional') - .child(namefile); + .child(random); final UploadTask uploadTask = ref.putFile(image);