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) {
//print(results);
setState(() { setState(() {
businessUser = results; //businessUser = results;
titleController.text = businessUser!.title; titleController.text = widget.arguments.businessUser!.title;
fnameController.text = widget.signedInUser.fname; fnameController.text = widget.arguments.signedInUser.fname;
lnameController.text = widget.signedInUser.lname; lnameController.text = widget.arguments.signedInUser.lname;
signtureController.text = businessUser!.signature; signtureController.text = widget.arguments.businessUser!.signature;
titleController.text = businessUser!.title; titleController.text = widget.arguments.businessUser!.title;
accessController.text = businessUser!.access; accessController.text = widget.arguments.businessUser!.access;
oldSigPath = businessUser!.sig_path; oldSigPath = widget.arguments.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();
@@ -269,6 +259,8 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
child: SingleChildScrollView( child: SingleChildScrollView(
padding: EdgeInsets.all(25), padding: EdgeInsets.all(25),
child: Column( child: Column(
children: [
Column(
children: [ children: [
const Text( const Text(
"Update Business Profile:", "Update Business Profile:",
@@ -323,8 +315,13 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
), ),
const SizedBox(height: 15.0), const SizedBox(height: 15.0),
Divider( Divider(
color: MzanziInnovationHub.of(context)?.theme.secondaryColor(), color:
MzanziInnovationHub.of(context)?.theme.secondaryColor(),
), ),
],
),
Column(
children: [
const SizedBox(height: 15.0), const SizedBox(height: 15.0),
const Text( const Text(
"My Business User:", "My Business User:",
@@ -391,8 +388,9 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
height: 100.0, height: 100.0,
child: MyButton( child: MyButton(
buttonText: "Add", buttonText: "Add",
buttonColor: buttonColor: MzanziInnovationHub.of(context)!
MzanziInnovationHub.of(context)!.theme.secondaryColor(), .theme
.secondaryColor(),
textColor: textColor:
MzanziInnovationHub.of(context)!.theme.primaryColor(), MzanziInnovationHub.of(context)!.theme.primaryColor(),
onTap: () { onTap: () {
@@ -403,6 +401,8 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
), ),
], ],
), ),
],
),
), ),
), ),
); );