block_user_list_page.dart 6.3 KB

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