auto complete

This commit is contained in:
Juan Felipe Duarte
2023-06-20 15:56:21 -05:00
parent 8dffecf6a4
commit 72ee055561
6 changed files with 735 additions and 91 deletions
+1 -4
View File
@@ -38,12 +38,9 @@ void main() async {
DeviceOrientation.portraitDown,
]);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@@ -67,7 +64,7 @@ class MyApp extends StatelessWidget {
'/solicitudEnviada': (context) => const RequestSentScreen(),
'/nuevaPassword': (context) => NewPasswordScreen(),
'/servicio': (context) => const ServiceScreen(),
'/profilePro': (context) => const ProfilePro(),
'/profilePro': (context) => const ProfileProScreen(),
'/calendar': (context) => const CalendarScreen(),
'/solicitud': (context) => SolicitudScreen(),
'/misserviciospro': (context) => const MyServicesProScreen(),
+7 -1
View File
@@ -1,5 +1,6 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
@@ -11,6 +12,7 @@ import 'package:prosappco/src/screens/my_services_pro.dart';
import 'package:prosappco/src/screens/professional.dart';
import 'package:prosappco/src/screens/profile.dart';
import 'package:prosappco/src/screens/profile_pro.dart';
import 'package:prosappco/src/screens/profile_pro_web.dart';
import 'package:prosappco/src/screens/reputacion_pro.dart';
import '../models/scores_model.dart';
import '../screens/configuracion.dart';
@@ -139,7 +141,11 @@ class _DrawerProfessionalState extends State<DrawerProfessional> {
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return const ProfilePro();
if (kIsWeb) {
return const ProfileProWebScreen();
} else {
return const ProfileProScreen();
}
},
),
);
+2 -1
View File
@@ -195,7 +195,8 @@ class Schedule {
final snapshot =
await FirebaseFirestore.instance.collection('users').doc(uid).get();
final Map<String, dynamic>? data = snapshot.data();
return fromJson(data);
final Map<String, dynamic>? horarioData = data?['horario'];
return fromJson(horarioData);
} catch (e) {
print('Error getting user: $e');
return {
+5 -11
View File
@@ -3,8 +3,6 @@ import 'package:flutter/material.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/components/primary_btn.dart';
import 'package:prosappco/src/screens/profile_pro.dart';
import '../components/schedule_picker.dart';
class HorarioScreen extends StatefulWidget {
@@ -21,6 +19,8 @@ class _HorarioScreenState extends State<HorarioScreen> {
@override
void initState() {
super.initState();
print('horario a ${widget.horarios}');
}
bool lunesValue = false;
@@ -95,10 +95,7 @@ class _HorarioScreenState extends State<HorarioScreen> {
child: Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const ProfilePro()),
);
Navigator.pop(context);
},
label: 'Horario'),
body: SingleChildScrollView(
@@ -121,11 +118,8 @@ class _HorarioScreenState extends State<HorarioScreen> {
padding: const EdgeInsets.only(top: 30, bottom: 30),
child: PrimaryButtom(
onPressed: () async {
updateHorario().then((value) => Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => const ProfilePro()),
));
await updateHorario();
Navigator.pop(context);
},
label: 'Guardar',
),
+141 -74
View File
@@ -1,8 +1,8 @@
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_animate/flutter_animate.dart';
@@ -16,20 +16,21 @@ import 'package:prosappco/src/models/setting_model.dart';
import 'package:prosappco/src/screens/horario.dart';
import 'package:prosappco/src/screens/professional.dart';
import 'package:prosappco/src/screens/professional_direccion.dart';
import 'package:prosappco/src/screens/ubicacion.dart';
import 'package:prosappco/src/services/select_image_profile.dart';
class ProfilePro extends StatefulWidget {
const ProfilePro({super.key});
class ProfileProScreen extends StatefulWidget {
const ProfileProScreen({super.key});
@override
State<ProfilePro> createState() => _ProfileProState();
State<ProfileProScreen> createState() => _ProfileProScreenState();
}
class _ProfileProState extends State<ProfilePro> {
class _ProfileProScreenState extends State<ProfileProScreen> {
final uid = AuthenticationRepository.instance.getCurrentUserUid();
final TextEditingController _opcionalAddressController =
TextEditingController();
TextEditingController _tarifaController = TextEditingController();
final TextEditingController _tarifaController = TextEditingController();
File? image_portada;
File? imagen_to_upload;
@@ -71,11 +72,11 @@ class _ProfileProState extends State<ProfilePro> {
if (_horarios == null) {
Schedule.getHorarios(uid.toString()).then(
(Map<String, Schedule> s) => setState(
() {
_horarios = s;
},
),
(Map<String, Schedule> data) {
setState(() {
_horarios = data;
});
},
);
}
@@ -183,7 +184,6 @@ class _ProfileProState extends State<ProfilePro> {
try {
if (imagen_to_upload == null) {
} else {
final uploaded = await uploadImage(imagen_to_upload!);
updateImage(photoTemp);
//image
}
@@ -196,9 +196,24 @@ class _ProfileProState extends State<ProfilePro> {
'Su información a sido actualizada con exito.',
snackPosition: SnackPosition.TOP,
);
Navigator.pop(context);
return;
}
void name() {
_horarios!.forEach((dia, horario) {
print('Día: $dia');
print('Habilitado: ${horario.habilitado}');
print('Jornada Continua: ${horario.jornadaContinua}');
print('Rango 1 Hora 1: ${horario.range1Hour1}');
print('Rango 1 Hora 2: ${horario.range1Hour2}');
print('Rango 2 Hora 1: ${horario.range2Hour1}');
print('Rango 2 Hora 2: ${horario.range2Hour2}');
print('-----------------------------------');
});
}
Future<void> updateImage(image) async {
try {
await FirebaseFirestore.instance
@@ -432,7 +447,7 @@ class _ProfileProState extends State<ProfilePro> {
),
GestureDetector(
onTap: () {
Navigator.push(
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
@@ -443,84 +458,137 @@ class _ProfileProState extends State<ProfilePro> {
),
);
},
child: Column(
children: [
const Padding(
padding: EdgeInsets.symmetric(vertical: 10),
child: Row(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
children: [
TableRow(
children: [
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 30),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text('Lunes'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text(timeList(_horarios?['Lunes'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Martes'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Martes'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Miercoles'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text(
'Dia',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500),
),
timeList(_horarios?['Miercoles'], context)),
),
),
Padding(
padding: EdgeInsets.only(right: 170),
child: Text(
'Hora',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w500),
),
),
Padding(
padding: EdgeInsets.only(right: 45),
child: Icon(Icons.edit_outlined),
),
],
),
),
Padding(
padding: sitioValue
? const EdgeInsets.only(bottom: 30)
: const EdgeInsets.only(bottom: 70),
child: Row(
TableRow(
children: [
const Padding(
padding: EdgeInsets.only(left: 30),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Lunes'),
Text('Martes'),
Text('Miércoles'),
Text('Jueves'),
Text('Viernes'),
Text('Sábado'),
Text('Domingo'),
],
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Jueves'),
),
),
Padding(
padding: const EdgeInsets.only(left: 25),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
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)),
],
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Jueves'], context)),
),
),
],
),
),
],
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Viernes'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Viernes'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Sabado'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Sabado'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Domingo'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Domingo'], context)),
),
),
],
),
],
),
),
),
PrimaryButtom(
onPressed: () {
updateInfo();
// name();
},
label: 'Guardar'),
const SizedBox(
@@ -568,7 +636,6 @@ class _ProfileProState extends State<ProfilePro> {
if (schedule == null) {
return 'N/A';
}
if (!schedule.habilitado) {
return 'N/A';
}
+579
View File
@@ -0,0 +1,579 @@
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:get/get.dart';
import 'package:prosappco/src/authentication/authentication_repository.dart';
import 'package:prosappco/src/components/banner_photo.dart';
import 'package:prosappco/src/components/pop_appbar.dart';
import 'package:prosappco/src/components/primary_btn.dart';
import 'package:prosappco/src/components/schedule_picker.dart';
import 'package:prosappco/src/models/setting_model.dart';
import 'package:prosappco/src/screens/horario.dart';
import 'package:prosappco/src/screens/professional.dart';
import 'package:prosappco/src/screens/ubicacion.dart';
import 'package:prosappco/src/services/select_image_profile.dart';
class ProfileProWebScreen extends StatefulWidget {
const ProfileProWebScreen({super.key});
@override
State<ProfileProWebScreen> createState() => _ProfileProWebScreenState();
}
class _ProfileProWebScreenState extends State<ProfileProWebScreen> {
final uid = AuthenticationRepository.instance.getCurrentUserUid();
final TextEditingController _opcionalAddressController =
TextEditingController();
final TextEditingController _tarifaController = TextEditingController();
final TextEditingController _ubicationController = TextEditingController();
double latUser = 0.0;
double lngUser = 0.0;
bool domicilioValue = false;
bool tarifaValue = false;
bool sitioValue = false;
var photoTemp = '';
var _direccion = '...';
var _ubicacion = '...';
var _opcionalAddress = '...';
int _tarifa = 0;
SettingModel? settings;
Map<String, Schedule>? _horarios;
@override
void initState() {
super.initState();
if (settings == null) {
SettingModel.getSettings().then(
(SettingModel value) => setState(() => settings = value),
);
}
final uid = AuthenticationRepository.instance.getCurrentUserUid();
if (_horarios == null) {
Schedule.getHorarios(uid.toString()).then(
(Map<String, Schedule> data) {
setState(() {
_horarios = data;
});
},
);
}
if (_direccion == '...') {
AuthenticationRepository.instance
.getAddress(uid.toString())
.then((String s) => setState(() {
_direccion = s;
_ubicationController.text = _direccion;
}));
}
if (_ubicacion == '...') {
AuthenticationRepository.instance.getUbicacion(uid.toString()).then(
(String s) => setState(
() {
_ubicacion = s;
if (_ubicacion == 'ambos') {
sitioValue = true;
domicilioValue = true;
} else if (_ubicacion == 'sitio') {
sitioValue = true;
} else if (_ubicacion == 'domicilio') {
domicilioValue = true;
}
},
),
);
}
if (_opcionalAddress == '...') {
AuthenticationRepository.instance.getOpcionalAddress(uid.toString()).then(
(String s) => setState(
() {
_opcionalAddress = s;
if (_opcionalAddress != '...') {
_opcionalAddressController.text = _opcionalAddress;
}
},
),
);
}
if (_tarifa == 0) {
AuthenticationRepository.instance.getTarifa(uid.toString()).then(
(s) => setState(
() {
_tarifa = s;
if (_tarifa != 0) {
tarifaValue = true;
_tarifaController.text = _tarifa.toString();
}
},
),
);
}
}
Future<void> updateInfo() async {
if (_ubicationController.text.isNotEmpty) {
FirebaseFirestore.instance.collection('users').doc(uid).update({
'address': _ubicationController.text,
if (latUser != 0.0) 'latitude': latUser,
if (latUser != 0.0) 'longitude': lngUser,
});
}
if (_opcionalAddressController.text.isNotEmpty) {
FirebaseFirestore.instance
.collection('users')
.doc(uid)
.update({'opcional_address': _opcionalAddressController.text});
}
if (tarifaValue && _tarifaController.text.isNotEmpty) {
FirebaseFirestore.instance
.collection('users')
.doc(uid)
.update({'tarifa': int.parse(_tarifaController.text)});
} else {
FirebaseFirestore.instance
.collection('users')
.doc(uid)
.update({'tarifa': 0});
}
if (domicilioValue && sitioValue) {
FirebaseFirestore.instance
.collection('users')
.doc(uid)
.update({'ubicacion': 'ambos'});
} else if (domicilioValue) {
FirebaseFirestore.instance
.collection('users')
.doc(uid)
.update({'ubicacion': 'domicilio'});
} else if (sitioValue) {
FirebaseFirestore.instance
.collection('users')
.doc(uid)
.update({'ubicacion': 'sitio'});
} else {
Get.snackbar(
'Elige como vas a dar tu servicio',
'Selecciona si tu servicio es a domicilio o en tu consultorio.',
snackPosition: SnackPosition.TOP,
backgroundColor: Colors.black.withOpacity(0.2),
messageText: const Text(
'Selecciona si tu servicio es a domicilio o en tu consultorio.',
style: TextStyle(color: Colors.white),
),
);
return;
}
Get.snackbar(
'Información actualizada',
'Su información a sido actualizada con exito.',
snackPosition: SnackPosition.TOP,
);
Navigator.pop(context);
return;
}
void name() {
_horarios!.forEach((dia, horario) {
print('Día: $dia');
print('Habilitado: ${horario.habilitado}');
print('Jornada Continua: ${horario.jornadaContinua}');
print('Rango 1 Hora 1: ${horario.range1Hour1}');
print('Rango 1 Hora 2: ${horario.range1Hour2}');
print('Rango 2 Hora 1: ${horario.range2Hour1}');
print('Rango 2 Hora 2: ${horario.range2Hour2}');
print('-----------------------------------');
});
}
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;
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: PopAppbar(
onPressed: () {
Navigator.pop(context);
},
label: 'Perfil profesional'),
body: SingleChildScrollView(
reverse: true,
child: Column(
children: [
if (settings?.tarifas == true)
const Divider(
color: Colors.white,
height: 12,
),
if (settings?.tarifas == true)
customSwitch(
'Tarifa',
tarifaValue,
(value) {
tarifaValue = value;
},
),
tarifaValue
? Padding(
padding:
const EdgeInsets.only(left: 40, right: 40, bottom: 15),
child: Column(
children: [
TextFormField(
controller: _tarifaController,
keyboardType: TextInputType.number,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.attach_money),
hintText: 'COP'),
inputFormatters: [
FilteringTextInputFormatter.digitsOnly,
],
),
],
)
.animate()
.moveY(duration: const Duration(milliseconds: 100)),
)
: const SizedBox(),
if (settings?.domicilios == true)
const Divider(
color: Colors.white,
height: 12,
),
if (settings?.domicilios == true)
customSwitch(
'Servicio a domicilio',
domicilioValue,
(value) {
domicilioValue = value;
},
),
const Divider(),
customSwitch(
'Servicio en sitio',
sitioValue,
(value) {
sitioValue = value;
},
),
sitioValue
? Padding(
padding:
const EdgeInsets.only(left: 40, right: 40, bottom: 15),
child: Column(
children: [
TextFormField(
controller: _ubicationController,
readOnly: true,
onTap: () async {
final List<dynamic> datos = await Navigator.push(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return const UbicacionScreen();
},
),
);
if (datos.length == 3) {
final formattedAddress = datos[0];
final lat = datos[1];
final lng = datos[2];
setState(() {
_ubicationController.text = formattedAddress;
latUser = lat;
lngUser = lng;
});
}
},
decoration: const InputDecoration(
hintText: 'Escribe tu ubicación',
prefixIcon: Icon(Icons.near_me),
),
),
const SizedBox(height: 10),
TextFormField(
controller: _opcionalAddressController,
decoration: const InputDecoration(
hintText: 'Oficina / Piso / Conjunto'),
),
],
)
.animate()
.moveY(duration: const Duration(milliseconds: 100)),
)
: const SizedBox(),
const Divider(),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: SizedBox(
width: double.infinity,
child: Text(
'Horario estandar',
style: TextStyle(
color: Colors.black,
fontSize: 15,
),
),
),
),
GestureDetector(
onTap: () {
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (BuildContext context) {
return HorarioScreen(
horarios: _horarios!,
);
},
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
children: [
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text('Lunes'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text(timeList(_horarios?['Lunes'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Martes'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Martes'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Miercoles'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: Text(
timeList(_horarios?['Miercoles'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Jueves'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Jueves'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Viernes'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Viernes'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Sabado'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Sabado'], context)),
),
),
],
),
TableRow(
children: [
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child: const Text('Domingo'),
),
),
TableCell(
child: Container(
padding: const EdgeInsets.all(8.0),
child:
Text(timeList(_horarios?['Domingo'], context)),
),
),
],
),
],
),
),
),
PrimaryButtom(
onPressed: () {
updateInfo();
// name();
},
label: 'Guardar'),
const SizedBox(
height: 20,
)
],
),
),
);
}
customSwitch(String text, bool switchValue, ValueChanged<bool> onChanged) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 30),
child: SizedBox(
height: 40,
child: Row(
children: [
Expanded(
child: Text(
text,
style: const TextStyle(
fontSize: 15,
color: Colors.black,
),
)),
Transform.scale(
scale: 1.2,
child: Switch(
value: switchValue,
onChanged: (bool newValue) {
setState(() {
onChanged(newValue);
});
},
),
),
],
),
),
);
}
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.range2Hour2?.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()}';
}
}
}