|
|
@ -11,13 +11,11 @@ import '/views/main/friend/request_list_item.dart'; |
|
|
|
|
|
|
|
class FriendList extends StatefulWidget { |
|
|
|
final List<Friend> friends; |
|
|
|
final List<Friend> friendRequests; |
|
|
|
final Function callback; |
|
|
|
|
|
|
|
const FriendList({ |
|
|
|
Key? key, |
|
|
|
required this.friends, |
|
|
|
required this.friendRequests, |
|
|
|
required this.callback, |
|
|
|
}) : super(key: key); |
|
|
|
|
|
|
@ -26,11 +24,10 @@ class FriendList extends StatefulWidget { |
|
|
|
} |
|
|
|
|
|
|
|
class _FriendListState extends State<FriendList> { |
|
|
|
List<Friend> friends = []; |
|
|
|
List<Friend> friendRequests = []; |
|
|
|
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>(); |
|
|
|
|
|
|
|
List<Friend> friends = []; |
|
|
|
List<Friend> friendsDuplicate = []; |
|
|
|
List<Friend> friendRequestsDuplicate = []; |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
@ -46,31 +43,33 @@ class _FriendListState extends State<FriendList> { |
|
|
|
showBack: false, |
|
|
|
backgroundColor: Colors.transparent, |
|
|
|
), |
|
|
|
body: Padding( |
|
|
|
padding: const EdgeInsets.only(top: 16,left: 16,right: 16), |
|
|
|
child: SingleChildScrollView( |
|
|
|
child: Column( |
|
|
|
children: <Widget>[ |
|
|
|
TextField( |
|
|
|
decoration: const InputDecoration( |
|
|
|
hintText: 'Search...', |
|
|
|
prefixIcon: Icon( |
|
|
|
Icons.search, |
|
|
|
size: 20 |
|
|
|
), |
|
|
|
), |
|
|
|
onChanged: (value) => filterSearchResults(value.toLowerCase()) |
|
|
|
), |
|
|
|
headingOrNull('Friend Requests'), |
|
|
|
friendRequestList(), |
|
|
|
headingOrNull('Friends'), |
|
|
|
friendList(), |
|
|
|
body: Padding( |
|
|
|
padding: const EdgeInsets.only(top: 16,left: 16,right: 16, bottom: 65), |
|
|
|
child: Stack( |
|
|
|
children: <Widget>[ |
|
|
|
Padding( |
|
|
|
padding: const EdgeInsets.only(top: 50), |
|
|
|
child: RefreshIndicator( |
|
|
|
key: _refreshIndicatorKey, |
|
|
|
onRefresh: _refresh, |
|
|
|
child: list(), |
|
|
|
) |
|
|
|
), |
|
|
|
TextField( |
|
|
|
decoration: const InputDecoration( |
|
|
|
hintText: 'Search...', |
|
|
|
prefixIcon: Icon( |
|
|
|
Icons.search, |
|
|
|
size: 20 |
|
|
|
), |
|
|
|
), |
|
|
|
onChanged: (value) => filterSearchResults(value.toLowerCase()) |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
floatingActionButton: Padding( |
|
|
|
padding: const EdgeInsets.only(right: 10, bottom: 10), |
|
|
|
padding: const EdgeInsets.only(right: 10, bottom: 60), |
|
|
|
child: ExpandableFab( |
|
|
|
icon: Icon( |
|
|
|
Icons.add, |
|
|
@ -96,20 +95,17 @@ class _FriendListState extends State<FriendList> { |
|
|
|
icon: const Icon(Icons.search, size: 25), |
|
|
|
), |
|
|
|
], |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
void filterSearchResults(String query) { |
|
|
|
List<Friend> dummyFriendsList = []; |
|
|
|
List<Friend> dummyFriendRequestsList = []; |
|
|
|
dummyFriendsList.addAll(friends); |
|
|
|
dummyFriendRequestsList.addAll(friendRequests); |
|
|
|
|
|
|
|
if (query.isNotEmpty) { |
|
|
|
List<Friend> dummyFriendData = []; |
|
|
|
List<Friend> dummyFriendRequestData = []; |
|
|
|
|
|
|
|
for (Friend item in dummyFriendsList) { |
|
|
|
if(item.username.toLowerCase().contains(query)) { |
|
|
@ -117,27 +113,17 @@ class _FriendListState extends State<FriendList> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
for (Friend item in dummyFriendRequestsList) { |
|
|
|
if(item.username.toLowerCase().contains(query)) { |
|
|
|
dummyFriendRequestData.add(item); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setState(() { |
|
|
|
friends.clear(); |
|
|
|
friends.addAll(dummyFriendData); |
|
|
|
friendRequests.clear(); |
|
|
|
friendRequests.addAll(dummyFriendRequestData); |
|
|
|
}); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
setState(() { |
|
|
|
friends.clear(); |
|
|
|
friends.addAll(widget.friends); |
|
|
|
friendRequests.clear(); |
|
|
|
friendRequests.addAll(widget.friendRequests); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@ -145,23 +131,17 @@ class _FriendListState extends State<FriendList> { |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
friends.addAll(widget.friends); |
|
|
|
friendRequests.addAll(widget.friendRequests); |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> initFriends() async { |
|
|
|
friends = await FriendsRepository.getFriends(accepted: true); |
|
|
|
friendRequests = await FriendsRepository.getFriends(accepted: false); |
|
|
|
friends = await FriendsRepository.getFriends(); |
|
|
|
setState(() {}); |
|
|
|
widget.callback(); |
|
|
|
} |
|
|
|
|
|
|
|
Widget headingOrNull(String heading) { |
|
|
|
if (friends.isEmpty || friendRequests.isEmpty) { |
|
|
|
return const SizedBox.shrink(); |
|
|
|
} |
|
|
|
|
|
|
|
Widget _heading(String heading) { |
|
|
|
return Padding( |
|
|
|
padding: const EdgeInsets.only(top: 16), |
|
|
|
padding: const EdgeInsets.only(top: 5, bottom: 10), |
|
|
|
child: Align( |
|
|
|
alignment: Alignment.centerLeft, |
|
|
|
child: Text( |
|
|
@ -175,42 +155,50 @@ class _FriendListState extends State<FriendList> { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget friendRequestList() { |
|
|
|
if (friendRequests.isEmpty) { |
|
|
|
return const SizedBox.shrink(); |
|
|
|
} |
|
|
|
|
|
|
|
return ListView.builder( |
|
|
|
itemCount: friendRequests.length, |
|
|
|
shrinkWrap: true, |
|
|
|
padding: const EdgeInsets.only(top: 16), |
|
|
|
physics: const NeverScrollableScrollPhysics(), |
|
|
|
itemBuilder: (context, i) { |
|
|
|
return FriendRequestListItem( |
|
|
|
friend: friendRequests[i], |
|
|
|
callback: initFriends, |
|
|
|
); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Widget friendList() { |
|
|
|
Widget list() { |
|
|
|
if (friends.isEmpty) { |
|
|
|
return const Center( |
|
|
|
child: Text('No Friends'), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return ListView.builder( |
|
|
|
return ListView.separated( |
|
|
|
itemCount: friends.length, |
|
|
|
shrinkWrap: true, |
|
|
|
padding: const EdgeInsets.only(top: 16), |
|
|
|
physics: const NeverScrollableScrollPhysics(), |
|
|
|
itemBuilder: (context, i) { |
|
|
|
shrinkWrap: false, |
|
|
|
physics: const AlwaysScrollableScrollPhysics(), |
|
|
|
padding: const EdgeInsets.only(top: 10), |
|
|
|
separatorBuilder: (context, i) { |
|
|
|
if (friends[i].acceptedAt == null) { |
|
|
|
return FriendRequestListItem( |
|
|
|
friend: friends[i], |
|
|
|
callback: initFriends, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return FriendListItem( |
|
|
|
friend: friends[i], |
|
|
|
); |
|
|
|
}, |
|
|
|
itemBuilder: (context, i) { |
|
|
|
if (i == 0 && friends[i].acceptedAt == null) { |
|
|
|
return _heading('Friend Requests'); |
|
|
|
} |
|
|
|
|
|
|
|
if ((i == 0 || friends[i - 1].acceptedAt == null) && friends[i].acceptedAt != null) { |
|
|
|
return _heading('Friends'); |
|
|
|
} |
|
|
|
|
|
|
|
return const SizedBox.shrink(); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
Future<void> _refresh() async { |
|
|
|
Future.delayed( |
|
|
|
const Duration(seconds: 1), |
|
|
|
() { |
|
|
|
print('Doing thing'); |
|
|
|
} |
|
|
|
); |
|
|
|
} |
|
|
|
} |