legacy code
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_apis/mih_file_api.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_apis/mih_location_api.dart';
|
import 'package:mzansi_innovation_hub/mih_apis/mih_location_api.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
|
||||||
@@ -11,14 +12,13 @@ import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih-
|
|||||||
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';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_success_message.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_components/mih_profile_picture.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_env/env.dart';
|
import 'package:mzansi_innovation_hub/mih_env/env.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_objects/arguments.dart';
|
import 'package:mzansi_innovation_hub/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:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:supertokens_flutter/http.dart' as http;
|
import 'package:supertokens_flutter/http.dart' as http;
|
||||||
import 'package:http/http.dart' as http2;
|
|
||||||
import 'package:supertokens_flutter/supertokens.dart';
|
|
||||||
|
|
||||||
class MihBusinessProfile extends StatefulWidget {
|
class MihBusinessProfile extends StatefulWidget {
|
||||||
final BusinessArguments arguments;
|
final BusinessArguments arguments;
|
||||||
@@ -52,14 +52,18 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
|
|
||||||
late PlatformFile? selectedLogo = null;
|
late PlatformFile? selectedLogo = null;
|
||||||
late PlatformFile? selectedSignature = null;
|
late PlatformFile? selectedSignature = null;
|
||||||
|
PlatformFile? logoFile;
|
||||||
|
ImageProvider<Object>? logoPreview = null;
|
||||||
|
|
||||||
final ValueNotifier<String> busType = ValueNotifier("");
|
final ValueNotifier<String> busType = ValueNotifier("");
|
||||||
|
|
||||||
late String business_id;
|
late String business_id;
|
||||||
late String oldLogoPath;
|
late String oldLogoPath;
|
||||||
late String oldSigPath;
|
late String oldSigPath;
|
||||||
|
String logoUri = "";
|
||||||
|
|
||||||
Future<void> updateBusinessProfileAPICall(String business_id) async {
|
Future<void> updateBusinessProfileAPICall(String business_id) async {
|
||||||
|
print("inside update business profile api call");
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
@@ -89,9 +93,8 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
//var businessResponse = jsonDecode(response.body);
|
//var businessResponse = jsonDecode(response.body);
|
||||||
//print(selectedLogo != null);
|
//print(selectedLogo != null);
|
||||||
if (selectedLogo != null) {
|
if (logoFile != null) {
|
||||||
uploadSelectedFile(selectedLogo, logonameController);
|
uploadSelectedFile(logoFile);
|
||||||
deleteFileApiCall(oldLogoPath);
|
|
||||||
}
|
}
|
||||||
updateBusinessUserAPICall(business_id);
|
updateBusinessUserAPICall(business_id);
|
||||||
} else {
|
} else {
|
||||||
@@ -117,7 +120,7 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
);
|
);
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
if (selectedSignature != null) {
|
if (selectedSignature != null) {
|
||||||
uploadSelectedFile(selectedSignature, signtureController);
|
uploadSelectedFile(selectedSignature);
|
||||||
deleteFileApiCall(oldSigPath);
|
deleteFileApiCall(oldSigPath);
|
||||||
}
|
}
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
@@ -138,23 +141,16 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> uploadSelectedFile(
|
Future<void> uploadSelectedFile(PlatformFile? file) async {
|
||||||
PlatformFile? file, TextEditingController controller) async {
|
print("Inside upload selected file");
|
||||||
//to-do delete file when changed
|
var response = await MihFileApi.uploadFile(
|
||||||
var token = await SuperTokens.getAccessToken();
|
widget.arguments.signedInUser.app_id,
|
||||||
//print(t);
|
"business_files",
|
||||||
//print("here1");
|
file,
|
||||||
var request = http2.MultipartRequest(
|
context,
|
||||||
'POST', Uri.parse("${AppEnviroment.baseApiUrl}/minio/upload/file/"));
|
);
|
||||||
request.headers['accept'] = 'application/json';
|
if (response == 200) {
|
||||||
request.headers['Authorization'] = 'Bearer $token';
|
deleteFileApiCall(oldLogoPath);
|
||||||
request.headers['Content-Type'] = 'multipart/form-data';
|
|
||||||
request.fields['app_id'] = widget.arguments.signedInUser.app_id;
|
|
||||||
request.fields['folder'] = "business_files";
|
|
||||||
request.files.add(await http2.MultipartFile.fromBytes('file', file!.bytes!,
|
|
||||||
filename: file.name.replaceAll(RegExp(r' '), '-')));
|
|
||||||
var response1 = await request.send();
|
|
||||||
if (response1.statusCode == 200) {
|
|
||||||
} else {
|
} else {
|
||||||
internetConnectionPopUp();
|
internetConnectionPopUp();
|
||||||
}
|
}
|
||||||
@@ -162,16 +158,13 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
|
|
||||||
Future<void> deleteFileApiCall(String filePath) async {
|
Future<void> deleteFileApiCall(String filePath) async {
|
||||||
// delete file from minio
|
// delete file from minio
|
||||||
var response = await http.delete(
|
var response = await MihFileApi.deleteFile(
|
||||||
Uri.parse("$baseAPI/minio/delete/file/"),
|
widget.arguments.signedInUser.app_id,
|
||||||
headers: <String, String>{
|
"business_files",
|
||||||
"Content-Type": "application/json; charset=UTF-8"
|
filePath.split("/").last,
|
||||||
},
|
context,
|
||||||
body: jsonEncode(<String, dynamic>{"file_path": filePath}),
|
|
||||||
);
|
);
|
||||||
//print("Here4");
|
if (response == 200) {
|
||||||
//print(response.statusCode);
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
//SQL delete
|
//SQL delete
|
||||||
} else {
|
} else {
|
||||||
internetConnectionPopUp();
|
internetConnectionPopUp();
|
||||||
@@ -222,6 +215,7 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
if (!validEmail()) {
|
if (!validEmail()) {
|
||||||
emailError();
|
emailError();
|
||||||
} else if (isFieldsFilled()) {
|
} else if (isFieldsFilled()) {
|
||||||
|
print("inside submit form mthod");
|
||||||
updateBusinessProfileAPICall(business_id);
|
updateBusinessProfileAPICall(business_id);
|
||||||
} else {
|
} else {
|
||||||
showDialog(
|
showDialog(
|
||||||
@@ -263,6 +257,20 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImageProvider<Object>? isPictureAvailable(String url) {
|
||||||
|
print("logo Url: $url");
|
||||||
|
if (url == "") {
|
||||||
|
return const AssetImage(
|
||||||
|
'lib/mih_components/mih_package_components/assets/images/i-dont-know-2.png');
|
||||||
|
} else if (url != "") {
|
||||||
|
return NetworkImage(url);
|
||||||
|
} else {
|
||||||
|
return const AssetImage(
|
||||||
|
'lib/mih_components/mih_package_components/assets/images/i-dont-know-2.png');
|
||||||
|
// return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
nameController.dispose();
|
nameController.dispose();
|
||||||
@@ -306,6 +314,15 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
practiceNoController.text = widget.arguments.business!.practice_no;
|
practiceNoController.text = widget.arguments.business!.practice_no;
|
||||||
vatNoController.text = widget.arguments.business!.vat_no;
|
vatNoController.text = widget.arguments.business!.vat_no;
|
||||||
});
|
});
|
||||||
|
MihFileApi.getMinioFileUrl(
|
||||||
|
widget.arguments.business!.logo_path,
|
||||||
|
context,
|
||||||
|
).then((value) {
|
||||||
|
setState(() {
|
||||||
|
logoUri = value;
|
||||||
|
});
|
||||||
|
logoPreview = isPictureAvailable(logoUri);
|
||||||
|
});
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,8 +360,48 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Divider(
|
Divider(
|
||||||
color:
|
color: MzanziInnovationHub.of(context)
|
||||||
MzanziInnovationHub.of(context)?.theme.secondaryColor(),
|
?.theme
|
||||||
|
.secondaryColor()),
|
||||||
|
const SizedBox(height: 10.0),
|
||||||
|
MIHProfilePicture(
|
||||||
|
profilePictureFile: logoPreview,
|
||||||
|
proPicController: logonameController,
|
||||||
|
proPic: logoFile,
|
||||||
|
width: 155,
|
||||||
|
radius: 70,
|
||||||
|
drawerMode: false,
|
||||||
|
editable: true,
|
||||||
|
frameColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
onChange: (newProPic) {
|
||||||
|
setState(() {
|
||||||
|
logoFile = newProPic;
|
||||||
|
});
|
||||||
|
print("logoFile: ${logoFile?.bytes}");
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10.0),
|
||||||
|
MIHFileField(
|
||||||
|
controller: logonameController,
|
||||||
|
hintText: "Logo",
|
||||||
|
editable: false,
|
||||||
|
required: true,
|
||||||
|
onPressed: () async {
|
||||||
|
FilePickerResult? result =
|
||||||
|
await FilePicker.platform.pickFiles(
|
||||||
|
type: FileType.custom,
|
||||||
|
allowedExtensions: ['jpg', 'png'],
|
||||||
|
);
|
||||||
|
if (result == null) return;
|
||||||
|
final selectedFile = result.files.first;
|
||||||
|
setState(() {
|
||||||
|
selectedLogo = selectedFile;
|
||||||
|
});
|
||||||
|
setState(() {
|
||||||
|
logonameController.text = selectedFile.name;
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10.0),
|
const SizedBox(height: 10.0),
|
||||||
MIHTextField(
|
MIHTextField(
|
||||||
@@ -407,28 +464,6 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
required: true,
|
required: true,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10.0),
|
const SizedBox(height: 10.0),
|
||||||
MIHFileField(
|
|
||||||
controller: logonameController,
|
|
||||||
hintText: "Logo",
|
|
||||||
editable: false,
|
|
||||||
required: true,
|
|
||||||
onPressed: () async {
|
|
||||||
FilePickerResult? result =
|
|
||||||
await FilePicker.platform.pickFiles(
|
|
||||||
type: FileType.custom,
|
|
||||||
allowedExtensions: ['jpg', 'png', 'pdf'],
|
|
||||||
);
|
|
||||||
if (result == null) return;
|
|
||||||
final selectedFile = result.files.first;
|
|
||||||
setState(() {
|
|
||||||
selectedLogo = selectedFile;
|
|
||||||
});
|
|
||||||
setState(() {
|
|
||||||
logonameController.text = selectedFile.name;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10.0),
|
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Flexible(
|
Flexible(
|
||||||
@@ -489,7 +524,7 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
MIHDropdownField(
|
MIHDropdownField(
|
||||||
controller: titleController,
|
controller: titleController,
|
||||||
hintText: "Title",
|
hintText: "Title",
|
||||||
dropdownOptions: const ["Doctor", "Assistant"],
|
dropdownOptions: const ["Doctor", "Assistant", "Other"],
|
||||||
required: true,
|
required: true,
|
||||||
editable: true,
|
editable: true,
|
||||||
enableSearch: false,
|
enableSearch: false,
|
||||||
@@ -551,6 +586,7 @@ class _MihBusinessProfileState extends State<MihBusinessProfile> {
|
|||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
//print(business_id);
|
//print(business_id);
|
||||||
|
print("submit form call");
|
||||||
submitForm(business_id);
|
submitForm(business_id);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user