edit community details completed and some fixes in main page and also fixes in communities page
This commit is contained in:
@@ -176,6 +176,7 @@ class ApiUrls {
|
||||
|
||||
static const geteditcommunity = "${baseUrl}edit-community";
|
||||
|
||||
static const posteditcommunity = "${baseUrl}update-community";
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
debugShowCheckedModeBanner: false,
|
||||
// initialRoute: RouteName.individualactivitystep2,
|
||||
|
||||
initialRoute: RouteName.individualactivitystep2,
|
||||
initialRoute: RouteName.splashScreen,
|
||||
|
||||
getPages: AppRoutes.appRoutes(),
|
||||
),
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dotted_border/dotted_border.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get.dart' hide MultipartFile, FormData;
|
||||
import 'package:regroup/Common/CommonGlassmorphism.dart';
|
||||
import 'package:regroup/Common/base_manager.dart';
|
||||
import 'package:regroup/Main_Screens/ProfileTab/EditProfile/Model/InterestModel.dart'
|
||||
@@ -20,8 +21,10 @@ import 'package:regroup/Utils/dialogs.dart';
|
||||
import 'package:regroup/Utils/texts.dart';
|
||||
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
|
||||
import 'package:regroup/sidemenu/Community/MyCommunity/view_model/getmethod.dart';
|
||||
import 'package:regroup/sidemenu/Community/MyCommunity/view_model/postmethod.dart';
|
||||
import 'package:regroup/sidemenu/Community/MyCommunity/view_model/primaryactivity.dart';
|
||||
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
class EditCommunity extends StatefulWidget {
|
||||
const EditCommunity({super.key});
|
||||
@@ -42,9 +45,6 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
@override
|
||||
void initState() {
|
||||
myfuture = Getcommunity().getCommunityeditpage(communityid);
|
||||
// communitynameController.text = 'Active alliance network';
|
||||
// descriptionController.text =
|
||||
// "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer .";
|
||||
|
||||
super.initState();
|
||||
}
|
||||
@@ -98,7 +98,11 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
List<primaryactlist.Data> activity = [];
|
||||
List<String> _activitydrop = [];
|
||||
|
||||
String? selectedActivityName;
|
||||
String? selectedActivityName = '';
|
||||
|
||||
bool isDataLoaded = false;
|
||||
|
||||
List<Map<String, dynamic>> _abilityMap = [];
|
||||
|
||||
Future<void> fetchActivitylist() async {
|
||||
PrimaryActivityListApi abilityListAPI = PrimaryActivityListApi();
|
||||
@@ -110,24 +114,50 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
activity = abilityModel!.data ?? [];
|
||||
_activitydrop =
|
||||
activity.map((platform) => platform.name.toString()).toList();
|
||||
_abilityMap = activity.map((platform) {
|
||||
return {
|
||||
"id": platform.id,
|
||||
"name": platform.name.toString(),
|
||||
};
|
||||
}).toList();
|
||||
});
|
||||
|
||||
// Ensure dropdown list updates after setting the initial value
|
||||
// Debugging log for _abilityMap
|
||||
print('Ability Map: $_abilityMap');
|
||||
|
||||
if (communityeditobj != null && communityeditobj!.data != null) {
|
||||
int abilitiesXids = communityeditobj!.data!.communityData!.activityXid!;
|
||||
selectedactivityid = abilitiesXids;
|
||||
|
||||
String? name = await getSelectedName(selectedactivityid!);
|
||||
setState(() {
|
||||
// Set the initial selected activity if data is available
|
||||
int activitiesXids =
|
||||
communityeditobj!.data!.communityData!.activityData!.id!;
|
||||
selectedactivityid = activitiesXids;
|
||||
selectedActivityName = activity
|
||||
.firstWhere((item) => item.id == activitiesXids,
|
||||
orElse: () => activity.first)
|
||||
.name;
|
||||
selectedActivityName = name ?? '';
|
||||
isactivityLoaded = true;
|
||||
isDataLoaded = true; // Mark data as loaded
|
||||
});
|
||||
log(activity.toString());
|
||||
} else {
|
||||
print('Failed to fetch abilities');
|
||||
|
||||
// Debugging log for selectedActivityName
|
||||
print('Selected activity ID is $selectedactivityid');
|
||||
print('Selected activity name is $selectedActivityName');
|
||||
}
|
||||
} else {
|
||||
print('Failed to fetch activities');
|
||||
setState(() {
|
||||
isDataLoaded = false; // Ensure loader is not hidden in case of error
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> getSelectedName(int selectedId) async {
|
||||
print('Searching for ID: $selectedId in _abilityMap');
|
||||
|
||||
for (Map<String, dynamic> ability in _abilityMap) {
|
||||
if (ability["id"] == selectedId) {
|
||||
print('Found ability: ${ability["name"]}');
|
||||
return ability["name"] as String;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
int? selectedactivityid;
|
||||
@@ -140,16 +170,86 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
print('Selected activity ID is $selectedactivityid');
|
||||
}
|
||||
|
||||
Uploadata() async {
|
||||
utils.loader();
|
||||
List<MultipartFile> bannermedialist = [];
|
||||
List<MultipartFile> profielpicturelist = [];
|
||||
MultipartFile? imageFile;
|
||||
|
||||
for (var file in bannerPath.where((file) => file != null)) {
|
||||
bannermedialist.add(
|
||||
await MultipartFile.fromFile(
|
||||
file!.path,
|
||||
filename: path.basename(file.path),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (filePath.isNotEmpty && filePath[0] != null) {
|
||||
var profileFile = filePath[0];
|
||||
if (profileFile!.path.isNotEmpty) {
|
||||
// Convert local file to MultipartFile
|
||||
imageFile = await MultipartFile.fromFile(
|
||||
profileFile.path,
|
||||
filename: path.basename(profileFile.path),
|
||||
);
|
||||
} else {
|
||||
// Handle case where file path is empty
|
||||
imageFile = await Helper.networkImageToMultipartFile(
|
||||
communityeditobj!.data!.communityData!.communityProfilePhoto!,
|
||||
);
|
||||
}
|
||||
} else if (communityeditobj!.data!.communityData!.communityProfilePhoto != null) {
|
||||
// Handle case where no file is provided, fallback to network image
|
||||
imageFile = await Helper.networkImageToMultipartFile(
|
||||
communityeditobj!.data!.communityData!.communityProfilePhoto!,
|
||||
);
|
||||
} else {
|
||||
// Handle case where no profile picture is provided
|
||||
print('No profile picture provided.');
|
||||
return;
|
||||
}
|
||||
|
||||
int communityTypeValue = _typeCommunityMap[_selectedtypecommunity] ?? 0;
|
||||
|
||||
FormData formdata = FormData.fromMap({
|
||||
"community_profile_photo": imageFile,
|
||||
"community_banner_image": bannermedialist[0],
|
||||
"community_name": communitynameController.text,
|
||||
"community_location": locationcontroller.text,
|
||||
"community_description": descriptionController.text,
|
||||
'community_type_xid': communityTypeValue,
|
||||
'activity_xid': selectedactivityid,
|
||||
'community_id': communityid,
|
||||
});
|
||||
print('updata is ${formdata.toString()}');
|
||||
log('log is ${formdata.toString()}');
|
||||
final data = await PostMethodCommunity().postEditcommunity(formdata);
|
||||
if (data.status == ResponseStatus.SUCCESS) {
|
||||
Get.back();
|
||||
print("community updated");
|
||||
// Get.toNamed(RouteName.mycommunity);
|
||||
Get.back();
|
||||
return utils.showToast(data.message);
|
||||
} else {
|
||||
Get.back();
|
||||
print("community not updated");
|
||||
return utils.showToast(data.message);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
return GestureDetector(
|
||||
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
|
||||
child: Scaffold(
|
||||
// key: _scaffoldKey1,
|
||||
backgroundColor: Color(0xFF222935),
|
||||
extendBody: true,
|
||||
appBar: CommonAppbar(
|
||||
titleTxt: "Edit community info",
|
||||
),
|
||||
resizeToAvoidBottomInset: false,
|
||||
resizeToAvoidBottomInset: true,
|
||||
body: FutureBuilder(
|
||||
future: myfuture,
|
||||
builder: (ctx, snapshot) {
|
||||
@@ -177,8 +277,8 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
}
|
||||
}
|
||||
if (!isBannerLoaded) {
|
||||
bannerimage =
|
||||
communityeditobj!.data!.communityData!.communityBannerImage!;
|
||||
bannerimage = communityeditobj!
|
||||
.data!.communityData!.communityBannerImage!;
|
||||
_loadBannerImage(); // Call only if not already loaded
|
||||
}
|
||||
communitynameController.text =
|
||||
@@ -189,20 +289,29 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
communityeditobj!.data!.communityData!.communityLocation!;
|
||||
websitelinkcontroller.text =
|
||||
communityeditobj!.data!.communityData!.communityDescription!;
|
||||
var communityType =
|
||||
communityeditobj!.data!.communityData!.communityTypeData!.name;
|
||||
var communityType = communityeditobj!
|
||||
.data!.communityData!.communityTypeData!.name;
|
||||
if (_selectedtypecommunity.isEmpty) {
|
||||
_selectedtypecommunity = communityType ?? 'Public';
|
||||
}
|
||||
if (!isactivityLoaded) {
|
||||
fetchActivitylist();
|
||||
}
|
||||
if (!isDataLoaded) {
|
||||
// Show a loader or a placeholder until data is fully loaded
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Color(0xFFC18948),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Stack(children: [
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage("assets/images/png/Ellipse 1496.png"),
|
||||
image:
|
||||
AssetImage("assets/images/png/Ellipse 1496.png"),
|
||||
fit: BoxFit.fill)),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
@@ -249,8 +358,8 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
.communityData!
|
||||
.communityProfilePhoto!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) {
|
||||
errorBuilder: (context, error,
|
||||
stackTrace) {
|
||||
// Error handling when image fails to load
|
||||
return Image.asset(
|
||||
"assets/images/png/Ellipse 37.png",
|
||||
@@ -297,7 +406,8 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
color: Color(0xFFD90B2E),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: Color(0xFFD90B2E), width: 0.5.w)),
|
||||
color: Color(0xFFD90B2E),
|
||||
width: 0.5.w)),
|
||||
child: Center(
|
||||
child: Image.asset(
|
||||
'assets/images/png/cameraicon.png',
|
||||
@@ -330,7 +440,8 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
width: double.infinity,
|
||||
height: 150.h,
|
||||
borderRadius: BorderRadius.circular(10.r),
|
||||
customWidget: bannerPath.isNotEmpty && isbannerAdded
|
||||
customWidget:
|
||||
bannerPath.isNotEmpty && isbannerAdded
|
||||
? Stack(
|
||||
children: [
|
||||
Image.file(
|
||||
@@ -338,33 +449,6 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
fit: BoxFit.cover,
|
||||
width: double.infinity,
|
||||
),
|
||||
// Positioned(
|
||||
// right: 5,
|
||||
// bottom: 5,
|
||||
// child: InkWell(
|
||||
// onTap: () {
|
||||
// setState(() {
|
||||
// bannerPath.clear();
|
||||
// isbannerAdded = false;
|
||||
// });
|
||||
// },
|
||||
// child: Container(
|
||||
// width: 27,
|
||||
// height: 27,
|
||||
// decoration: ShapeDecoration(
|
||||
// color: Color(0xFF7E7E7E),
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius:
|
||||
// BorderRadius.circular(5),
|
||||
// ),
|
||||
// ),
|
||||
// child: Icon(
|
||||
// Icons.delete_outline_outlined,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
)
|
||||
: GestureDetector(
|
||||
@@ -381,7 +465,8 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
int fileSizeInBytes =
|
||||
file.lengthSync();
|
||||
double fileSizeInMB =
|
||||
fileSizeInBytes / (1024 * 1024);
|
||||
fileSizeInBytes /
|
||||
(1024 * 1024);
|
||||
|
||||
if (fileSizeInMB > 10) {
|
||||
// Show toast message if the file size exceeds 10 MB
|
||||
@@ -407,8 +492,8 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 16.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 16.h),
|
||||
child: Column(
|
||||
children: [
|
||||
Image.asset(
|
||||
@@ -422,9 +507,11 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
SizedBox(height: 8.h),
|
||||
SizedBox(
|
||||
width: 270.w,
|
||||
child: Center(
|
||||
child: text8w400_8A8A8A(
|
||||
"Allowed file extensions: jpg, png, gif Max file size: 10 MB"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -439,8 +526,8 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
borderRadius: BorderRadius.circular(10.r),
|
||||
customWidget: Center(
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: 12.w),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12.w),
|
||||
child: Row(
|
||||
children: [
|
||||
// Conditionally render image or placeholder
|
||||
@@ -553,13 +640,13 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
text16w400_FCFCFC("Primary activity*"),
|
||||
sizedBoxHeight(14.h),
|
||||
CustomDropDownRadio(
|
||||
showOtherOption: true,
|
||||
showOtherOption: false,
|
||||
header: "",
|
||||
title: "",
|
||||
listData: _activitydrop,
|
||||
onItemSelected: getCatIdFromName,
|
||||
leadingImage: SizedBox(),
|
||||
initialSelectedValue: selectedActivityName.toString(),
|
||||
initialSelectedValue: selectedActivityName ?? '',
|
||||
),
|
||||
sizedBoxHeight(25.h),
|
||||
text16w400_FCFCFC("Website link"),
|
||||
@@ -576,7 +663,26 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
),
|
||||
sizedBoxHeight(25.h),
|
||||
sizedBoxHeight(50.h),
|
||||
CustomButton(text: 'Save changes', onPressed: () {}),
|
||||
CustomButton(
|
||||
text: 'Save changes',
|
||||
onPressed: () {
|
||||
if (bannerPath.isEmpty ||
|
||||
communitynameController.text.isEmpty ||
|
||||
_selectedtypecommunity.isEmpty ||
|
||||
locationcontroller.text.isEmpty ||
|
||||
selectedactivityid.isBlank!) {
|
||||
utils.showToast('Please fill all fields');
|
||||
}
|
||||
// else if (filePath.isEmpty) {
|
||||
// utils.showToast(
|
||||
// 'Please add community profile picture');
|
||||
// }
|
||||
else {
|
||||
print('done');
|
||||
|
||||
Uploadata();
|
||||
}
|
||||
}),
|
||||
sizedBoxHeight(50.h),
|
||||
],
|
||||
),
|
||||
@@ -585,6 +691,7 @@ class _EditCommunityState extends State<EditCommunity> {
|
||||
)
|
||||
]);
|
||||
},
|
||||
));
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,9 @@ class _AddGroupState extends State<AddGroup> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
return GestureDetector(
|
||||
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
|
||||
child: Scaffold(
|
||||
// key: _scaffoldKey1,
|
||||
backgroundColor: Color(0xFF222935),
|
||||
extendBody: true,
|
||||
@@ -296,7 +298,8 @@ class _AddGroupState extends State<AddGroup> {
|
||||
sizedBoxHeight(50.h),
|
||||
]),
|
||||
)
|
||||
]));
|
||||
])),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNoDataBody(context) {
|
||||
|
||||
@@ -160,7 +160,7 @@ class _NewCommunityState extends State<NewCommunity> {
|
||||
// key: _scaffoldKey1,
|
||||
backgroundColor: Color(0xFF222935),
|
||||
extendBody: true,
|
||||
resizeToAvoidBottomInset: false,
|
||||
resizeToAvoidBottomInset: true,
|
||||
appBar: CommonAppbar(
|
||||
titleTxt: "New community",
|
||||
),
|
||||
|
||||
@@ -425,7 +425,11 @@ class _CommunityDetailsState extends State<CommunityDetails> {
|
||||
sizedBoxHeight(20.h),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Get.toNamed(RouteName.addgroup);
|
||||
// Get.toNamed(RouteName.addgroup);
|
||||
Get.toNamed(RouteName.group, arguments: {
|
||||
'id': CommunityId,
|
||||
'iscommunity': true,
|
||||
});
|
||||
},
|
||||
child: commonGlassUI(
|
||||
width: double.infinity,
|
||||
|
||||
@@ -15,4 +15,15 @@ class PostMethodCommunity {
|
||||
print("response message is ${response.message}");
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<ResponseData<dynamic>> postEditcommunity(updata) async {
|
||||
print("updata is $updata");
|
||||
final response = await NetworkApiServices().postApi(
|
||||
updata,
|
||||
ApiUrls.posteditcommunity,
|
||||
);
|
||||
print("response is ${response.data}");
|
||||
print("response message is ${response.message}");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user