ProfileBusinessUpdate to take in BusinessUpdateArguments as parameter
This commit is contained in:
@@ -12,25 +12,25 @@ import 'package:patient_manager/components/myTextInput.dart';
|
||||
import 'package:patient_manager/components/mybutton.dart';
|
||||
import 'package:patient_manager/env/env.dart';
|
||||
import 'package:patient_manager/main.dart';
|
||||
import 'package:patient_manager/objects/appUser.dart';
|
||||
import 'package:patient_manager/objects/business.dart';
|
||||
import 'package:patient_manager/objects/businessUser.dart';
|
||||
import 'package:patient_manager/objects/arguments.dart';
|
||||
import 'package:supertokens_flutter/http.dart' as http;
|
||||
import 'package:supertokens_flutter/supertokens.dart';
|
||||
import 'package:http/http.dart' as http2;
|
||||
|
||||
class ProfileBusinessUpdate extends StatefulWidget {
|
||||
//final BusinessUserScreenArguments arguments;
|
||||
final AppUser signedInUser;
|
||||
final BusinessUpdateArguments arguments;
|
||||
//final AppUser signedInUser;
|
||||
const ProfileBusinessUpdate({
|
||||
super.key,
|
||||
required this.signedInUser,
|
||||
required this.arguments,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ProfileBusinessUpdate> createState() => _ProfileBusinessUpdateState();
|
||||
}
|
||||
|
||||
class BusinessUserScreenArguments {}
|
||||
|
||||
class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
final baseAPI = AppEnviroment.baseApiUrl;
|
||||
@@ -48,10 +48,10 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
late PlatformFile? selectedLogo = null;
|
||||
late PlatformFile? selectedSignature = null;
|
||||
|
||||
late Future<BusinessUser?> futureBusinessUser;
|
||||
BusinessUser? businessUser;
|
||||
late Future<Business?> futureBusiness;
|
||||
Business? business;
|
||||
// late Future<BusinessUser?> futureBusinessUser;
|
||||
// BusinessUser? businessUser;
|
||||
// late Future<Business?> futureBusiness;
|
||||
// Business? business;
|
||||
|
||||
late String business_id;
|
||||
late String oldLogoPath;
|
||||
@@ -75,31 +75,31 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<BusinessUser?> getBusinessUserDetails() async {
|
||||
var response = await http
|
||||
.get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}"));
|
||||
if (response.statusCode == 200) {
|
||||
String body = response.body;
|
||||
var decodedData = jsonDecode(body);
|
||||
BusinessUser business_User = BusinessUser.fromJson(decodedData);
|
||||
return business_User;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// Future<BusinessUser?> getBusinessUserDetails() async {
|
||||
// var response = await http
|
||||
// .get(Uri.parse("$baseAPI/business-user/${widget.signedInUser.app_id}"));
|
||||
// if (response.statusCode == 200) {
|
||||
// String body = response.body;
|
||||
// var decodedData = jsonDecode(body);
|
||||
// BusinessUser business_User = BusinessUser.fromJson(decodedData);
|
||||
// return business_User;
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<Business?> getBusinessDetails() async {
|
||||
var response = await http.get(
|
||||
Uri.parse("$baseAPI/business/app_id/${widget.signedInUser.app_id}"));
|
||||
if (response.statusCode == 200) {
|
||||
String body = response.body;
|
||||
var decodedData = jsonDecode(body);
|
||||
Business business = Business.fromJson(decodedData);
|
||||
return business;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
// Future<Business?> getBusinessDetails() async {
|
||||
// var response = await http.get(
|
||||
// Uri.parse("$baseAPI/business/app_id/${widget.signedInUser.app_id}"));
|
||||
// if (response.statusCode == 200) {
|
||||
// String body = response.body;
|
||||
// var decodedData = jsonDecode(body);
|
||||
// Business business = Business.fromJson(decodedData);
|
||||
// return business;
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<void> uploadSelectedFile(
|
||||
PlatformFile? file, TextEditingController controller) async {
|
||||
@@ -113,7 +113,7 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
request.headers['accept'] = 'application/json';
|
||||
request.headers['Authorization'] = 'Bearer $token';
|
||||
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.files.add(await http2.MultipartFile.fromBytes('file', file!.bytes!,
|
||||
filename: file.name.replaceAll(RegExp(r' '), '-')));
|
||||
@@ -132,10 +132,10 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
},
|
||||
body: jsonEncode(<String, dynamic>{
|
||||
"business_id": business_id,
|
||||
"app_id": widget.signedInUser.app_id,
|
||||
"app_id": widget.arguments.signedInUser.app_id,
|
||||
"signature": signtureController.text,
|
||||
"sig_path":
|
||||
"${widget.signedInUser.app_id}/business_files/${signtureController.text}",
|
||||
"${widget.arguments.signedInUser.app_id}/business_files/${signtureController.text}",
|
||||
"title": titleController.text,
|
||||
"access": accessController.text,
|
||||
}),
|
||||
@@ -176,7 +176,7 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
"registration_no": regController.text,
|
||||
"logo_name": logonameController.text,
|
||||
"logo_path":
|
||||
"${widget.signedInUser.app_id}/business_files/${logonameController.text}",
|
||||
"${widget.arguments.signedInUser.app_id}/business_files/${logonameController.text}",
|
||||
}),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
@@ -220,33 +220,23 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
futureBusinessUser = getBusinessUserDetails().then((results) {
|
||||
//print(results);
|
||||
setState(() {
|
||||
businessUser = results;
|
||||
titleController.text = businessUser!.title;
|
||||
fnameController.text = widget.signedInUser.fname;
|
||||
lnameController.text = widget.signedInUser.lname;
|
||||
signtureController.text = businessUser!.signature;
|
||||
titleController.text = businessUser!.title;
|
||||
accessController.text = businessUser!.access;
|
||||
oldSigPath = businessUser!.sig_path;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
//businessUser = results;
|
||||
titleController.text = widget.arguments.businessUser!.title;
|
||||
fnameController.text = widget.arguments.signedInUser.fname;
|
||||
lnameController.text = widget.arguments.signedInUser.lname;
|
||||
signtureController.text = widget.arguments.businessUser!.signature;
|
||||
titleController.text = widget.arguments.businessUser!.title;
|
||||
accessController.text = widget.arguments.businessUser!.access;
|
||||
oldSigPath = widget.arguments.businessUser!.sig_path;
|
||||
|
||||
futureBusiness = getBusinessDetails().then((results) {
|
||||
//print(results);
|
||||
setState(() {
|
||||
business = results;
|
||||
business_id = business!.business_id;
|
||||
regController.text = business!.registration_no;
|
||||
nameController.text = business!.Name;
|
||||
typeController.text = business!.type;
|
||||
logonameController.text = business!.logo_name;
|
||||
oldLogoPath = business!.logo_path;
|
||||
});
|
||||
return null;
|
||||
//business = results;
|
||||
business_id = widget.arguments.business!.business_id;
|
||||
regController.text = widget.arguments.business!.registration_no;
|
||||
nameController.text = widget.arguments.business!.Name;
|
||||
typeController.text = widget.arguments.business!.type;
|
||||
logonameController.text = widget.arguments.business!.logo_name;
|
||||
oldLogoPath = widget.arguments.business!.logo_path;
|
||||
});
|
||||
|
||||
super.initState();
|
||||
@@ -269,6 +259,8 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.all(25),
|
||||
child: Column(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
const Text(
|
||||
"Update Business Profile:",
|
||||
@@ -323,8 +315,13 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
),
|
||||
const SizedBox(height: 15.0),
|
||||
Divider(
|
||||
color: MzanziInnovationHub.of(context)?.theme.secondaryColor(),
|
||||
color:
|
||||
MzanziInnovationHub.of(context)?.theme.secondaryColor(),
|
||||
),
|
||||
],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
const SizedBox(height: 15.0),
|
||||
const Text(
|
||||
"My Business User:",
|
||||
@@ -391,8 +388,9 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
height: 100.0,
|
||||
child: MyButton(
|
||||
buttonText: "Add",
|
||||
buttonColor:
|
||||
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||
buttonColor: MzanziInnovationHub.of(context)!
|
||||
.theme
|
||||
.secondaryColor(),
|
||||
textColor:
|
||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||
onTap: () {
|
||||
@@ -403,6 +401,8 @@ class _ProfileBusinessUpdateState extends State<ProfileBusinessUpdate> {
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user