move update user api call to user services
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
import 'package:flutter_speed_dial/flutter_speed_dial.dart';
|
||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_floating_menu.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_floating_menu.dart';
|
||||||
@@ -22,7 +20,6 @@ import 'package:mzansi_innovation_hub/mih_config/mih_env.dart';
|
|||||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:supertokens_flutter/http.dart' as http;
|
|
||||||
|
|
||||||
class MihPersonalProfile extends StatefulWidget {
|
class MihPersonalProfile extends StatefulWidget {
|
||||||
final AppProfileUpdateArguments arguments;
|
final AppProfileUpdateArguments arguments;
|
||||||
@@ -115,35 +112,16 @@ class _MihPersonalProfileState extends State<MihPersonalProfile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateUserApiCall() async {
|
Future<void> updateUserApiCall() async {
|
||||||
var fname = proPicController.text.replaceAll(RegExp(r' '), '-');
|
int responseCode = await MihUserApis().updateUser(
|
||||||
var filePath =
|
widget.arguments.signedInUser,
|
||||||
"${widget.arguments.signedInUser.app_id}/profile_files/$fname";
|
fnameController.text,
|
||||||
var profileType;
|
lnameController.text,
|
||||||
if (businessUser) {
|
usernameController.text,
|
||||||
profileType = "business";
|
proPicController.text,
|
||||||
} else {
|
businessUser,
|
||||||
profileType = "personal";
|
context,
|
||||||
}
|
|
||||||
if (isUsernameValid(usernameController.text) == false) {
|
|
||||||
usernamePopUp();
|
|
||||||
} else {
|
|
||||||
var response = await http.put(
|
|
||||||
Uri.parse("${AppEnviroment.baseApiUrl}/user/update/"),
|
|
||||||
headers: <String, String>{
|
|
||||||
"Content-Type": "application/json; charset=UTF-8"
|
|
||||||
},
|
|
||||||
body: jsonEncode(<String, dynamic>{
|
|
||||||
"idusers": widget.arguments.signedInUser.idUser,
|
|
||||||
"username": usernameController.text,
|
|
||||||
"fnam": fnameController.text,
|
|
||||||
"lname": lnameController.text,
|
|
||||||
"type": profileType,
|
|
||||||
"pro_pic_path": filePath,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
//print("Here4");
|
if (responseCode == 200) {
|
||||||
//print(response.statusCode);
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
@@ -159,7 +137,6 @@ class _MihPersonalProfileState extends State<MihPersonalProfile> {
|
|||||||
} else {
|
} else {
|
||||||
internetConnectionPopUp();
|
internetConnectionPopUp();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteFileApiCall(String filename) async {
|
Future<void> deleteFileApiCall(String filename) async {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:mzansi_innovation_hub/mih_components/mih_objects/app_user.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_objects/arguments.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||||
@@ -29,6 +30,45 @@ class MihUserApis {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> updateUser(
|
||||||
|
AppUser signedInUser,
|
||||||
|
String firstName,
|
||||||
|
String lastName,
|
||||||
|
String username,
|
||||||
|
String profilePicture,
|
||||||
|
bool isBusinessUser,
|
||||||
|
BuildContext context,
|
||||||
|
) async {
|
||||||
|
var fileName = profilePicture.replaceAll(RegExp(r' '), '-');
|
||||||
|
var filePath =
|
||||||
|
"${signedInUser.app_id}/profile_files/$fileName";
|
||||||
|
String profileType;
|
||||||
|
if (isBusinessUser) {
|
||||||
|
profileType = "business";
|
||||||
|
} else {
|
||||||
|
profileType = "personal";
|
||||||
|
}
|
||||||
|
var response = await http.put(
|
||||||
|
Uri.parse("${AppEnviroment.baseApiUrl}/user/update/"),
|
||||||
|
headers: <String, String>{
|
||||||
|
"Content-Type": "application/json; charset=UTF-8"
|
||||||
|
},
|
||||||
|
body: jsonEncode(<String, dynamic>{
|
||||||
|
"idusers": signedInUser.idUser,
|
||||||
|
"username": username,
|
||||||
|
"fnam": firstName,
|
||||||
|
"lname": lastName,
|
||||||
|
"type": profileType,
|
||||||
|
"pro_pic_path": filePath,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
return response.statusCode;
|
||||||
|
} else {
|
||||||
|
return response.statusCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static Future<void> deleteAccount(
|
static Future<void> deleteAccount(
|
||||||
String app_id,
|
String app_id,
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
|
|||||||
Reference in New Issue
Block a user