social_index_page.dart 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import 'package:cached_network_image/cached_network_image.dart';
  2. import 'package:flutter/cupertino.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_easyrefresh/easy_refresh.dart';
  5. import 'package:get_it/get_it.dart';
  6. import 'package:provider/provider.dart';
  7. import 'package:shared_preferences/shared_preferences.dart';
  8. import 'package:sport/bean/forum.dart';
  9. import 'package:sport/constant/ui.dart' show ui_padding, ui_margin_list;
  10. import 'package:sport/pages/social/search_page.dart';
  11. import 'package:sport/pages/social/user_friend_page.dart';
  12. import 'package:sport/provider/lib/provider_widget.dart';
  13. import 'package:sport/provider/lib/view_state.dart';
  14. import 'package:sport/provider/lib/view_state_lifecycle.dart';
  15. import 'package:sport/provider/message_model.dart';
  16. import 'package:sport/provider/social_index_model.dart';
  17. import 'package:sport/router/navigator_util.dart';
  18. import 'package:sport/router/routes.dart';
  19. import 'package:sport/widgets/appbar.dart';
  20. import 'package:sport/widgets/decoration.dart';
  21. import 'package:sport/widgets/error.dart';
  22. import 'package:sport/widgets/image.dart';
  23. import 'package:sport/widgets/loading.dart';
  24. import 'package:sport/widgets/misc.dart';
  25. import 'package:sport/widgets/page_resume.dart';
  26. import 'package:sport/widgets/space.dart';
  27. import 'package:umeng_common_sdk/umeng_common_sdk.dart';
  28. class SocialIndexPage extends StatefulWidget {
  29. @override
  30. createState() => _PageState();
  31. }
  32. class _PageState extends ViewStateLifecycle<SocialIndexPage, SocialIndexModel> with AutomaticKeepAliveClientMixin, PageResume {
  33. @override
  34. void didChangeDependencies() {
  35. super.didChangeDependencies();
  36. }
  37. @override
  38. void onResume() {
  39. super.onResume();
  40. }
  41. @override
  42. Widget build(BuildContext context) {
  43. super.build(context);
  44. return Scaffold(
  45. body: ProviderWidget<SocialIndexModel>(
  46. model: model,
  47. onModelReady: (model) => model.initData(),
  48. builder: (_, model, __) {
  49. return EasyRefresh.builder(
  50. controller: model.refreshController,
  51. enableControlFinishRefresh: true,
  52. onRefresh: () => model.refresh(),
  53. header: buildClassicalHeader(),
  54. builder: (context, physics, header, footer) {
  55. return CustomScrollView(
  56. physics: physics,
  57. slivers: <Widget>[
  58. buildSliverAppBar(context, "社区",
  59. backgroundColor: Theme.of(context).scaffoldBackgroundColor,
  60. canBack: false,
  61. actions: <Widget>[
  62. IconButton(
  63. icon: Stack(
  64. alignment: Alignment.center,
  65. children: <Widget>[
  66. Image.asset("lib/assets/img/topbar_friendslist.png"),
  67. ValueListenableBuilder(
  68. valueListenable: GetIt.I<MessageModel>().notifierFriend,
  69. builder: (BuildContext context, int value, Widget? child) {
  70. if (value > 0) {
  71. return Align(
  72. alignment: Alignment.topRight,
  73. child: Container(
  74. margin: const EdgeInsets.only(top: 6.0),
  75. width: 10,
  76. height: 10,
  77. decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.red),
  78. child: Center(
  79. child: Text(""),
  80. ),
  81. ),
  82. );
  83. }
  84. return Container();
  85. }),
  86. ],
  87. ),
  88. onPressed: () async {
  89. UmengCommonSdk.onEvent("social_friend", {});
  90. NavigatorUtil.goPage(context, (context) => UserFriendPage());
  91. },
  92. ),
  93. Selector<SocialIndexModel, ViewState>(
  94. selector: (_, SocialIndexModel model) => model.viewState,
  95. shouldRebuild: (_, v) => v == ViewState.idle,
  96. builder: (BuildContext context, ViewState value, Widget? child) {
  97. return IconButton(
  98. icon: Stack(
  99. alignment: Alignment.center,
  100. children: <Widget>[
  101. Image.asset("lib/assets/img/bbs_icon_news.png"),
  102. FutureBuilder(
  103. future: SharedPreferences.getInstance(),
  104. builder: (BuildContext context, AsyncSnapshot<SharedPreferences> snapshot) {
  105. if (snapshot.connectionState == ConnectionState.done) {
  106. if (snapshot.data?.getBool("message_setting") ?? true == true) {
  107. return ValueListenableBuilder(
  108. valueListenable: GetIt.I<MessageModel>().notifierSocial,
  109. builder: (BuildContext context, int value, Widget? child) {
  110. if (value > 0) {
  111. return Align(
  112. alignment: Alignment.topRight,
  113. child: Container(
  114. margin: const EdgeInsets.only(top: 6.0),
  115. width: 10,
  116. height: 10,
  117. decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.red),
  118. child: Center(
  119. child: Text(""),
  120. ),
  121. ),
  122. );
  123. }
  124. return Container();
  125. });
  126. }
  127. }
  128. return Container();
  129. }),
  130. ],
  131. ),
  132. onPressed: () async {
  133. await NavigatorUtil.go(context, Routes.socialMessage);
  134. setState(() {});
  135. },
  136. );
  137. }),
  138. const SizedBox(width: 6.0,),
  139. ],
  140. paddingLeading: false),
  141. if (header != null) header,
  142. if (model.isBusy)
  143. SliverToBoxAdapter(
  144. child: RequestLoadingWidget(),
  145. ),
  146. if (model.isIdle && model.list.isNotEmpty == true)
  147. SliverList(
  148. delegate: SliverChildBuilderDelegate(
  149. (context, index) {
  150. return _buildItemWidget(model.list[index]);
  151. },
  152. childCount: model.list.length,
  153. ),
  154. ),
  155. if (model.isError)
  156. SliverToBoxAdapter(
  157. child: RequestErrorWidget(() {
  158. model.initData();
  159. }),
  160. ),
  161. ],
  162. );
  163. });
  164. }),
  165. );
  166. }
  167. Widget _buildSearchWidget() {
  168. return GestureDetector(
  169. onTap: () {
  170. Navigator.push(context, new MaterialPageRoute(builder: (context) => SearchPage()));
  171. },
  172. child: Container(
  173. margin: EdgeInsets.fromLTRB(12.0, 0, 12.0, 12.0),
  174. height: 35,
  175. padding: EdgeInsets.fromLTRB(12.0, 0, 12.0, 0),
  176. decoration: BoxDecoration(
  177. color: Color(0xffF1F1F1),
  178. shape: BoxShape.rectangle,
  179. borderRadius: BorderRadius.all(Radius.circular(50)),
  180. ),
  181. child: Row(
  182. children: <Widget>[
  183. Image.asset("lib/assets/img/searchbar_icon_search.png"),
  184. Space(
  185. width: 4,
  186. ),
  187. Text(
  188. "输入关键词",
  189. strutStyle: StrutStyle(forceStrutHeight: true),
  190. style: TextStyle(fontSize: 14, color: Color(0xff999999)),
  191. ),
  192. ],
  193. ),
  194. ),
  195. );
  196. }
  197. Widget _buildItemWidget(Forum item) {
  198. return Padding(
  199. padding: const EdgeInsets.fromLTRB(ui_padding, 6.0, ui_padding, 6.0),
  200. child: InkWell(
  201. onTap: () => NavigatorUtil.goSocialDetail(context, item),
  202. child: Container(
  203. decoration: BoxDecoration(
  204. color: Colors.white,
  205. borderRadius: BorderRadius.all(Radius.circular(10)),
  206. ),
  207. padding: const EdgeInsets.all(ui_padding),
  208. child: Column(
  209. crossAxisAlignment: CrossAxisAlignment.start,
  210. children: <Widget>[
  211. Row(
  212. children: <Widget>[
  213. CachedNetworkImage(imageUrl: item.cover ?? "", width: 48.0, height: 48.0,),
  214. Padding(
  215. padding: const EdgeInsets.all(8.0),
  216. child: Text(
  217. "${item.name}",
  218. maxLines: 1,
  219. style: Theme.of(context).textTheme.headline2!.copyWith(fontSize: 16.0),
  220. ),
  221. ),
  222. Expanded(
  223. child: Center(
  224. child: Row(
  225. mainAxisSize: MainAxisSize.min,
  226. children: [
  227. Image.asset("lib/assets/img/tab_bbs_normal.png", height: 14.0,),
  228. Padding(
  229. padding: const EdgeInsets.only(left: 5.0),
  230. child: ConstrainedBox(
  231. constraints: BoxConstraints(minWidth: 44),
  232. child: Text(
  233. "${item.subjectCount}",
  234. style: Theme.of(context).textTheme.bodyText1!,
  235. ),
  236. ),
  237. ),
  238. ],),
  239. ),
  240. ),
  241. Container(
  242. width: 79.0,
  243. height: 30.0,
  244. decoration: BoxDecoration(color: Theme.of(context).colorScheme.secondary, borderRadius: BorderRadius.circular(100.0)),
  245. child: Center(
  246. child: Text(
  247. "进入",
  248. style: Theme.of(context).textTheme.subtitle1?.copyWith(color: Colors.white),
  249. ),
  250. ),
  251. ),
  252. ],
  253. ),
  254. Padding(
  255. padding: const EdgeInsets.only(top: 12.0),
  256. child: Text(
  257. "${item.digest}",
  258. style: Theme.of(context).textTheme.subtitle1?.copyWith( height: 1.5,),
  259. ),
  260. ),
  261. ],
  262. ),
  263. ),
  264. ),
  265. );
  266. }
  267. @override
  268. bool get wantKeepAlive => true;
  269. @override
  270. SocialIndexModel createModel() => SocialIndexModel();
  271. }