671 lines
39 KiB
Dart
671 lines
39 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:regroup/Common/CommonWidget.dart';
|
|
import 'package:regroup/Common/base_manager.dart';
|
|
import 'package:regroup/Main_Screens/ProfileTab/Guest%20User/Model/GetGuestFollowing.dart';
|
|
import 'package:regroup/Main_Screens/ProfileTab/Guest%20User/ViewModel/GuestProfileApi.dart';
|
|
import 'package:regroup/Main_Screens/ProfileTab/Model/followingModel.dart';
|
|
import 'package:regroup/Main_Screens/ProfileTab/view_model/profileGetmethod.dart';
|
|
import 'package:regroup/Main_Screens/ProfileTab/view_model/profilePostmethod.dart';
|
|
|
|
import 'package:regroup/Utils/Common/CommonAppbar.dart';
|
|
import 'package:regroup/Utils/Common/CustomTextformfield.dart';
|
|
import 'package:regroup/Utils/Common/sized_box.dart';
|
|
import 'package:regroup/Utils/dialogs.dart';
|
|
import 'package:regroup/Utils/texts.dart';
|
|
import 'package:regroup/resources/routes/route_name.dart';
|
|
import 'package:remove_emoji_input_formatter/remove_emoji_input_formatter.dart';
|
|
|
|
class Following extends StatefulWidget {
|
|
const Following({super.key});
|
|
|
|
@override
|
|
State<Following> createState() => _FollowingState();
|
|
}
|
|
|
|
class _FollowingState extends State<Following> {
|
|
StreamController<FollowingModel> searchcontroller = StreamController();
|
|
StreamController<GetGuestFollowing> guestsearchcontroller =
|
|
StreamController();
|
|
|
|
var guestUserid = Get.arguments['UpdataGuestIdfollowing'] ?? '';
|
|
|
|
var fromBusFollowing = Get.arguments['From'] ?? '';
|
|
|
|
var guestBusUserid = Get.arguments['UpdataGuestBusIdfollowing'] ?? '';
|
|
|
|
var fromMainBusProfile = Get.arguments['From'] ?? '';
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
var updata = "";
|
|
if (fromMainBusProfile == 'MainBusProfile') {
|
|
Profilegetmethod()
|
|
.getFollowing(updata, streamController: searchcontroller);
|
|
}
|
|
|
|
var guestupdata = "";
|
|
if (fromBusFollowing == 'GuestBusFollowing') {
|
|
GuestProfileApi().getGuestfollowing(guestBusUserid, guestupdata,
|
|
streamController: guestsearchcontroller);
|
|
} else {
|
|
GuestProfileApi().getGuestfollowing(guestUserid, guestupdata,
|
|
streamController: guestsearchcontroller);
|
|
}
|
|
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
searchcontroller.close();
|
|
super.dispose();
|
|
}
|
|
|
|
Uploadata() async {
|
|
utils.loader();
|
|
Map<String, dynamic> updata = {
|
|
"following_iam_principal_xid": unfollowid,
|
|
};
|
|
final data = await Profilepostmethod().postunfollowuser(updata);
|
|
if (data.status == ResponseStatus.SUCCESS) {
|
|
Get.back();
|
|
print("unfollow done");
|
|
// setState(() {
|
|
// // Assuming followingobj is a list of items, remove the item with matching user ID
|
|
// followingobj!.data!.removeWhere((item) => item.following!.id == userid);
|
|
// });
|
|
return utils.showToast(data.message);
|
|
} else {
|
|
Get.back();
|
|
print("unfollow not done");
|
|
return utils.showToast(data.message);
|
|
}
|
|
}
|
|
|
|
int? unfollowid;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
// key: _scaffoldKey1,
|
|
backgroundColor: const Color(0xFF222935),
|
|
extendBody: true,
|
|
resizeToAvoidBottomInset: false,
|
|
appBar: const CommonAppbar(
|
|
titleTxt: "Following",
|
|
),
|
|
body: fromMainBusProfile == 'MainBusProfile'
|
|
? Stack(children: [
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage("assets/images/png/Ellipse 1496.png"),
|
|
fit: BoxFit.fill)),
|
|
),
|
|
SingleChildScrollView(
|
|
child: Column(children: [
|
|
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w),
|
|
child: CustomTextFormField(
|
|
leadingIcon: SizedBox(
|
|
height: 23,
|
|
width: 23,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/ion_search-outline.png",
|
|
height: 23,
|
|
width: 23,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Search people",
|
|
texttype: TextInputType.text,
|
|
inputFormatters: [
|
|
// LengthLimitingTextInputFormatter(20),
|
|
RemoveEmojiInputFormatter(),
|
|
],
|
|
onInput: (value) {
|
|
// Onboard().postGroupsearch({"search": value},
|
|
// streamController: searchcontroller);
|
|
// searchGroups(value!);
|
|
Profilegetmethod().getFollowing(value,
|
|
streamController: searchcontroller);
|
|
},
|
|
),
|
|
),
|
|
sizedBoxHeight(25.h),
|
|
StreamBuilder<FollowingModel>(
|
|
stream: searchcontroller.stream,
|
|
builder: (ctx, snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
// Display shimmer effect while waiting for data
|
|
return const Center(child: CircularProgressIndicator());
|
|
} else if (snapshot.hasError) {
|
|
// Handle error state
|
|
return Center(
|
|
child: Text(
|
|
'${snapshot.error} occurred',
|
|
style: const TextStyle(fontSize: 18),
|
|
),
|
|
);
|
|
} else {
|
|
// Data has been loaded, show actual UI
|
|
return followingobj!.data!.isEmpty
|
|
? _buildNoDataBody(context)
|
|
: ListView.separated(
|
|
physics: const ScrollPhysics(),
|
|
shrinkWrap: true,
|
|
itemCount: followingobj!.data!.length,
|
|
separatorBuilder:
|
|
(BuildContext context, int index) {
|
|
return commonDivider();
|
|
},
|
|
itemBuilder: (context, index) {
|
|
var mainFollowing =
|
|
followingobj!.data![index];
|
|
return
|
|
// Column(
|
|
// children: [
|
|
// Followinglist(
|
|
// imagePath: followingobj?.data?[index]
|
|
// .following?.profilePhoto ??
|
|
// '',
|
|
// title: followingobj!
|
|
// .data?[index].following?.fullName ??
|
|
// '',
|
|
// subtitle: followingobj!
|
|
// .data?[index].following?.userName ??
|
|
// '',
|
|
// unfollowontap: (id) => Uploadata(id),
|
|
// unfollowindex: followingobj!
|
|
// .data![index].following!.id!,
|
|
// ),
|
|
// if (index != followingobj!.data!.length - 1)
|
|
// commonDivider(),
|
|
// ],
|
|
// );
|
|
GestureDetector(
|
|
onTap: () {
|
|
mainFollowing.following!
|
|
.principleTypeXid ==
|
|
1
|
|
? Get.toNamed(
|
|
RouteName.profiletabindguest,
|
|
arguments: {
|
|
"FollowingidIndex": mainFollowing
|
|
.followingIamPrincipalXid!,
|
|
})
|
|
: Get.toNamed(
|
|
RouteName.profiletabbusguest,
|
|
arguments: {
|
|
"FollowingidIndex": mainFollowing
|
|
.followingIamPrincipalXid!,
|
|
});
|
|
},
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
vertical: 16.h, horizontal: 16.w),
|
|
child: Row(
|
|
children: [
|
|
mainFollowing.following!
|
|
.profilePhoto ==
|
|
null ||
|
|
mainFollowing.following!
|
|
.profilePhoto!.isEmpty
|
|
? CircleAvatar(
|
|
backgroundImage:
|
|
const AssetImage(
|
|
'assets/images/png/Ellipse 43.png'),
|
|
radius: 25.r,
|
|
)
|
|
: CircleAvatar(
|
|
backgroundImage:
|
|
NetworkImage(
|
|
mainFollowing
|
|
.following!
|
|
.profilePhoto!),
|
|
radius: 25.r,
|
|
),
|
|
sizedBoxWidth(10.w),
|
|
Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment.start,
|
|
children: [
|
|
mainFollowing.following!
|
|
.fullName ==
|
|
null ||
|
|
mainFollowing
|
|
.following!
|
|
.fullName!
|
|
.isEmpty
|
|
? text16w400_FCFCFC(
|
|
"Regroup")
|
|
: text16w400_FCFCFC(
|
|
mainFollowing
|
|
.following!
|
|
.fullName!),
|
|
sizedBoxHeight(4.h),
|
|
mainFollowing.following!
|
|
.userName ==
|
|
null ||
|
|
mainFollowing
|
|
.following!
|
|
.userName!
|
|
.isEmpty
|
|
? text12w400_FCFCFC_blur(
|
|
"regroup")
|
|
: text12w400_FCFCFC_blur(
|
|
mainFollowing
|
|
.following!
|
|
.userName!)
|
|
],
|
|
),
|
|
const Spacer(),
|
|
PopupMenuButton(
|
|
surfaceTintColor:
|
|
const Color(0xFF222935),
|
|
constraints:
|
|
BoxConstraints.tightFor(
|
|
width: 176.w),
|
|
offset: const Offset(0, 20),
|
|
color:
|
|
const Color(0xFF222935),
|
|
tooltip: "",
|
|
itemBuilder: (BuildContext
|
|
context) =>
|
|
<PopupMenuEntry>[
|
|
PopupMenuItem(
|
|
onTap: () async {
|
|
setState(() {
|
|
unfollowid =
|
|
mainFollowing
|
|
.following!
|
|
.id ??
|
|
0;
|
|
// followingobj!.data!.removeAt(index);
|
|
followingobj!
|
|
.data!
|
|
.removeWhere((item) =>
|
|
item.following!
|
|
.id ==
|
|
unfollowid);
|
|
Uploadata();
|
|
});
|
|
},
|
|
child: Padding(
|
|
padding: EdgeInsets
|
|
.symmetric(
|
|
horizontal:
|
|
12.w),
|
|
child: Row(
|
|
children: [
|
|
text14400white(
|
|
"Unfollow user"),
|
|
const Spacer(),
|
|
Image.asset(
|
|
"assets/images/png/Black1323e.png",
|
|
height: 20.h,
|
|
width: 20.w,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const PopupMenuDivider(),
|
|
PopupMenuItem(
|
|
onTap: () {},
|
|
child: Padding(
|
|
padding: EdgeInsets
|
|
.symmetric(
|
|
horizontal:
|
|
12.w),
|
|
child: Row(
|
|
children: [
|
|
text14400white(
|
|
"Message user"),
|
|
const Spacer(),
|
|
Image.asset(
|
|
"assets/images/png/fluent_chat-20-22.png",
|
|
height: 20.h,
|
|
width: 20.w,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
child: Container(
|
|
height: 20,
|
|
width: 20,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Group 1000004071.png",
|
|
height: 22.h,
|
|
width: 4.w,
|
|
),
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
},
|
|
),
|
|
])
|
|
]))
|
|
])
|
|
: Stack(
|
|
children: [
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
image: DecorationImage(
|
|
image:
|
|
AssetImage("assets/images/png/Ellipse 1496.png"),
|
|
fit: BoxFit.fill)),
|
|
),
|
|
SingleChildScrollView(
|
|
child: Column(children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16.w),
|
|
child: CustomTextFormField(
|
|
leadingIcon: SizedBox(
|
|
height: 23,
|
|
width: 23,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/ion_search-outline.png",
|
|
height: 23,
|
|
width: 23,
|
|
),
|
|
),
|
|
),
|
|
hintText: "Search people",
|
|
texttype: TextInputType.text,
|
|
inputFormatters: [
|
|
// LengthLimitingTextInputFormatter(20),
|
|
RemoveEmojiInputFormatter(),
|
|
],
|
|
onInput: (value) {
|
|
// GuestProfileApi().getGuestfollowing(guestUserid, value,
|
|
// streamController: guestsearchcontroller);
|
|
if (fromBusFollowing == 'GuestBusFollowing') {
|
|
GuestProfileApi().getGuestfollowing(
|
|
guestBusUserid, value,
|
|
streamController: guestsearchcontroller);
|
|
} else {
|
|
GuestProfileApi().getGuestfollowing(
|
|
guestUserid, value,
|
|
streamController: guestsearchcontroller);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
sizedBoxHeight(25.h),
|
|
StreamBuilder<GetGuestFollowing>(
|
|
stream: guestsearchcontroller.stream,
|
|
builder: (ctx, snapshot) {
|
|
if (snapshot.connectionState ==
|
|
ConnectionState.waiting) {
|
|
// Display shimmer effect while waiting for data
|
|
return const Center(
|
|
child: CircularProgressIndicator());
|
|
} else if (snapshot.hasError) {
|
|
// Handle error state
|
|
return Center(
|
|
child: Text(
|
|
'${snapshot.error} occurred',
|
|
style: const TextStyle(fontSize: 18),
|
|
),
|
|
);
|
|
} else {
|
|
// Data has been loaded, show actual UI
|
|
return getguestfollowingobj!.data!.isEmpty
|
|
? _buildNoDataBody(context)
|
|
: ListView.separated(
|
|
physics: const ScrollPhysics(),
|
|
shrinkWrap: true,
|
|
itemCount:
|
|
getguestfollowingobj!.data!.length,
|
|
separatorBuilder:
|
|
(BuildContext context, int index) {
|
|
return commonDivider();
|
|
},
|
|
itemBuilder: (context, index) {
|
|
var guestFollowing =
|
|
getguestfollowingobj!.data![index];
|
|
return GestureDetector(
|
|
onTap: () {
|
|
guestFollowing.following!
|
|
.principleTypeXid ==
|
|
1
|
|
? Get.toNamed(
|
|
RouteName
|
|
.profiletabindguest,
|
|
arguments: {
|
|
"FollowingidIndex":
|
|
guestFollowing
|
|
.followingIamPrincipalXid!,
|
|
})
|
|
: Get.toNamed(
|
|
RouteName
|
|
.profiletabbusguest,
|
|
arguments: {
|
|
"FollowingidIndex":
|
|
guestFollowing
|
|
.followingIamPrincipalXid!,
|
|
},
|
|
);
|
|
},
|
|
child: Column(
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
vertical: 16.h,
|
|
horizontal: 16.w),
|
|
child: Row(
|
|
children: [
|
|
guestFollowing.following!
|
|
.profilePhoto ==
|
|
null ||
|
|
guestFollowing
|
|
.following!
|
|
.profilePhoto!
|
|
.isEmpty
|
|
? CircleAvatar(
|
|
backgroundImage:
|
|
const AssetImage(
|
|
'assets/images/png/Ellipse 43.png'),
|
|
radius: 25.r,
|
|
)
|
|
: CircleAvatar(
|
|
backgroundImage:
|
|
NetworkImage(
|
|
guestFollowing
|
|
.following!
|
|
.profilePhoto!),
|
|
radius: 25.r,
|
|
),
|
|
sizedBoxWidth(10.w),
|
|
Column(
|
|
crossAxisAlignment:
|
|
CrossAxisAlignment
|
|
.start,
|
|
children: [
|
|
guestFollowing.following!
|
|
.fullName ==
|
|
null ||
|
|
guestFollowing
|
|
.following!
|
|
.fullName!
|
|
.isEmpty
|
|
? text16w400_FCFCFC(
|
|
"Regroup")
|
|
: text16w400_FCFCFC(
|
|
guestFollowing
|
|
.following!
|
|
.fullName!),
|
|
sizedBoxHeight(4.h),
|
|
guestFollowing.following!
|
|
.userName ==
|
|
null ||
|
|
guestFollowing
|
|
.following!
|
|
.userName!
|
|
.isEmpty
|
|
? text12w400_FCFCFC_blur(
|
|
"regroup")
|
|
: text12w400_FCFCFC_blur(
|
|
guestFollowing
|
|
.following!
|
|
.userName!)
|
|
],
|
|
),
|
|
const Spacer(),
|
|
PopupMenuButton(
|
|
surfaceTintColor:
|
|
const Color(
|
|
0xFF222935),
|
|
constraints:
|
|
BoxConstraints
|
|
.tightFor(
|
|
width:
|
|
176.w),
|
|
offset:
|
|
const Offset(0, 20),
|
|
color: const Color(
|
|
0xFF222935),
|
|
tooltip: "",
|
|
itemBuilder:
|
|
(BuildContext
|
|
context) =>
|
|
<PopupMenuEntry>[
|
|
PopupMenuItem(
|
|
onTap:
|
|
() async {
|
|
// setState(
|
|
// () {
|
|
// unfollowid =
|
|
// getguestfollowingobj!.data![index].following!.id ??
|
|
// 0;
|
|
// // followingobj!.data!.removeAt(index);
|
|
// getguestfollowingobj!.data!.removeWhere((item) =>
|
|
// item.following!.id ==
|
|
// unfollowid);
|
|
// Uploadata();
|
|
// });
|
|
},
|
|
child:
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal:
|
|
12.w),
|
|
child:
|
|
Row(
|
|
children: [
|
|
text14400white(
|
|
""),
|
|
const Spacer(),
|
|
Image
|
|
.asset(
|
|
"assets/images/png/Black1323e.png",
|
|
height:
|
|
20.h,
|
|
width:
|
|
20.w,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
const PopupMenuDivider(),
|
|
PopupMenuItem(
|
|
onTap:
|
|
() {},
|
|
child:
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal:
|
|
12.w),
|
|
child:
|
|
Row(
|
|
children: [
|
|
text14400white(
|
|
"Message user"),
|
|
const Spacer(),
|
|
Image
|
|
.asset(
|
|
"assets/images/png/fluent_chat-20-22.png",
|
|
height:
|
|
20.h,
|
|
width:
|
|
20.w,
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
child: Container(
|
|
height: 20,
|
|
width: 20,
|
|
child: Center(
|
|
child: Image.asset(
|
|
"assets/images/png/Group 1000004071.png",
|
|
height: 22.h,
|
|
width: 4.w,
|
|
),
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
},
|
|
),
|
|
])
|
|
]))
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildNoDataBody(context) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
"No Data Found",
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.w600),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|