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