508 lines
24 KiB
Dart
508 lines
24 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart' hide MultipartFile, FormData;
|
|
import 'package:regroup/Common/CommonButton.dart';
|
|
import 'package:regroup/Common/CommonWidget.dart';
|
|
import 'package:regroup/Common/base_manager.dart';
|
|
import 'package:regroup/Main_Screens/ProfileTab/EditProfile/View/picturecontroller/profileimagecontoller.dart';
|
|
import 'package:regroup/Main_Screens/ProfileTab/EditProfile/ViewModel/EditProfileApi.dart';
|
|
import 'package:regroup/Utils/Common/CommonAppbar.dart';
|
|
import 'package:regroup/Utils/Common/ImageUpload.dart';
|
|
import 'package:regroup/Utils/Common/sized_box.dart';
|
|
import 'package:regroup/Utils/dialogs.dart';
|
|
import 'package:regroup/Utils/texts.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:regroup/resources/routes/route_name.dart';
|
|
|
|
import '../../../../../Utils/Common/CustomTextformfield.dart';
|
|
|
|
class BusEditProfile extends StatefulWidget {
|
|
const BusEditProfile({super.key});
|
|
|
|
@override
|
|
State<BusEditProfile> createState() => _BusEditProfileState();
|
|
}
|
|
|
|
class _BusEditProfileState extends State<BusEditProfile> {
|
|
TextEditingController busNameController = TextEditingController();
|
|
TextEditingController busUserNameController = TextEditingController();
|
|
TextEditingController ownerNameController = TextEditingController();
|
|
|
|
TextEditingController foundedonController = TextEditingController();
|
|
TextEditingController websiteLinkController = TextEditingController();
|
|
TextEditingController locationController = TextEditingController();
|
|
TextEditingController bioController = TextEditingController();
|
|
|
|
String profilePicture = "";
|
|
bool isImageAdded = false;
|
|
|
|
bool isOnce = true;
|
|
late Future myfuture;
|
|
|
|
convertFileToMultiPart(String? file) async {
|
|
return await MultipartFile.fromFile(
|
|
file!,
|
|
filename: path.basename(file),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
|
|
myfuture = EditProfileApi()
|
|
.getEditProfileBusiness()
|
|
.then((value) => {setValues()});
|
|
super.initState();
|
|
}
|
|
|
|
//Founded on & bio , businessUsername data not there
|
|
|
|
setValues() {
|
|
if (isOnce) {
|
|
busNameController.text = getEditProfileBus!.data!.businessName ?? '';
|
|
busUserNameController.text =
|
|
getEditProfileBus!.data!.businessOwnerName ?? 'victorygames _10';
|
|
ownerNameController.text =
|
|
getEditProfileBus!.data!.businessOwnerName ?? 'James Bothman';
|
|
foundedonController.text =
|
|
getEditProfileBus!.data!.foundedon ?? '12-04-2024';
|
|
websiteLinkController.text =
|
|
getEditProfileBus!.data!.websiteLink ?? 'victorygames _10';
|
|
locationController.text = getEditProfileBus!.data!.businessLocation ??
|
|
'Elm street london, United Kingdom';
|
|
|
|
bioController.text = getEditProfileBus!.data!.bio ?? "";
|
|
|
|
// _selectedgenderType = getEditProfileIndi!.data!.gender ?? '';
|
|
// _selectedsportType = getEditProfileIndi!.data!.interest!.join(', ') ?? '';
|
|
|
|
isOnce = false;
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
void saveEditProfileBus() async {
|
|
var imageFile;
|
|
|
|
if (editProfileImage.usserprofilePicPath.value.isNotEmpty) {
|
|
imageFile = await MultipartFile.fromFile(
|
|
editProfileImage.usserprofilePicPath.value,
|
|
filename: path.basename(profilePicture),
|
|
);
|
|
}
|
|
|
|
FormData? updata;
|
|
if (busNameController.text.isBlank! ||
|
|
busUserNameController.text.isBlank! ||
|
|
ownerNameController.text.isBlank! ||
|
|
foundedonController.text.isBlank! ||
|
|
websiteLinkController.text.isBlank! ||
|
|
locationController.text.isBlank! ||
|
|
bioController.text.isBlank!) {
|
|
Get.snackbar(
|
|
'Error',
|
|
'Enter your credentials',
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
backgroundColor: Colors.red,
|
|
colorText: Colors.white,
|
|
);
|
|
}
|
|
// else if (profilePicture == "") {
|
|
// utils.showToast('Upload edit profile picture!');
|
|
// }
|
|
else {
|
|
utils.loader();
|
|
updata = FormData.fromMap({
|
|
"business_name": busNameController.text,
|
|
"business_username": busUserNameController.text,
|
|
"business_owner_name": ownerNameController.text,
|
|
"founded_on": foundedonController.text,
|
|
"website_link": websiteLinkController.text,
|
|
"business_location": locationController.text,
|
|
"bio": bioController.text,
|
|
"business_profile":
|
|
editProfileImage.usserprofilePicPath.isNotEmpty ? imageFile : null,
|
|
// await convertFileToMultiPart(profilePicture),
|
|
});
|
|
|
|
final data = await EditProfileApi().postEditProfileBusiness(updata);
|
|
if (data.status == ResponseStatus.SUCCESS) {
|
|
Get.back();
|
|
// await global.setname();
|
|
// Get.snackbar(
|
|
// "Success!",
|
|
// 'success!',
|
|
// duration: Duration(seconds: 2),
|
|
// colorText: Colors.white,
|
|
// backgroundColor: Colors.green,
|
|
// margin: EdgeInsets.all(8),
|
|
// snackStyle: SnackStyle.FLOATING,
|
|
// snackPosition: SnackPosition.BOTTOM,
|
|
// );
|
|
utils.showToast("Data Saved Successfully");
|
|
// Get.back();
|
|
Get.toNamed(RouteName.mainscreen, arguments: 4);
|
|
// Get.back(result: true);
|
|
} else {
|
|
Get.back();
|
|
// btnController.reset();
|
|
Get.snackbar(
|
|
"Error!",
|
|
data.data['message'],
|
|
duration: const Duration(seconds: 2),
|
|
colorText: Colors.white,
|
|
backgroundColor: Colors.red,
|
|
margin: const EdgeInsets.all(8),
|
|
snackStyle: SnackStyle.FLOATING,
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
);
|
|
// _controller.isTextFieldEnabled.value = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
final UserProfileImageController editProfileImage =
|
|
Get.put(UserProfileImageController());
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
|
|
child: Scaffold(
|
|
// key: _scaffoldKey1,
|
|
backgroundColor: const Color(0xFF222935),
|
|
extendBody: true,
|
|
appBar: const CommonAppbar(
|
|
titleTxt: "",
|
|
),
|
|
body: FutureBuilder(
|
|
future: myfuture,
|
|
builder: (ctx, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return
|
|
// const ShimmerCommon();
|
|
|
|
const Center(
|
|
child: CircularProgressIndicator(
|
|
color: Colors.blue,
|
|
),
|
|
);
|
|
}
|
|
|
|
if (snapshot.hasError) {
|
|
return Center(
|
|
child: Text(
|
|
'${snapshot.error} occurred',
|
|
style: TextStyle(fontSize: 18.spMin),
|
|
),
|
|
);
|
|
}
|
|
|
|
if (snapshot.connectionState == ConnectionState.done &&
|
|
snapshot.hasData) {
|
|
print("Data fetched-->");
|
|
return Stack(children: [
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(
|
|
"assets/images/png/Ellipse 1496.png"),
|
|
fit: BoxFit.fill)),
|
|
),
|
|
SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Column(children: [
|
|
sizedBoxHeight(25.h),
|
|
Stack(
|
|
children: [
|
|
Obx(
|
|
() => editProfileImage
|
|
.usserprofilePicPath.value !=
|
|
''
|
|
? ClipOval(
|
|
child: SizedBox.fromSize(
|
|
size: Size.fromRadius(50.r),
|
|
child: editProfileImage
|
|
.usserprofilePicPath
|
|
.value !=
|
|
''
|
|
? Image(
|
|
// File(profilePicture),
|
|
image: FileImage(
|
|
File(
|
|
editProfileImage
|
|
.usserprofilePicPath
|
|
.value,
|
|
),
|
|
),
|
|
fit: BoxFit.cover,
|
|
width: double.infinity,
|
|
errorBuilder:
|
|
(BuildContext
|
|
context,
|
|
Object
|
|
exception,
|
|
StackTrace?
|
|
stackTrace) {
|
|
return CircleAvatar(
|
|
backgroundImage:
|
|
const AssetImage(
|
|
"assets/images/png/Ellipse 37 (1).png"),
|
|
radius: 50.r,
|
|
);
|
|
},
|
|
)
|
|
: Image.asset(
|
|
'assets/images/png/Ellipse 37 (1).png')),
|
|
)
|
|
: ClipOval(
|
|
child: SizedBox.fromSize(
|
|
size: Size.fromRadius(60.r),
|
|
child: getEditProfileBus!.data!
|
|
.businessProfileImage !=
|
|
null
|
|
? ClipOval(
|
|
child:
|
|
SizedBox.fromSize(
|
|
size: Size.fromRadius(
|
|
25.r),
|
|
child: CircleAvatar(
|
|
backgroundImage:
|
|
NetworkImage(
|
|
getEditProfileBus!
|
|
.data!
|
|
.businessProfileImage!),
|
|
radius: 25.r,
|
|
),
|
|
),
|
|
)
|
|
: Image.asset(
|
|
"assets/images/png/Ellipse 37 (1).png")),
|
|
),
|
|
),
|
|
Positioned(
|
|
bottom: 0,
|
|
right: 0,
|
|
child: InkWell(
|
|
onTap: () {
|
|
ImageUploadBottomSheet().showModal(
|
|
context,
|
|
true,
|
|
(result) {
|
|
editProfileImage
|
|
.usserprofilePicPath
|
|
.value = result;
|
|
var filenameresult =
|
|
extractFileName(result);
|
|
|
|
print(
|
|
"File name is $filenameresult");
|
|
|
|
profilePicture = result;
|
|
isImageAdded = true;
|
|
setState(() {});
|
|
},
|
|
);
|
|
},
|
|
child: Container(
|
|
height: 35.h,
|
|
width: 35.w,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Color(0xFFD90B2E)),
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/cameraicon2.png",
|
|
height: 19.h,
|
|
width: 19.w,
|
|
),
|
|
),
|
|
),
|
|
))
|
|
],
|
|
),
|
|
sizedBoxHeight(15.h),
|
|
text16400white("Edit profile picture"),
|
|
sizedBoxHeight(30.h),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
text16400white("Business name"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController: busNameController,
|
|
leadingIcon: SizedBox(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Frame 24.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Enter your business name",
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(
|
|
RegExp(r'[a-zA-Z0-9\s]')),
|
|
],
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Business username"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController:
|
|
busUserNameController,
|
|
leadingIcon: SizedBox(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Frame 24.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Enter your business username",
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(
|
|
RegExp(r'[a-zA-Z0-9\s]')),
|
|
],
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Owner name"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController: ownerNameController,
|
|
leadingIcon: SizedBox(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Frame 24.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Enter your owner name",
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(
|
|
RegExp(r'[a-zA-Z0-9\s]')),
|
|
],
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Founded on"),
|
|
sizedBoxHeight(16.h),
|
|
GestureDetector(
|
|
onTap: () => datePicker(
|
|
context, foundedonController),
|
|
child: AbsorbPointer(
|
|
child: CustomTextFormField(
|
|
leadingIcon: SizedBox(
|
|
width: 18.0,
|
|
height: 17.0,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/calender.png",
|
|
width: 18.0,
|
|
height: 17.0,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Select date",
|
|
textEditingController:
|
|
foundedonController,
|
|
),
|
|
),
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Website link"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController:
|
|
websiteLinkController,
|
|
leadingIcon: SizedBox(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Vector2a.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Enter your website link",
|
|
),
|
|
sizedBoxHeight(25.h),
|
|
Row(
|
|
children: [
|
|
text16400white("Location"),
|
|
sizedBoxWidth(6.w),
|
|
Image.asset(
|
|
"assets/images/png/octicon_question-24.png",
|
|
height: 16.h,
|
|
width: 16.w,
|
|
)
|
|
],
|
|
),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController: locationController,
|
|
leadingIcon: SizedBox(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Group 58645.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Enter your location",
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(
|
|
RegExp(r'[a-zA-Z0-9\s]')),
|
|
],
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Bio"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField2(
|
|
textEditingController: bioController,
|
|
hintText: "Enter your business bio",
|
|
maxlines: 3,
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.allow(
|
|
RegExp(r'[a-zA-Z0-9\s]')),
|
|
],
|
|
),
|
|
sizedBoxHeight(60.h),
|
|
CommonBtn(
|
|
text: "Save",
|
|
onTap: () {
|
|
saveEditProfileBus();
|
|
},
|
|
),
|
|
sizedBoxHeight(60.h),
|
|
],
|
|
)
|
|
])))
|
|
]);
|
|
}
|
|
return Container();
|
|
})),
|
|
);
|
|
}
|
|
}
|