FriendList.dart 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import 'package:douyin_demo/providers/AtUserProvider.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:sticky_headers/sticky_headers.dart';
  5. class AtFriendPage extends StatelessWidget {
  6. const AtFriendPage({Key? key}) : super(key: key);
  7. @override
  8. Widget build(BuildContext context) {
  9. ScrollController controller = ScrollController();
  10. double rpx = MediaQuery.of(context).size.width / 750;
  11. AtUserProvider provider = Provider.of<AtUserProvider>(context);
  12. List<String> groupList = provider.groupList;
  13. return provider != null
  14. ? Scaffold(
  15. backgroundColor: Color(0xff121319),
  16. appBar: AppBar(
  17. backgroundColor: Color(0xff121319),
  18. leading: Container(
  19. width: 80 * rpx,
  20. child: IconButton(
  21. icon: Icon(Icons.close),
  22. onPressed: () {
  23. Navigator.pop(context);
  24. },
  25. )),
  26. title: Text("@好友"),
  27. bottom: PreferredSize(
  28. preferredSize: Size.fromHeight(80 * rpx),
  29. child: Container(
  30. margin: EdgeInsets.symmetric(horizontal: 30 * rpx),
  31. decoration: BoxDecoration(color: Color(0xff2a2b33)),
  32. padding: EdgeInsets.symmetric(horizontal: 20 * rpx),
  33. child: TextField(
  34. decoration: InputDecoration(
  35. icon: Icon(
  36. Icons.search,
  37. color: Colors.grey[500],
  38. ),
  39. hintText: "搜索用户备注或名字",
  40. hintStyle: TextStyle(
  41. color: Colors.grey[500],
  42. )),
  43. ),
  44. ),
  45. )),
  46. body: ListView.builder(
  47. shrinkWrap: true,
  48. controller: controller,
  49. itemCount: groupList.length,
  50. itemBuilder: (BuildContext context, int index) {
  51. return StickyHeader(
  52. header: Container(
  53. width: MediaQuery.of(context).size.width,
  54. padding: EdgeInsets.only(left: 20 * rpx),
  55. height: 50,
  56. decoration: BoxDecoration(color: Color(0xff121319)),
  57. alignment: Alignment.centerLeft,
  58. child: Text(
  59. groupList[index].toString(),
  60. style: TextStyle(color: Colors.white, fontSize: 35 * rpx),
  61. ),
  62. ),
  63. content: genContentList(
  64. provider.result[provider.groupList[index]]!,
  65. context,
  66. controller),
  67. );
  68. },
  69. ),
  70. )
  71. : Scaffold();
  72. }
  73. }
  74. genUserList(context, controller) {
  75. AtUserProvider provider = Provider.of<AtUserProvider>(context);
  76. List<String> groupList = provider.groupList;
  77. return ListView.builder(
  78. shrinkWrap: true,
  79. controller: controller,
  80. itemCount: groupList.length,
  81. itemBuilder: (BuildContext context, int index) {
  82. return StickyHeader(
  83. header: Container(
  84. width: MediaQuery.of(context).size.width,
  85. height: 50,
  86. decoration: BoxDecoration(color: Colors.black),
  87. child: Text(
  88. groupList[index].toString(),
  89. style: TextStyle(color: Colors.white, fontSize: 20),
  90. ),
  91. ),
  92. content: genContentList(
  93. provider.result[provider.groupList[index]]!, context, controller),
  94. );
  95. },
  96. );
  97. }
  98. genContentList(
  99. List<dynamic> friends, BuildContext context, ScrollController controller) {
  100. double rpx = MediaQuery.of(context).size.width / 750;
  101. return ListView.builder(
  102. shrinkWrap: true,
  103. controller: controller,
  104. itemCount: friends.length,
  105. itemBuilder: (BuildContext context, int index) {
  106. return Container(
  107. decoration: BoxDecoration(color: Color(0xff121319)),
  108. height: 130 * rpx,
  109. child: Row(
  110. children: [
  111. Container(
  112. padding: EdgeInsets.all(15 * rpx),
  113. width: 100 * rpx,
  114. height: 100 * rpx,
  115. child: CircleAvatar(
  116. backgroundImage: NetworkImage(friends[index]["avatarUrl"]),
  117. ),
  118. ),
  119. Container(
  120. width: 450 * rpx,
  121. child: friends[index]["desc"].toString().length > 0
  122. ? Column(
  123. crossAxisAlignment: CrossAxisAlignment.start,
  124. mainAxisAlignment: MainAxisAlignment.center,
  125. children: [
  126. Container(
  127. child: Text(
  128. friends[index]["userName"],
  129. style: TextStyle(
  130. fontSize: 32 * rpx, color: Colors.white),
  131. maxLines: 1,
  132. overflow: TextOverflow.ellipsis,
  133. ),
  134. ),
  135. Container(
  136. child: Text(
  137. friends[index]["desc"],
  138. style: TextStyle(color: Colors.grey[500]),
  139. maxLines: 1,
  140. overflow: TextOverflow.ellipsis,
  141. ),
  142. ),
  143. ],
  144. )
  145. : Container(
  146. child: Text(
  147. friends[index]["userName"],
  148. style: TextStyle(
  149. fontSize: 32 * rpx, color: Colors.white),
  150. maxLines: 1,
  151. overflow: TextOverflow.ellipsis,
  152. ),
  153. ),
  154. ),
  155. Container(
  156. width: 200 * rpx,
  157. child: Icon(
  158. Icons.search,
  159. color: Colors.grey[500],
  160. ),
  161. )
  162. ],
  163. ));
  164. },
  165. );
  166. }