tarifa
This commit is contained in:
@@ -201,6 +201,19 @@ class AuthenticationRepository extends GetxController {
|
||||
return opcional_location;
|
||||
}
|
||||
|
||||
Future<int> getTarifa(String uid) async {
|
||||
int tarifa = 0;
|
||||
try {
|
||||
final snapshot =
|
||||
await FirebaseFirestore.instance.collection('users').doc(uid).get();
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
tarifa = data?['tarifa'] ?? 0;
|
||||
} catch (e) {
|
||||
print('Error getting tarifa: $e');
|
||||
}
|
||||
return tarifa;
|
||||
}
|
||||
|
||||
Future<String> getPhoto(String uid) async {
|
||||
String photo = '';
|
||||
try {
|
||||
|
||||
@@ -2,32 +2,33 @@ import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class SettingModel {
|
||||
final bool domicilios;
|
||||
final bool tarifas;
|
||||
|
||||
SettingModel(this.domicilios);
|
||||
SettingModel(this.domicilios, this.tarifas);
|
||||
|
||||
static Future<SettingModel> fromJson(Map<String, dynamic> json) async {
|
||||
try {
|
||||
if (json == null) return SettingModel(false);
|
||||
if (json == null) return SettingModel(false, false);
|
||||
|
||||
return SettingModel(json['habilitado']);
|
||||
return SettingModel(json['domicilio'], json['tarifa']);
|
||||
} catch (e) {
|
||||
print('Error settings: $e');
|
||||
return SettingModel(false);
|
||||
return SettingModel(false, false);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<SettingModel> getDomiciliosSettings() async {
|
||||
static Future<SettingModel> getSettings() async {
|
||||
try {
|
||||
final DocumentSnapshot<Map<String, dynamic>> snapshot =
|
||||
await FirebaseFirestore.instance
|
||||
.collection('settings')
|
||||
.doc('domicilios')
|
||||
.doc('global')
|
||||
.get();
|
||||
final Map<String, dynamic>? data = snapshot.data();
|
||||
return fromJson(data!);
|
||||
} catch (e) {
|
||||
print('Error getting settings: $e');
|
||||
return SettingModel(false);
|
||||
return SettingModel(false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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';
|
||||
@@ -28,11 +29,13 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
final uid = AuthenticationRepository.instance.getCurrentUserUid();
|
||||
final TextEditingController _opcionalAddressController =
|
||||
TextEditingController();
|
||||
TextEditingController _tarifaController = TextEditingController();
|
||||
|
||||
File? image_portada;
|
||||
File? imagen_to_upload;
|
||||
|
||||
bool domicilioValue = false;
|
||||
bool tarifaValue = false;
|
||||
bool sitioValue = false;
|
||||
var photoTemp = '';
|
||||
|
||||
@@ -40,16 +43,17 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
var _direccion = '...';
|
||||
var _ubicacion = '...';
|
||||
var _opcionalAddress = '...';
|
||||
SettingModel? setting_domicilio;
|
||||
int _tarifa = 0;
|
||||
SettingModel? settings;
|
||||
|
||||
Map<String, Schedule>? _horarios;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (setting_domicilio == null) {
|
||||
SettingModel.getDomiciliosSettings().then(
|
||||
(SettingModel value) => setState(() => setting_domicilio = value),
|
||||
if (settings == null) {
|
||||
SettingModel.getSettings().then(
|
||||
(SettingModel value) => setState(() => settings = value),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -112,6 +116,20 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
),
|
||||
);
|
||||
}
|
||||
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 {
|
||||
@@ -121,6 +139,17 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
.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
|
||||
@@ -288,12 +317,47 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (setting_domicilio?.domicilios == true)
|
||||
if (settings?.tarifas == true)
|
||||
const Divider(
|
||||
color: Colors.white,
|
||||
height: 12,
|
||||
),
|
||||
if (setting_domicilio?.domicilios == true)
|
||||
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,
|
||||
@@ -316,7 +380,6 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
// controller: _emailController,
|
||||
readOnly: true,
|
||||
onTap: () async {
|
||||
final String? direccion = await Navigator.push(
|
||||
@@ -334,7 +397,6 @@ class _ProfileProState extends State<ProfilePro> {
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
decoration: InputDecoration(
|
||||
prefixIcon: const Icon(Icons.near_me),
|
||||
hintStyle: address == ''
|
||||
|
||||
Reference in New Issue
Block a user