424 lines
19 KiB
Dart
424 lines
19 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:dio/dio.dart';
|
|
import 'package:flutter/material.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/Feed%20Module/Main_Screens/ProfileTab/EditProfile/View/ProfileTab.dart';
|
|
import 'package:regroup/Feed%20Module/Main_Screens/ProfileTab/EditProfile/ViewModel/EditProfileApi.dart';
|
|
import 'package:regroup/Utils/Common/CommonAppbar.dart';
|
|
import 'package:regroup/Utils/Common/CommonDropdown.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 data not there
|
|
|
|
setValues() {
|
|
if (isOnce) {
|
|
busNameController.text = getEditProfileBus!.data!.businessName ?? '';
|
|
busUserNameController.text = getEditProfileBus!.data!.businessName ?? '';
|
|
ownerNameController.text =
|
|
getEditProfileBus!.data!.businessOwnerName ?? '';
|
|
foundedonController.text =
|
|
getEditProfileBus!.data!.businessOwnerName ?? '';
|
|
websiteLinkController.text = getEditProfileBus!.data!.websiteLink ?? '';
|
|
locationController.text = getEditProfileBus!.data!.businessLocation ?? '';
|
|
|
|
bioController.text = getEditProfileBus!.data!.businessOwnerName ?? '';
|
|
|
|
// _selectedgenderType = getEditProfileIndi!.data!.gender ?? '';
|
|
// _selectedsportType = getEditProfileIndi!.data!.interest!.join(', ') ?? '';
|
|
|
|
isOnce = false;
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
void saveEditProfileBus() async {
|
|
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 {
|
|
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": await convertFileToMultiPart(profilePicture),
|
|
});
|
|
|
|
final data = await EditProfileApi().postEditProfileBusiness(updata);
|
|
if (data.status == ResponseStatus.SUCCESS) {
|
|
// 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.profiletab);
|
|
// Get.back(result: true);
|
|
} else {
|
|
// btnController.reset();
|
|
Get.snackbar(
|
|
"Error!",
|
|
data.data['message'],
|
|
duration: Duration(seconds: 2),
|
|
colorText: Colors.white,
|
|
backgroundColor: Colors.red,
|
|
margin: EdgeInsets.all(8),
|
|
snackStyle: SnackStyle.FLOATING,
|
|
snackPosition: SnackPosition.BOTTOM,
|
|
);
|
|
// _controller.isTextFieldEnabled.value = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
// key: _scaffoldKey1,
|
|
backgroundColor: Color(0xFF222935),
|
|
extendBody: true,
|
|
appBar: CommonAppbar(
|
|
titleTxt: "",
|
|
),
|
|
body: FutureBuilder(
|
|
future: myfuture,
|
|
builder: (ctx, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
return 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: [
|
|
profilePicture != "" && isImageAdded
|
|
? ClipOval(
|
|
child: SizedBox.fromSize(
|
|
size: Size.fromRadius(50.r),
|
|
child: Image.file(
|
|
File(profilePicture),
|
|
// filePath[0]!,
|
|
fit: BoxFit.cover,
|
|
width: double.infinity,
|
|
),
|
|
),
|
|
)
|
|
: getEditProfileBus!.data!.businessLogo !=
|
|
null
|
|
? Container(
|
|
width: 100.w,
|
|
height: 100.h,
|
|
decoration: ShapeDecoration(
|
|
image: DecorationImage(
|
|
image: Image(
|
|
image: NetworkImage(
|
|
getEditProfileBus!.data!
|
|
.businessLogo ??
|
|
''),
|
|
).image,
|
|
fit: BoxFit.cover,
|
|
),
|
|
shape: OvalBorder(),
|
|
),
|
|
)
|
|
: CircleAvatar(
|
|
backgroundImage: AssetImage(
|
|
"assets/images/png/Ellipse 37 (1).png",
|
|
),
|
|
radius: 50.r,
|
|
),
|
|
Positioned(
|
|
bottom: 0,
|
|
right: 0,
|
|
child: InkWell(
|
|
onTap: () {
|
|
ImageUploadBottomSheet().showModal(
|
|
context,
|
|
true,
|
|
(result) {
|
|
var filenameresult =
|
|
extractFileName(result);
|
|
|
|
profilePicture = result;
|
|
isImageAdded = true;
|
|
setState(() {});
|
|
},
|
|
);
|
|
},
|
|
child: Container(
|
|
height: 35.h,
|
|
width: 35.w,
|
|
decoration: 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: Container(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Frame 24.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Victory gear sports emporium",
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Business username"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController: busUserNameController,
|
|
leadingIcon: Container(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Frame 24.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "victorygames _10",
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Owner name"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController: ownerNameController,
|
|
leadingIcon: Container(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Frame 24.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "James Bothman",
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Founded on"),
|
|
sizedBoxHeight(16.h),
|
|
GestureDetector(
|
|
onTap: () =>
|
|
datePicker(context, foundedonController),
|
|
child: AbsorbPointer(
|
|
child: CustomTextFormField(
|
|
leadingIcon: Container(
|
|
width: 18.0,
|
|
height: 17.0,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/calender.png",
|
|
width: 18.0,
|
|
height: 17.0,
|
|
),
|
|
),
|
|
),
|
|
hintText: "12-04-2024",
|
|
textEditingController:
|
|
foundedonController,
|
|
),
|
|
),
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Website link"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField(
|
|
textEditingController: websiteLinkController,
|
|
leadingIcon: Container(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Vector2a.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "victorygames _10",
|
|
),
|
|
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: Container(
|
|
width: 18.w,
|
|
height: 17.h,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Group 58645.png",
|
|
width: 18.w,
|
|
height: 17.h,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Elm street london, United Kingdom",
|
|
),
|
|
sizedBoxHeight(20.h),
|
|
text16400white("Bio"),
|
|
sizedBoxHeight(16.h),
|
|
CustomTextFormField2(
|
|
textEditingController: bioController,
|
|
hintText:
|
|
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s. Lorem Ipsum has been the industry's standard",
|
|
maxlines: 3,
|
|
),
|
|
sizedBoxHeight(60.h),
|
|
CommonBtn(
|
|
text: "Save",
|
|
onTap: () {
|
|
saveEditProfileBus();
|
|
},
|
|
),
|
|
sizedBoxHeight(60.h),
|
|
],
|
|
)
|
|
])))
|
|
]);
|
|
}
|
|
return Container();
|
|
}));
|
|
}
|
|
}
|