foto portada
This commit is contained in:
@@ -1,14 +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/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:prosappco/src/authentication/authentication_repository.dart';
|
||||
import 'package:prosappco/src/components/banner_photo.dart';
|
||||
import 'package:prosappco/src/components/column_padding.dart';
|
||||
import 'package:prosappco/src/components/drawer_professional.dart';
|
||||
import 'package:prosappco/src/components/primary_btn.dart';
|
||||
import 'package:prosappco/src/components/schedule_picker.dart';
|
||||
import 'package:prosappco/src/screens/horario.dart';
|
||||
import 'package:prosappco/src/screens/professional.dart';
|
||||
import 'package:prosappco/src/services/select_image_profile.dart';
|
||||
@@ -21,31 +23,191 @@ class ProfilePro extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ProfileProState extends State<ProfilePro> {
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
|
||||
File? image_portada;
|
||||
File? imagen_to_upload;
|
||||
|
||||
bool domicilioValue = false;
|
||||
bool sitioValue = false;
|
||||
var photoTemp = '';
|
||||
|
||||
var _photo = '...';
|
||||
Map<String, Schedule>? _horarios;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
late final FirebaseAuth _auth;
|
||||
_auth = FirebaseAuth.instance;
|
||||
|
||||
if (_photo == '...') {
|
||||
AuthenticationRepository.instance.getPhoto(uid.toString()).then(
|
||||
AuthenticationRepository.instance.getBanner(uid.toString()).then(
|
||||
(String s) => setState(
|
||||
() {
|
||||
_photo = s;
|
||||
print('HOLA $s');
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (_horarios == null) {
|
||||
Schedule.getHorarios(uid.toString()).then(
|
||||
(Map<String, Schedule> s) => setState(
|
||||
() {
|
||||
_horarios = s;
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateInfo() async {
|
||||
try {
|
||||
if (imagen_to_upload == null) {
|
||||
return;
|
||||
} else {
|
||||
final uploaded = await uploadImage(imagen_to_upload!);
|
||||
updateImage(photoTemp);
|
||||
//image
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error al actualizar la imagen de perfil $e');
|
||||
}
|
||||
}
|
||||
|
||||
// Future<Widget> downloadImage(Reference ref) async {
|
||||
// try {
|
||||
// if (_photo == '...' || _photo.isEmpty) {
|
||||
// return GestureDetector(
|
||||
// onTap: () {
|
||||
// _showChoiceDialog(context);
|
||||
// },
|
||||
// child: Container(
|
||||
// margin: EdgeInsets.symmetric(vertical: 50),
|
||||
// width: 100,
|
||||
// height: 100,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Color(0xFF2BA4EC),
|
||||
// borderRadius: BorderRadius.circular(50),
|
||||
// ),
|
||||
// child: Icon(
|
||||
// Icons.person,
|
||||
// color: Colors.white,
|
||||
// size: 90,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// } else {
|
||||
// final imageData = await ref.getData();
|
||||
// if (imageData != null) {
|
||||
// final widgetImage = GestureDetector(
|
||||
// onTap: () {
|
||||
// _showChoiceDialog(context);
|
||||
// },
|
||||
// child: Container(
|
||||
// margin: const EdgeInsets.symmetric(vertical: 50),
|
||||
// child: ClipOval(
|
||||
// child: Image.memory(
|
||||
// imageData,
|
||||
// width: 60,
|
||||
// height: 60,
|
||||
// fit: BoxFit.cover,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// return widgetImage;
|
||||
// } else {
|
||||
// return GestureDetector(
|
||||
// onTap: () {
|
||||
// _showChoiceDialog(context);
|
||||
// },
|
||||
// child: Container(
|
||||
// margin: const EdgeInsets.symmetric(vertical: 50),
|
||||
// width: 100,
|
||||
// height: 100,
|
||||
// decoration: BoxDecoration(
|
||||
// color: const Color(0xFF2BA4EC),
|
||||
// borderRadius: BorderRadius.circular(50),
|
||||
// ),
|
||||
// child: const Icon(
|
||||
// Icons.person,
|
||||
// color: Colors.white,
|
||||
// size: 90,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print('XD $e');
|
||||
// return GestureDetector(
|
||||
// onTap: () {
|
||||
// _showChoiceDialog(context);
|
||||
// },
|
||||
// child: Container(
|
||||
// margin: const EdgeInsets.symmetric(vertical: 50),
|
||||
// width: 100,
|
||||
// height: 100,
|
||||
// decoration: BoxDecoration(
|
||||
// color: const Color(0xFF2BA4EC),
|
||||
// borderRadius: BorderRadius.circular(50),
|
||||
// ),
|
||||
// child: const Icon(
|
||||
// Icons.person,
|
||||
// color: Colors.white,
|
||||
// size: 90,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> updateImage(image) async {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'banner': image});
|
||||
|
||||
print('imagen actualizada correctamente');
|
||||
} catch (e) {
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.set({'banner': image});
|
||||
} catch (e) {
|
||||
print('Error al agregar la imagen de perfil: $e');
|
||||
}
|
||||
|
||||
print('Error al actualizar la imagen de perfil: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> uploadImage(File image) async {
|
||||
final String namefile = image.path.split('/').last;
|
||||
|
||||
Reference ref = storage
|
||||
.ref()
|
||||
.child('users')
|
||||
.child(uid!)
|
||||
.child('profile')
|
||||
.child(namefile);
|
||||
|
||||
final UploadTask uploadTask = ref.putFile(image);
|
||||
|
||||
final TaskSnapshot snapshot = await uploadTask.whenComplete(() => true);
|
||||
|
||||
photoTemp = ref.fullPath;
|
||||
|
||||
if (snapshot.state == TaskState.success) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _showChoiceDialog(BuildContext context) async {
|
||||
@@ -124,7 +286,7 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
file: imagen_to_upload!,
|
||||
)
|
||||
: ReferenceBannerPhoto(
|
||||
ref: storage.ref().child('_photo'),
|
||||
ref: storage.ref().child(_photo),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -191,7 +353,9 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return const HorarioScreen();
|
||||
return HorarioScreen(
|
||||
horarios: _horarios!,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -223,7 +387,7 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: 35),
|
||||
padding: EdgeInsets.only(right: 45),
|
||||
child: Icon(Icons.edit_outlined),
|
||||
),
|
||||
],
|
||||
@@ -251,17 +415,18 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 35),
|
||||
padding: const EdgeInsets.only(left: 25),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Text('N/A'),
|
||||
Text('N/A'),
|
||||
Text('N/A'),
|
||||
Text('N/A'),
|
||||
Text('N/A'),
|
||||
Text('N/A'),
|
||||
Text('N/A'),
|
||||
children: [
|
||||
Text(timeList(_horarios?['Lunes'], context)),
|
||||
Text(timeList(_horarios?['Martes'], context)),
|
||||
Text(
|
||||
timeList(_horarios?['Miercoles'], context)),
|
||||
Text(timeList(_horarios?['Jueves'], context)),
|
||||
Text(timeList(_horarios?['Viernes'], context)),
|
||||
Text(timeList(_horarios?['Sabado'], context)),
|
||||
Text(timeList(_horarios?['Domingo'], context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -271,7 +436,11 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
],
|
||||
),
|
||||
),
|
||||
PrimaryButtom(onPressed: () {}, label: 'Guardar'),
|
||||
PrimaryButtom(
|
||||
onPressed: () {
|
||||
updateInfo();
|
||||
},
|
||||
label: 'Guardar'),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
)
|
||||
@@ -313,4 +482,19 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String timeList(Schedule? schedule, BuildContext context) {
|
||||
if (schedule == null) {
|
||||
return 'N/A';
|
||||
}
|
||||
|
||||
if (!schedule.habilitado) {
|
||||
return 'N/A';
|
||||
}
|
||||
if (schedule.jornadaContinua) {
|
||||
return '${schedule.range1Hour1?.format(context).toString()} - ${schedule.range1Hour2?.format(context).toString()}';
|
||||
} else {
|
||||
return '${schedule.range1Hour1?.format(context).toString()} - ${schedule.range1Hour2?.format(context).toString()}; ${schedule.range2Hour1?.format(context).toString()} - ${schedule.range2Hour2?.format(context).toString()}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user