@@ -22,6 +22,8 @@ class ProfileHeader extends StatelessWidget {
2222 Widget build (BuildContext context) {
2323 return BlocBuilder <ProfileBloc , ProfileState >(
2424 builder: (context, state) {
25+ // Follow Notifier
26+ final _followNotifier = ValueNotifier (state.isFollowing);
2527 return Container (
2628 color: AppColors .primary,
2729 child: Column (
@@ -192,18 +194,39 @@ class ProfileHeader extends StatelessWidget {
192194 vertical: 8. h,
193195 horizontal: 16. w,
194196 ),
195- child: Visibility (
196- visible: state.isFollowing,
197- replacement: FollowButton (
198- onTap: () {
199- // TODO(aman-singh7): Implement follow
200- },
201- ),
202- child: FollowingButton (
203- onTap: () {
204- // TODO(aman-singh7): Implement unfollow
205- },
206- ),
197+ child: ValueListenableBuilder <bool >(
198+ valueListenable: _followNotifier,
199+ builder: (_, value, child) {
200+ if (value) {
201+ return FollowingButton (
202+ onTap: () async {
203+ try {
204+ await context
205+ .read <ProfileBloc >()
206+ .unfollow (state.user! .id! );
207+ _followNotifier.value = false ;
208+ } on Exception catch (_) {
209+ showSnackBar (
210+ message: AppStrings .genericError);
211+ }
212+ },
213+ );
214+ }
215+
216+ return FollowButton (
217+ onTap: () async {
218+ try {
219+ await context
220+ .read <ProfileBloc >()
221+ .follow (state.user! .id! );
222+ _followNotifier.value = true ;
223+ } on Exception catch (_) {
224+ showSnackBar (
225+ message: AppStrings .genericError);
226+ }
227+ },
228+ );
229+ },
207230 ),
208231 ),
209232 ],
0 commit comments