Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
5.8 KiB

  1. import 'package:flutter/material.dart';
  2. import '/models/friends.dart';
  3. import '/views/main/friend_list_item.dart';
  4. class FriendList extends StatefulWidget {
  5. const FriendList({Key? key}) : super(key: key);
  6. @override
  7. State<FriendList> createState() => _FriendListState();
  8. }
  9. class _FriendListState extends State<FriendList> {
  10. List<Friend> friends = [];
  11. @override
  12. void initState() {
  13. super.initState();
  14. fetchFriends();
  15. }
  16. void fetchFriends() async {
  17. friends = await getFriends();
  18. setState(() {});
  19. }
  20. Widget list() {
  21. if (friends.isEmpty) {
  22. return const Center(
  23. child: Text('No Friends'),
  24. );
  25. }
  26. return ListView.builder(
  27. itemCount: friends.length,
  28. shrinkWrap: true,
  29. padding: const EdgeInsets.only(top: 16),
  30. physics: const NeverScrollableScrollPhysics(),
  31. itemBuilder: (context, i) {
  32. return FriendListItem(
  33. id: friends[i].id,
  34. username: friends[i].username!,
  35. );
  36. },
  37. );
  38. }
  39. @override
  40. Widget build(BuildContext context) {
  41. return Scaffold(
  42. body: SingleChildScrollView(
  43. physics: const BouncingScrollPhysics(),
  44. child: Column(
  45. crossAxisAlignment: CrossAxisAlignment.start,
  46. children: <Widget>[
  47. SafeArea(
  48. child: Padding(
  49. padding: const EdgeInsets.only(left: 16,right: 16,top: 10),
  50. child: Row(
  51. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  52. children: <Widget>[
  53. const Text("Friends",style: TextStyle(fontSize: 32,fontWeight: FontWeight.bold),),
  54. Container(
  55. padding: const EdgeInsets.only(left: 8,right: 8,top: 2,bottom: 2),
  56. height: 30,
  57. decoration: BoxDecoration(
  58. borderRadius: BorderRadius.circular(30),
  59. color: Colors.pink[50],
  60. ),
  61. child: Row(
  62. children: const <Widget>[
  63. Icon(Icons.add,color: Colors.pink,size: 20,),
  64. SizedBox(width: 2,),
  65. Text("Add",style: TextStyle(fontSize: 14,fontWeight: FontWeight.bold),),
  66. ],
  67. ),
  68. )
  69. ],
  70. ),
  71. ),
  72. ),
  73. Padding(
  74. padding: const EdgeInsets.only(top: 16,left: 16,right: 16),
  75. child: TextField(
  76. decoration: InputDecoration(
  77. hintText: "Search...",
  78. hintStyle: TextStyle(color: Colors.grey.shade600),
  79. prefixIcon: Icon(Icons.search,color: Colors.grey.shade600, size: 20,),
  80. filled: true,
  81. fillColor: Colors.grey.shade100,
  82. contentPadding: const EdgeInsets.all(8),
  83. enabledBorder: OutlineInputBorder(
  84. borderRadius: BorderRadius.circular(20),
  85. borderSide: BorderSide(
  86. color: Colors.grey.shade100
  87. )
  88. ),
  89. ),
  90. ),
  91. ),
  92. Padding(
  93. padding: const EdgeInsets.only(top: 16,left: 16,right: 16),
  94. child: list(),
  95. ),
  96. ],
  97. ),
  98. ),
  99. );
  100. }
  101. }