project_list_page.dart 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/internal/lift/lift_router.dart';
  3. import 'package:liftmanager/internal/project/model/project_list_entity.dart';
  4. import 'package:liftmanager/internal/project/presenter/project_list_presenter.dart';
  5. import 'package:liftmanager/internal/project/project_router.dart';
  6. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  7. import 'package:liftmanager/mvp/base_page_state.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/utils/theme_utils.dart';
  11. import 'package:liftmanager/widgets/app_bar.dart';
  12. import 'package:liftmanager/widgets/app_search_bar.dart';
  13. import 'package:liftmanager/widgets/my_button.dart';
  14. import 'package:liftmanager/widgets/my_refresh_list.dart';
  15. import 'package:liftmanager/widgets/search_bar.dart';
  16. import 'package:liftmanager/widgets/state_layout.dart';
  17. import 'package:provider/provider.dart' as p;
  18. class ProjectListPage extends StatefulWidget {
  19. @override
  20. ProjectListPageState createState() => ProjectListPageState();
  21. }
  22. class ProjectListPageState
  23. extends BasePageState<ProjectListPage, ProjectListPresenter> {
  24. BaseListProvider<ProjectListItem> provider =
  25. BaseListProvider<ProjectListItem>();
  26. String _keyword = "";
  27. int _page = 1;
  28. @override
  29. void initState() {
  30. /// 默认为加载中状态,本页面场景默认为空
  31. provider.setStateTypeNotNotify(StateType.loading);
  32. super.initState();
  33. _onRefresh();
  34. }
  35. ///电梯列表
  36. void _liftList(id) {
  37. NavigatorUtils.push(context, LiftRouter.liftListPage + "?id=${id}");
  38. }
  39. ///项目详情
  40. void _projectDetail(id) {
  41. NavigatorUtils.push(context, "${ProjectRouter.projectDetailPage}?id=${id}");
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. bool isDark = ThemeUtils.isDark(context);
  46. return p.ChangeNotifierProvider<BaseListProvider<ProjectListItem>>(
  47. create: (_) => provider,
  48. child: WillPopScope(
  49. onWillPop: () {
  50. NavigatorUtils.goBackWithParams(context, true);
  51. return Future.value(false);
  52. },
  53. child: Scaffold(
  54. appBar: SearchAppBar2(
  55. backgroundColor: Colors.white,
  56. onPressed: (text) {
  57. _keyword = text;
  58. provider.setStateType(StateType.loading);
  59. _page = 1;
  60. presenter.searchProject(context, _keyword, _page, true);
  61. },
  62. ),
  63. body: Container(
  64. color: ThemeUtils.getBackgroundColor(context),
  65. child: Column(
  66. crossAxisAlignment: CrossAxisAlignment.start,
  67. children: <Widget>[
  68. // Container(
  69. // color:ThemeUtils.getTabsBg(context),
  70. // padding:
  71. // EdgeInsets.only(top: 10, bottom: 10, left: 15, right: 15),
  72. // child: SearchBar(
  73. // hintText: "搜索项目",
  74. // autofocus: false,
  75. // onPressed: (text) {
  76. // _keyword = text;
  77. // provider.setStateType(StateType.loading);
  78. // _page = 1;
  79. // presenter.searchProject(context,_keyword, _page, true);
  80. // },
  81. // ),
  82. // ),
  83. Expanded(
  84. flex: 1,
  85. child: p.Consumer<BaseListProvider<ProjectListItem>>(
  86. builder: (_, provider, __) {
  87. return MyListView(
  88. key: Key('project_list'),
  89. itemCount: provider.list.length,
  90. stateType: provider.stateType,
  91. onRefresh: _onRefresh,
  92. loadMore: _loadMore,
  93. hasMore: provider.hasMore,
  94. itemBuilder: (_, index) {
  95. return InkWell(
  96. onTap: () {
  97. _projectDetail(
  98. provider.list[index].projectId);
  99. },
  100. child: Container(
  101. margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  102. decoration: BoxDecoration(
  103. color:
  104. isDark ? Colors.black : Colors.white,
  105. borderRadius: BorderRadius.circular(6.0),
  106. ),
  107. padding: const EdgeInsets.only(bottom: 10),
  108. child: Column(
  109. children: <Widget>[
  110. Container(
  111. // decoration: BoxDecoration(
  112. // border: Border(
  113. // // bottom: BorderSide(
  114. // // width: 0.5, color: Colours.text_gray_c),
  115. // )),
  116. padding: EdgeInsets.only(left: 12),
  117. child: Row(
  118. children: <Widget>[
  119. Expanded(
  120. flex: 1,
  121. child: Text(
  122. provider.list[index]
  123. .projectName,
  124. style: TextStyle(
  125. fontSize: 15,
  126. color: isDark
  127. ? Colours.dark_text
  128. : Colours.text),
  129. overflow:
  130. TextOverflow.ellipsis,
  131. softWrap: false, //单行显示
  132. )),
  133. MyButton(
  134. key: const Key('lift_list'),
  135. onPressed: () {
  136. _liftList(provider
  137. .list[index].projectId);
  138. },
  139. height: 25,
  140. fontSize: 11,
  141. colors: [
  142. Colours.app_main,
  143. Colours.app_main
  144. ],
  145. borderWidth: 0.5,
  146. borderColor: Colours.app_main,
  147. text: "查看电梯",
  148. )
  149. ],
  150. ),
  151. ),
  152. Container(
  153. color: Colours.dark_line_bg,
  154. child: Column(
  155. children: [
  156. lineTxt("区域主管",
  157. "${provider.list[index].directorName}"),
  158. lineTxt(
  159. "项目用途",
  160. "${provider.list[index].getProjectUsageName()}",
  161. ),
  162. lineTxt("项目台量",
  163. "${provider.list[index].actualNum}")
  164. ],
  165. ),
  166. )
  167. ],
  168. ),
  169. ));
  170. },
  171. );
  172. }))
  173. ],
  174. ),
  175. ),
  176. )));
  177. }
  178. Widget lineTxt(title, value) {
  179. return Container(
  180. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  181. child: Row(
  182. children: <Widget>[
  183. Text("${title}",
  184. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  185. Expanded(
  186. flex: 1,
  187. child: Text(
  188. "${value}",
  189. textAlign: TextAlign.right,
  190. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  191. ),
  192. )
  193. ],
  194. ),
  195. );
  196. }
  197. Future _onRefresh() async {
  198. _page = 1;
  199. await presenter.searchProject(context, _keyword, _page, false);
  200. }
  201. Future _loadMore() async {
  202. _page++;
  203. await presenter.searchProject(context, _keyword, _page, false);
  204. }
  205. @override
  206. ProjectListPresenter createPresenter() {
  207. return ProjectListPresenter();
  208. }
  209. }