ProfileBusinessUpdate to take in BusinessUpdateArguments as parameter

This commit is contained in:
2024-08-08 13:29:40 +02:00
parent de8f63c116
commit 92c8220a65

View File

@@ -12,25 +12,25 @@ import 'package:patient_manager/components/myTextInput.dart';
import 'package:patient_manager/components/mybutton.dart'; import 'package:patient_manager/components/mybutton.dart';
import 'package:patient_manager/env/env.dart'; import 'package:patient_manager/env/env.dart';
import 'package:patient_manager/main.dart'; import 'package:patient_manager/main.dart';
import 'package:patient_manager/objects/appUser.dart'; import 'package:patient_manager/objects/arguments.dart';
import 'package:patient_manager/objects/business.dart';
import 'package:patient_manager/objects/businessUser.dart';
import 'package:supertokens_flutter/http.dart' as http; import 'package:supertokens_flutter/http.dart' as http;
import 'package:supertokens_flutter/supertokens.dart'; import 'package:supertokens_flutter/supertokens.dart';
import 'package:http/http.dart' as http2; import 'package:http/http.dart' as http2;
class ProfileBusinessUpdate extends StatefulWidget { class ProfileBusinessUpdate extends StatefulWidget {
//final BusinessUserScreenArguments arguments; final BusinessUpdateArguments arguments;
final AppUser signedInUser; //final AppUser signedInUser;
const ProfileBusinessUpdate({ const ProfileBusinessUpdate({
super.key, super.key,
required this.signedInUser, required this.arguments,
}); });
@override @override
State<ProfileBusinessUpdate> createState() => _ProfileBusinessUpdateState(); State<ProfileBusinessUpdate> createState() => _ProfileBusinessUpdateState();
} }
class BusinessUserScreenArguments {}
class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> { class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
final FocusNode _focusNode = FocusNode(); final FocusNode _focusNode = FocusNode();
final baseAPI = AppEnviroment.baseApiUrl; final baseAPI = AppEnviroment.baseApiUrl;
@@ -48,10 +48,10 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
late PlatformFile? selectedLogo = null; late PlatformFile? selectedLogo = null;
late PlatformFile? selectedSignature = null; late PlatformFile? selectedSignature = null;
late Future<BusinessUser?> futureBusinessUser; // late Future<BusinessUser?> futureBusinessUser;
BusinessUser? businessUser; // BusinessUser? businessUser;
late Future<Business?> futureBusiness; // late Future<Business?> futureBusiness;
Business? business; // Business? business;
late String business_id; late String business_id;
late String oldLogoPath; late String oldLogoPath;
@@ -75,31 +75,31 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
} }
} }
Future<BusinessUser?> getBusinessUserDetails() async { // Future<BusinessUser?> getBusinessUserDetails() async {
var response = await http // var response = await http
.get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}")); // .get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}"));
if (response.statusCode == 200) { // if (response.statusCode == 200) {
String body = response.body; // String body = response.body;
var decodedData = jsonDecode(body); // var decodedData = jsonDecode(body);
BusinessUser business_User = BusinessUser.fromJson(decodedData); // BusinessUser business_User = BusinessUser.fromJson(decodedData);
return business_User; // return business_User;
} else { // } else {
return null; // return null;
} // }
} // }
Future<Business?> getBusinessDetails() async { // Future<Business?> getBusinessDetails() async {
var response = await http.get( // var response = await http.get(
Uri.parse("$baseAPI/business/app_id/${widget.signedInUser.app_id}")); // Uri.parse("$baseAPI/business/app_id/${widget.signedInUser.app_id}"));
if (response.statusCode == 200) { // if (response.statusCode == 200) {
String body = response.body; // String body = response.body;
var decodedData = jsonDecode(body); // var decodedData = jsonDecode(body);
Business business = Business.fromJson(decodedData); // Business business = Business.fromJson(decodedData);
return business; // return business;
} else { // } else {
return null; // return null;
} // }
} // }
Future<void> uploadSelectedFile( Future<void> uploadSelectedFile(
PlatformFile? file, TextEditingController controller) async { PlatformFile? file, TextEditingController controller) async {
@@ -113,7 +113,7 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
request.headers['accept'] = 'application/json'; request.headers['accept'] = 'application/json';
request.headers['Authorization'] = 'Bearer $token'; request.headers['Authorization'] = 'Bearer $token';
request.headers['Content-Type'] = 'multipart/form-data'; request.headers['Content-Type'] = 'multipart/form-data';
request.fields['app_id'] = widget.signedInUser.app_id; request.fields['app_id'] = widget.arguments.signedInUser.app_id;
request.fields['folder'] = "business_files"; request.fields['folder'] = "business_files";
request.files.add(await http2.MultipartFile.fromBytes('file', file!.bytes!, request.files.add(await http2.MultipartFile.fromBytes('file', file!.bytes!,
filename: file.name.replaceAll(RegExp(r' '), '-'))); filename: file.name.replaceAll(RegExp(r' '), '-')));
@@ -132,10 +132,10 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
}, },
body: jsonEncode(<String, dynamic>{ body: jsonEncode(<String, dynamic>{
"business_id": business_id, "business_id": business_id,
"app_id": widget.signedInUser.app_id, "app_id": widget.arguments.signedInUser.app_id,
"signature": signtureController.text, "signature": signtureController.text,
"sig_path": "sig_path":
"${widget.signedInUser.app_id}/business_files/${signtureController.text}", "${widget.arguments.signedInUser.app_id}/business_files/${signtureController.text}",
"title": titleController.text, "title": titleController.text,
"access": accessController.text, "access": accessController.text,
}), }),
@@ -176,7 +176,7 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
"registration_no": regController.text, "registration_no": regController.text,
"logo_name": logonameController.text, "logo_name": logonameController.text,
"logo_path": "logo_path":
"${widget.signedInUser.app_id}/business_files/${logonameController.text}", "${widget.arguments.signedInUser.app_id}/business_files/${logonameController.text}",
}), }),
); );
if (response.statusCode == 200) { if (response.statusCode == 200) {
@@ -220,33 +220,23 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
@override @override
void initState() { void initState() {
futureBusinessUser = getBusinessUserDetails().then((results) { setState(() {
//print(results); //businessUser = results;
setState(() { titleController.text = widget.arguments.businessUser!.title;
businessUser = results; fnameController.text = widget.arguments.signedInUser.fname;
titleController.text = businessUser!.title; lnameController.text = widget.arguments.signedInUser.lname;
fnameController.text = widget.signedInUser.fname; signtureController.text = widget.arguments.businessUser!.signature;
lnameController.text = widget.signedInUser.lname; titleController.text = widget.arguments.businessUser!.title;
signtureController.text = businessUser!.signature; accessController.text = widget.arguments.businessUser!.access;
titleController.text = businessUser!.title; oldSigPath = widget.arguments.businessUser!.sig_path;
accessController.text = businessUser!.access;
oldSigPath = businessUser!.sig_path;
});
return null;
});
futureBusiness = getBusinessDetails().then((results) { //business = results;
//print(results); business_id = widget.arguments.business!.business_id;
setState(() { regController.text = widget.arguments.business!.registration_no;
business = results; nameController.text = widget.arguments.business!.Name;
business_id = business!.business_id; typeController.text = widget.arguments.business!.type;
regController.text = business!.registration_no; logonameController.text = widget.arguments.business!.logo_name;
nameController.text = business!.Name; oldLogoPath = widget.arguments.business!.logo_path;
typeController.text = business!.type;
logonameController.text = business!.logo_name;
oldLogoPath = business!.logo_path;
});
return null;
}); });
super.initState(); super.initState();
@@ -270,136 +260,146 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
padding: EdgeInsets.all(25), padding: EdgeInsets.all(25),
child: Column( child: Column(
children: [ children: [
const Text( Column(
"Update Business Profile:", children: [
style: TextStyle( const Text(
fontWeight: FontWeight.bold, "Update Business Profile:",
fontSize: 25, style: TextStyle(
), fontWeight: FontWeight.bold,
fontSize: 25,
),
),
const SizedBox(height: 15.0),
MyTextField(
controller: regController,
hintText: "Registration No.",
editable: true,
required: true,
),
const SizedBox(height: 10.0),
MyTextField(
controller: nameController,
hintText: "Business Name",
editable: true,
required: true,
),
const SizedBox(height: 10.0),
MyDropdownField(
controller: typeController,
hintText: "Business Type",
dropdownOptions: const ["Doctors Office", "Other"],
required: true,
editable: true,
),
const SizedBox(height: 10.0),
MyFileField(
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: 15.0),
Divider(
color:
MzanziInnovationHub.of(context)?.theme.secondaryColor(),
),
],
), ),
const SizedBox(height: 15.0), Column(
MyTextField( children: [
controller: regController, const SizedBox(height: 15.0),
hintText: "Registration No.", const Text(
editable: true, "My Business User:",
required: true, style: TextStyle(
), fontWeight: FontWeight.bold,
const SizedBox(height: 10.0), fontSize: 25,
MyTextField( ),
controller: nameController, ),
hintText: "Business Name", const SizedBox(height: 15.0),
editable: true, MyDropdownField(
required: true, controller: titleController,
), hintText: "Title",
const SizedBox(height: 10.0), dropdownOptions: const ["Doctor", "Assistant"],
MyDropdownField( required: true,
controller: typeController, editable: true,
hintText: "Business Type", ),
dropdownOptions: const ["Doctors Office", "Other"], const SizedBox(height: 10.0),
required: true, MyTextField(
editable: true, controller: fnameController,
), hintText: "Name",
const SizedBox(height: 10.0), editable: false,
MyFileField( required: true,
controller: logonameController, ),
hintText: "Logo", const SizedBox(height: 10.0),
editable: false, MyTextField(
required: true, controller: lnameController,
onPressed: () async { hintText: "Surname",
FilePickerResult? result = editable: false,
await FilePicker.platform.pickFiles( required: true,
type: FileType.custom, ),
allowedExtensions: ['jpg', 'png', 'pdf'], const SizedBox(height: 10.0),
); MyFileField(
if (result == null) return; controller: signtureController,
final selectedFile = result.files.first; hintText: "Signature",
setState(() { editable: false,
selectedLogo = selectedFile; required: true,
}); onPressed: () async {
setState(() { FilePickerResult? result =
logonameController.text = selectedFile.name; await FilePicker.platform.pickFiles(
}); type: FileType.custom,
}, allowedExtensions: ['jpg', 'png', 'pdf'],
), );
const SizedBox(height: 15.0), if (result == null) return;
Divider( final selectedFile = result.files.first;
color: MzanziInnovationHub.of(context)?.theme.secondaryColor(), setState(() {
), selectedSignature = selectedFile;
const SizedBox(height: 15.0), });
const Text( setState(() {
"My Business User:", signtureController.text = selectedFile.name;
style: TextStyle( });
fontWeight: FontWeight.bold, },
fontSize: 25, ),
), const SizedBox(height: 15.0),
), MyDropdownField(
const SizedBox(height: 15.0), controller: accessController,
MyDropdownField( hintText: "Access",
controller: titleController, dropdownOptions: const ["Full", "Partial"],
hintText: "Title", required: true,
dropdownOptions: const ["Doctor", "Assistant"], editable: false,
required: true, ),
editable: true, const SizedBox(height: 15.0),
), SizedBox(
const SizedBox(height: 10.0), width: 500.0,
MyTextField( height: 100.0,
controller: fnameController, child: MyButton(
hintText: "Name", buttonText: "Add",
editable: false, buttonColor: MzanziInnovationHub.of(context)!
required: true, .theme
), .secondaryColor(),
const SizedBox(height: 10.0), textColor:
MyTextField( MzanziInnovationHub.of(context)!.theme.primaryColor(),
controller: lnameController, onTap: () {
hintText: "Surname", //print(business_id);
editable: false, submitForm(business_id);
required: true, },
), ),
const SizedBox(height: 10.0), ),
MyFileField( ],
controller: signtureController,
hintText: "Signature",
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(() {
selectedSignature = selectedFile;
});
setState(() {
signtureController.text = selectedFile.name;
});
},
),
const SizedBox(height: 15.0),
MyDropdownField(
controller: accessController,
hintText: "Access",
dropdownOptions: const ["Full", "Partial"],
required: true,
editable: false,
),
const SizedBox(height: 15.0),
SizedBox(
width: 500.0,
height: 100.0,
child: MyButton(
buttonText: "Add",
buttonColor:
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
textColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(),
onTap: () {
//print(business_id);
submitForm(business_id);
},
),
), ),
], ],
), ),