126 lines
3.6 KiB
Dart
126 lines
3.6 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:Tripz/constant/colors.dart';
|
|
import 'package:Tripz/controller/functions/encrypt_decrypt.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:Tripz/constant/box_name.dart';
|
|
import 'package:Tripz/constant/links.dart';
|
|
import 'package:Tripz/controller/functions/crud.dart';
|
|
import 'package:Tripz/main.dart';
|
|
import 'package:Tripz/views/widgets/my_textField.dart';
|
|
|
|
import '../../views/widgets/elevated_btn.dart';
|
|
|
|
class ProfileController extends GetxController {
|
|
bool isloading = false;
|
|
Map prfoileData = {};
|
|
TextEditingController txtController = TextEditingController();
|
|
List genders = ['Male', 'Female', 'Other'];
|
|
|
|
String gender = 'Male';
|
|
|
|
void setGender(String value) {
|
|
gender = value;
|
|
update();
|
|
}
|
|
|
|
String? selectedDegree;
|
|
|
|
void setDegree(String? degree) {
|
|
selectedDegree = degree;
|
|
update();
|
|
}
|
|
|
|
String? selectedCountry;
|
|
|
|
void setCountry(String? country) {
|
|
selectedCountry = country;
|
|
// box.write(BoxName.countryCode, country);
|
|
update();
|
|
}
|
|
|
|
updateColumn(Map<String, dynamic> payload) async {
|
|
isloading = true;
|
|
update();
|
|
await CRUD().post(link: AppLink.updateprofile, payload: payload);
|
|
await getProfile();
|
|
isloading = false;
|
|
update();
|
|
}
|
|
|
|
updatField(String columnName, TextInputType type) async {
|
|
Get.dialog(
|
|
CupertinoAlertDialog(
|
|
title: Text('${'Update'.tr} $columnName'),
|
|
content: Column(
|
|
children: [
|
|
const SizedBox(height: 16), // Add spacing between title and input
|
|
CupertinoTextField(
|
|
controller: txtController,
|
|
placeholder: 'type here'.tr,
|
|
keyboardType: type,
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: CupertinoColors.lightBackgroundGray),
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
),
|
|
const SizedBox(height: 20),
|
|
CupertinoButton(
|
|
color: AppColor.blueColor,
|
|
onPressed: () async {
|
|
Get.back();
|
|
await updateColumn({
|
|
'id': box.read(BoxName.passengerID),
|
|
columnName:
|
|
EncryptionHelper.instance.encryptData(txtController.text),
|
|
});
|
|
if (columnName == 'first_name') {
|
|
box.write(
|
|
BoxName.name,
|
|
EncryptionHelper.instance
|
|
.encryptData(txtController.text));
|
|
}
|
|
|
|
txtController.clear();
|
|
},
|
|
child: Text('Update'.tr),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
getProfile() async {
|
|
isloading = true;
|
|
update();
|
|
var res = await CRUD().get(link: AppLink.getprofile, payload: {
|
|
'id': box.read(BoxName.passengerID).toString(),
|
|
});
|
|
|
|
if (res.toString() == 'failure') {
|
|
// Get.snackbar('failure', 'message');
|
|
isloading = false;
|
|
update();
|
|
} else {
|
|
var jsonDecoded = jsonDecode(res);
|
|
prfoileData = jsonDecoded['data'];
|
|
box.write(BoxName.sosPhonePassenger, prfoileData['sosPhone'].toString());
|
|
box.write(BoxName.gender, prfoileData['gender'].toString());
|
|
box.write(BoxName.name,
|
|
'${prfoileData['first_name']} ${prfoileData['last_name']}');
|
|
isloading = false;
|
|
update();
|
|
}
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
getProfile();
|
|
super.onInit();
|
|
}
|
|
}
|