|
1 | 1 | import 'package:flutter/material.dart';
|
2 | 2 | import 'package:flutter_twitter_clone/helper/constant.dart';
|
3 | 3 | import 'package:flutter_twitter_clone/helper/theme.dart';
|
4 |
| -import 'package:flutter_twitter_clone/helper/utility.dart'; |
5 | 4 | import 'package:flutter_twitter_clone/model/user.dart';
|
| 5 | +import 'package:flutter_twitter_clone/state/authState.dart'; |
| 6 | +import 'package:flutter_twitter_clone/state/feedState.dart'; |
6 | 7 | import 'package:flutter_twitter_clone/state/notificationState.dart';
|
7 | 8 | import 'package:flutter_twitter_clone/widgets/customWidgets.dart';
|
8 | 9 | import 'package:flutter_twitter_clone/widgets/newWidget/customUrlText.dart';
|
9 | 10 | import 'package:flutter_twitter_clone/widgets/newWidget/emptyList.dart';
|
10 | 11 | import 'package:flutter_twitter_clone/widgets/newWidget/rippleButton.dart';
|
11 |
| -import 'package:flutter_twitter_clone/widgets/newWidget/title_text.dart'; |
12 | 12 | import 'package:provider/provider.dart';
|
13 | 13 |
|
14 | 14 | class UserListWidget extends StatelessWidget {
|
15 | 15 | final List<String> list;
|
16 | 16 | final fetchingListbool;
|
17 | 17 | final String emptyScreenText;
|
18 | 18 | final String emptyScreenSubTileText;
|
19 |
| - final bool isFollowing; |
20 |
| - const UserListWidget( |
| 19 | + String myId; |
| 20 | + UserListWidget( |
21 | 21 | {Key key,
|
22 | 22 | this.list,
|
23 | 23 | this.emptyScreenText,
|
24 |
| - this.isFollowing = false, |
25 | 24 | this.fetchingListbool,
|
26 | 25 | this.emptyScreenSubTileText})
|
27 | 26 | : super(key: key);
|
28 | 27 | Widget _userTile(BuildContext context, User user) {
|
| 28 | + bool isFollow = isFollowing(user); |
29 | 29 | return Container(
|
30 | 30 | padding: EdgeInsets.symmetric(vertical: 10),
|
31 | 31 | color: TwitterColor.white,
|
@@ -70,19 +70,18 @@ class UserListWidget extends StatelessWidget {
|
70 | 70 | borderRadius: BorderRadius.circular(25),
|
71 | 71 | child: Container(
|
72 | 72 | padding: EdgeInsets.symmetric(
|
73 |
| - horizontal: isFollowing ? 15 : 20, vertical: 3), |
| 73 | + horizontal: isFollow ? 15 : 20, vertical: 3), |
74 | 74 | decoration: BoxDecoration(
|
75 |
| - color: isFollowing |
76 |
| - ? TwitterColor.dodgetBlue |
77 |
| - : TwitterColor.white, |
| 75 | + color: |
| 76 | + isFollow ? TwitterColor.dodgetBlue : TwitterColor.white, |
78 | 77 | border:
|
79 | 78 | Border.all(color: TwitterColor.dodgetBlue, width: 1),
|
80 | 79 | borderRadius: BorderRadius.circular(25),
|
81 | 80 | ),
|
82 | 81 | child: Text(
|
83 |
| - isFollowing ? 'Following' : 'Follow', |
| 82 | + isFollow ? 'Following' : 'Follow', |
84 | 83 | style: TextStyle(
|
85 |
| - color: isFollowing ? TwitterColor.white : Colors.blue, |
| 84 | + color: isFollow ? TwitterColor.white : Colors.blue, |
86 | 85 | fontSize: 17,
|
87 | 86 | fontWeight: FontWeight.bold),
|
88 | 87 | ),
|
@@ -110,17 +109,27 @@ class UserListWidget extends StatelessWidget {
|
110 | 109 | return bio;
|
111 | 110 | }
|
112 | 111 | }
|
113 |
| - return null; |
| 112 | + return null; |
| 113 | + } |
| 114 | + |
| 115 | + bool isFollowing(User model) { |
| 116 | + if (model.followersList != null && |
| 117 | + model.followersList.any((x) => x == myId)) { |
| 118 | + return true; |
| 119 | + } else { |
| 120 | + return false; |
| 121 | + } |
114 | 122 | }
|
115 | 123 |
|
116 | 124 | @override
|
117 | 125 | Widget build(BuildContext context) {
|
118 |
| - var notificationState = Provider.of<NotificationState>(context); |
| 126 | + var state = Provider.of<AuthState>(context, listen: false); |
| 127 | + myId = state.userModel.key; |
119 | 128 | return list != null && list.isNotEmpty
|
120 | 129 | ? ListView.separated(
|
121 | 130 | itemBuilder: (context, index) {
|
122 | 131 | return FutureBuilder(
|
123 |
| - future: notificationState.getuserDetail(list[index]), |
| 132 | + future: state.getuserDetail(list[index]), |
124 | 133 | builder: (context, AsyncSnapshot<User> snapshot) {
|
125 | 134 | if (snapshot.hasData) {
|
126 | 135 | return _userTile(context, snapshot.data);
|
|
0 commit comments