block_user_list_page.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart' hide NestedScrollView;
  3. import 'package:flutter_easyrefresh/easy_refresh.dart';
  4. import 'package:sport/bean/post_user.dart';
  5. import 'package:sport/bean/user_info.dart';
  6. import 'package:sport/provider/lib/provider_widget.dart';
  7. import 'package:sport/provider/lib/simple_model.dart';
  8. import 'package:sport/provider/lib/view_state_lifecycle.dart';
  9. import 'package:sport/router/navigator_util.dart';
  10. import 'package:sport/services/api/inject_api.dart';
  11. import 'package:sport/utils/DateFormat.dart';
  12. import 'package:sport/widgets/appbar.dart';
  13. import 'package:sport/widgets/dialog/request_dialog.dart';
  14. import 'package:sport/widgets/error.dart';
  15. import 'package:sport/widgets/image.dart';
  16. import 'package:sport/widgets/loading.dart';
  17. import 'package:sport/widgets/misc.dart';
  18. class BlockUserListPage extends StatefulWidget {
  19. @override
  20. State<StatefulWidget> createState() => _PageDetailState();
  21. }
  22. class _PageDetailState
  23. extends ViewStateLifecycle<BlockUserListPage, SimpleModel> with InjectApi {
  24. late TextEditingController _controller;
  25. late FocusNode _focusNode;
  26. @override
  27. void initState() {
  28. super.initState();
  29. _focusNode = FocusNode();
  30. _controller = new TextEditingController(text: '');
  31. }
  32. @override
  33. void dispose() {
  34. super.dispose();
  35. _focusNode.dispose();
  36. _controller.dispose();
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return Scaffold(
  41. backgroundColor: Colors.white,
  42. appBar: buildAppBar(context, title: "屏蔽列表"),
  43. body: ProviderWidget<SimpleModel>(
  44. model: model,
  45. onModelReady: (model) => model.initData(),
  46. builder: (_, model, __) {
  47. return EasyRefresh.custom(
  48. onRefresh: () => model.refresh(),
  49. enableControlFinishRefresh: true,
  50. enableControlFinishLoad: true,
  51. controller: model.refreshController,
  52. header: buildClassicalHeader(),
  53. footer: buildClassicalFooter(),
  54. slivers: <Widget>[
  55. SliverToBoxAdapter(
  56. child: _searchWidget(),
  57. ),
  58. if (model.isBusy)
  59. SliverToBoxAdapter(
  60. child: RequestLoadingWidget(),
  61. ),
  62. if (model.isEmpty)
  63. SliverToBoxAdapter(
  64. child: RequestErrorWidget(
  65. null,
  66. msg: "暂无用户~",
  67. ),
  68. ),
  69. if (model.isIdle)
  70. SliverList(
  71. delegate: SliverChildBuilderDelegate(
  72. (context, index) {
  73. return _buildItem(model.list[index]);
  74. },
  75. childCount: model.list.length,
  76. ),
  77. ),
  78. if (model.isError)
  79. SliverToBoxAdapter(
  80. child: RequestErrorWidget(() {
  81. model.initData();
  82. }),
  83. ),
  84. ],
  85. );
  86. }),
  87. );
  88. }
  89. Widget _buildItem(UserInfo user) {
  90. return Column(
  91. children: <Widget>[
  92. Padding(
  93. padding: const EdgeInsets.all(12.0),
  94. child: InkWell(
  95. onTap: () => NavigatorUtil.goSocialUserDetail(
  96. context,
  97. PostUser(
  98. id: "${user.id}",
  99. name: user.name,
  100. avatar: user.avatar)),
  101. child: Row(
  102. children: <Widget>[
  103. CircleAvatar(
  104. backgroundColor: Colors.black26,
  105. backgroundImage: userAvatarProvider(user.avatar),
  106. radius: 22,
  107. ),
  108. SizedBox(
  109. width: 8,
  110. ),
  111. Expanded(
  112. child: Text(
  113. "${user.name}",
  114. style: Theme.of(context).textTheme.headline3,
  115. ),
  116. ),
  117. GestureDetector(
  118. child: Container(
  119. width: 82,
  120. height: 30,
  121. alignment: Alignment.center,
  122. child: Text(
  123. "取消屏蔽",
  124. strutStyle: fixedLine,
  125. style: Theme.of(context).textTheme.bodyText2!,
  126. ),
  127. decoration: BoxDecoration(
  128. borderRadius: BorderRadius.circular(20),
  129. border: Border.all(
  130. color: Color(0xff999999),
  131. width: .5,
  132. ),
  133. ),
  134. ),
  135. onTap: () async {
  136. await request(context, () async {
  137. var resp = await api
  138. .postForumUnBlockUser("${user.id}")
  139. .catchError((onError) {});
  140. if (resp.code == 0) {
  141. setState(() {
  142. model.list.remove(user);
  143. });
  144. }
  145. });
  146. },
  147. )
  148. ],
  149. )),
  150. ),
  151. Divider(
  152. height: 1,
  153. )
  154. ],
  155. );
  156. }
  157. Widget _searchWidget() {
  158. return Container(
  159. margin: EdgeInsets.fromLTRB(12.0, 6.0, 12.0, 6.0),
  160. height: 40,
  161. padding: EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
  162. decoration: BoxDecoration(
  163. color: Color(0xffF1F1F1),
  164. shape: BoxShape.rectangle,
  165. borderRadius: BorderRadius.all(Radius.circular(50)),
  166. ),
  167. child: Row(
  168. children: <Widget>[
  169. Image.asset("lib/assets/img/searchbar_icon_search.png"),
  170. SizedBox(
  171. width: 6,
  172. ),
  173. Expanded(
  174. child: CupertinoTextField(
  175. cursorColor: const Color(0xffFFC400),
  176. controller: _controller,
  177. maxLines: 1,
  178. focusNode: _focusNode,
  179. placeholder: "输入帐号/用户昵称",
  180. placeholderStyle: Theme.of(context).textTheme.bodyText2,
  181. decoration: BoxDecoration(
  182. // 文本框装饰
  183. color: Colors.transparent, // 文本框颜色
  184. ),
  185. onChanged: (value) {},
  186. onSubmitted: (value) {},
  187. ),
  188. ),
  189. ],
  190. ),
  191. );
  192. }
  193. @override
  194. SimpleModel createModel() =>
  195. SimpleModel((page) async => (await api.getMyBlockUsers()).results);
  196. }