|
@ -11,13 +11,11 @@ import '/views/main/friend/request_list_item.dart'; |
|
|
|
|
|
|
|
|
class FriendList extends StatefulWidget { |
|
|
class FriendList extends StatefulWidget { |
|
|
final List<Friend> friends; |
|
|
final List<Friend> friends; |
|
|
final List<Friend> friendRequests; |
|
|
|
|
|
final Function callback; |
|
|
final Function callback; |
|
|
|
|
|
|
|
|
const FriendList({ |
|
|
const FriendList({ |
|
|
Key? key, |
|
|
Key? key, |
|
|
required this.friends, |
|
|
required this.friends, |
|
|
required this.friendRequests, |
|
|
|
|
|
required this.callback, |
|
|
required this.callback, |
|
|
}) : super(key: key); |
|
|
}) : super(key: key); |
|
|
|
|
|
|
|
@ -26,11 +24,10 @@ class FriendList extends StatefulWidget { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class _FriendListState extends State<FriendList> { |
|
|
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> friendsDuplicate = []; |
|
|
List<Friend> friendRequestsDuplicate = []; |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
@override |
|
|
Widget build(BuildContext context) { |
|
|
Widget build(BuildContext context) { |
|
@ -46,31 +43,33 @@ class _FriendListState extends State<FriendList> { |
|
|
showBack: false, |
|
|
showBack: false, |
|
|
backgroundColor: Colors.transparent, |
|
|
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( |
|
|
floatingActionButton: Padding( |
|
|
padding: const EdgeInsets.only(right: 10, bottom: 10), |
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(right: 10, bottom: 60), |
|
|
child: ExpandableFab( |
|
|
child: ExpandableFab( |
|
|
icon: Icon( |
|
|
icon: Icon( |
|
|
Icons.add, |
|
|
Icons.add, |
|
@ -96,20 +95,17 @@ class _FriendListState extends State<FriendList> { |
|
|
icon: const Icon(Icons.search, size: 25), |
|
|
icon: const Icon(Icons.search, size: 25), |
|
|
), |
|
|
), |
|
|
], |
|
|
], |
|
|
) |
|
|
|
|
|
|
|
|
) |
|
|
) |
|
|
) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void filterSearchResults(String query) { |
|
|
void filterSearchResults(String query) { |
|
|
List<Friend> dummyFriendsList = []; |
|
|
List<Friend> dummyFriendsList = []; |
|
|
List<Friend> dummyFriendRequestsList = []; |
|
|
|
|
|
dummyFriendsList.addAll(friends); |
|
|
dummyFriendsList.addAll(friends); |
|
|
dummyFriendRequestsList.addAll(friendRequests); |
|
|
|
|
|
|
|
|
|
|
|
if (query.isNotEmpty) { |
|
|
if (query.isNotEmpty) { |
|
|
List<Friend> dummyFriendData = []; |
|
|
List<Friend> dummyFriendData = []; |
|
|
List<Friend> dummyFriendRequestData = []; |
|
|
|
|
|
|
|
|
|
|
|
for (Friend item in dummyFriendsList) { |
|
|
for (Friend item in dummyFriendsList) { |
|
|
if(item.username.toLowerCase().contains(query)) { |
|
|
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(() { |
|
|
setState(() { |
|
|
friends.clear(); |
|
|
friends.clear(); |
|
|
friends.addAll(dummyFriendData); |
|
|
friends.addAll(dummyFriendData); |
|
|
friendRequests.clear(); |
|
|
|
|
|
friendRequests.addAll(dummyFriendRequestData); |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
setState(() { |
|
|
setState(() { |
|
|
friends.clear(); |
|
|
friends.clear(); |
|
|
friends.addAll(widget.friends); |
|
|
friends.addAll(widget.friends); |
|
|
friendRequests.clear(); |
|
|
|
|
|
friendRequests.addAll(widget.friendRequests); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -145,23 +131,17 @@ class _FriendListState extends State<FriendList> { |
|
|
void initState() { |
|
|
void initState() { |
|
|
super.initState(); |
|
|
super.initState(); |
|
|
friends.addAll(widget.friends); |
|
|
friends.addAll(widget.friends); |
|
|
friendRequests.addAll(widget.friendRequests); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Future<void> initFriends() async { |
|
|
Future<void> initFriends() async { |
|
|
friends = await FriendsRepository.getFriends(accepted: true); |
|
|
|
|
|
friendRequests = await FriendsRepository.getFriends(accepted: false); |
|
|
|
|
|
|
|
|
friends = await FriendsRepository.getFriends(); |
|
|
setState(() {}); |
|
|
setState(() {}); |
|
|
widget.callback(); |
|
|
widget.callback(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
Widget headingOrNull(String heading) { |
|
|
|
|
|
if (friends.isEmpty || friendRequests.isEmpty) { |
|
|
|
|
|
return const SizedBox.shrink(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Widget _heading(String heading) { |
|
|
return Padding( |
|
|
return Padding( |
|
|
padding: const EdgeInsets.only(top: 16), |
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(top: 5, bottom: 10), |
|
|
child: Align( |
|
|
child: Align( |
|
|
alignment: Alignment.centerLeft, |
|
|
alignment: Alignment.centerLeft, |
|
|
child: Text( |
|
|
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) { |
|
|
if (friends.isEmpty) { |
|
|
return const Center( |
|
|
return const Center( |
|
|
child: Text('No Friends'), |
|
|
child: Text('No Friends'), |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return ListView.builder( |
|
|
|
|
|
|
|
|
return ListView.separated( |
|
|
itemCount: friends.length, |
|
|
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( |
|
|
return FriendListItem( |
|
|
friend: friends[i], |
|
|
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'); |
|
|
|
|
|
} |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |