lift_list_page.dart 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/common/common.dart';
  3. import 'package:liftmanager/common/user_db.dart';
  4. import 'package:liftmanager/internal/lift/lift_router.dart';
  5. import 'package:liftmanager/internal/lift/model/lift_list_entity.dart';
  6. import 'package:liftmanager/internal/lift/presenter/lift_list_presenter.dart';
  7. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  8. import 'package:liftmanager/mvp/base_page_state.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/theme_utils.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/state_layout.dart';
  16. import 'package:provider/provider.dart' as p;
  17. class LiftListPage extends StatefulWidget {
  18. LiftListPage(this.projectId);
  19. final String projectId;
  20. @override
  21. LiftListPageState createState() => LiftListPageState();
  22. }
  23. class LiftListPageState extends BasePageState<LiftListPage, LiftListPresenter> {
  24. BaseListProvider<LiftListItem> provider = BaseListProvider<LiftListItem>();
  25. String _keyword = "";
  26. int _page = 1;
  27. @override
  28. void initState() {
  29. /// 默认为加载中状态,本页面场景默认为空
  30. provider.setStateTypeNotNotify(StateType.loading);
  31. super.initState();
  32. _onRefresh();
  33. getHasRole();
  34. }
  35. bool noRole = true;
  36. getHasRole() async {
  37. var role = await User().getCompanyRole();
  38. print(role);
  39. if(role == Constant.RoleAdmin || role == Constant.RoleRegion || role == Constant.RoleWork){
  40. noRole = false;
  41. setState(() {
  42. });
  43. }
  44. }
  45. goToPage(pagePath){
  46. NavigatorUtils.pushResult(context, pagePath, (res){
  47. _onRefresh();
  48. });
  49. }
  50. @override
  51. Widget build(BuildContext context) {
  52. bool isDark = ThemeUtils.isDark(context);
  53. return p.ChangeNotifierProvider<BaseListProvider<LiftListItem>>(
  54. create: (_) => provider,
  55. child: Scaffold(
  56. appBar: SearchAppBar2(
  57. backgroundColor: Colors.white,
  58. onPressed: (text) {
  59. print(widget.projectId);
  60. _keyword = text;
  61. provider.setStateType(StateType.loading);
  62. _page = 1;
  63. presenter.searchLift(context,
  64. widget.projectId, _keyword, _page, true);
  65. },
  66. actions: [ Offstage(
  67. offstage: noRole,
  68. child: FlatButton(
  69. child: Text("新建", key: const Key('actionName')),
  70. textColor: Colours.text,
  71. highlightColor: Colors.transparent,
  72. onPressed: () {
  73. goToPage("${LiftRouter.liftCreatePage}?id="+widget.projectId);
  74. },
  75. )
  76. )],
  77. ),
  78. // appBar: MyAppBar(
  79. // centerTitle: "电梯列表",
  80. // actions: <Widget>[
  81. // Offstage(
  82. // offstage: noRole,
  83. // child: FlatButton(
  84. // child: Text("新建", key: const Key('actionName')),
  85. // textColor: Colours.dark_text,
  86. // highlightColor: Colors.transparent,
  87. // onPressed: () {
  88. // goToPage("${LiftRouter.liftCreatePage}?id="+widget.projectId);
  89. // },
  90. // )
  91. // )
  92. // ],
  93. // ),
  94. body: Container(
  95. color: ThemeUtils.getBackgroundColor(context),
  96. child: Column(
  97. crossAxisAlignment: CrossAxisAlignment.start,
  98. children: <Widget>[
  99. // Container(
  100. // color: ThemeUtils.getTabsBg(context),
  101. // padding:
  102. // EdgeInsets.only(top: 10, bottom: 10, left: 15, right: 15),
  103. // child: SearchBar(
  104. // autofocus: false,
  105. // hintText: "搜索电梯",
  106. // onPressed: (text) {
  107. // // if (text.isEmpty){
  108. // // showToast("搜索团队名称不能为空!");
  109. // // return;
  110. // // }
  111. // // FocusScope.of(context).unfocus();
  112. // print(widget.projectId);
  113. // _keyword = text;
  114. // provider.setStateType(StateType.loading);
  115. // _page = 1;
  116. // presenter.searchLift(context,
  117. // widget.projectId, _keyword, _page, true);
  118. // },
  119. // ),
  120. // ),
  121. Expanded(
  122. flex: 1,
  123. child: p.Consumer<BaseListProvider<LiftListItem>>(
  124. builder: (_, provider, __) {
  125. return MyListView(
  126. key: Key('lift_list'),
  127. itemCount: provider.list.length,
  128. stateType: provider.stateType,
  129. onRefresh: _onRefresh,
  130. loadMore: _loadMore,
  131. // itemExtent: 67.0,
  132. hasMore: provider.hasMore,
  133. itemBuilder: (_, index) {
  134. return Container(
  135. margin: EdgeInsets.fromLTRB(15, 5, 15, 5),
  136. decoration: BoxDecoration(
  137. color:isDark?Colors.black:Colors.white,
  138. borderRadius: BorderRadius.circular(6.0),
  139. ),
  140. padding: const EdgeInsets.only(bottom: 10),
  141. child: Column(
  142. children: <Widget>[
  143. Container(
  144. decoration: BoxDecoration(
  145. border: Border(
  146. bottom: BorderSide(
  147. width: 0.5, color: Colours.text_gray_c),
  148. )),
  149. padding: EdgeInsets.only(left: 12),
  150. child: Row(
  151. children: <Widget>[
  152. Expanded(
  153. flex: 1,
  154. child: Text(
  155. provider.list[index].useCompanyCode,
  156. style: TextStyle(fontSize: 15,color:isDark?Colours.dark_text:Colours.text,),
  157. overflow: TextOverflow.ellipsis,
  158. softWrap: false, //单行显示
  159. )),
  160. MyButton(
  161. key: const Key('lift_list'),
  162. onPressed: () {
  163. // _liftList(provider.list[index].id);
  164. goToPage("${LiftRouter.liftDetailPage}?project_id="+widget.projectId+"&id="+provider.list[index].id);
  165. },
  166. height: 25,
  167. fontSize: 11,
  168. colors: [
  169. Colours.app_main,
  170. Colours.app_main
  171. ],
  172. borderWidth: 0.5,
  173. borderColor: Colours.app_main,
  174. text: "查看详情",
  175. )
  176. ],
  177. ),
  178. ),
  179. lineTxt("注册代码",
  180. "${provider.list[index].registrationCode}"),
  181. lineTxt(
  182. "电梯型号", "${provider.list[index].liftCode}"),
  183. lineTxt(
  184. "电梯类型", "${provider.list[index].liftTypeName}"),
  185. lineTxt(
  186. "电梯品牌", "${provider.list[index].liftBrand}")
  187. ],
  188. ),
  189. );
  190. },
  191. );
  192. }))
  193. ],
  194. ),
  195. ),
  196. ));
  197. }
  198. Widget lineTxt(title, value) {
  199. return Container(
  200. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  201. child: Row(
  202. children: <Widget>[
  203. Text("${title}",
  204. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  205. Expanded(
  206. flex: 1,
  207. child: Text(
  208. "${value}",
  209. textAlign: TextAlign.right,
  210. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  211. ),
  212. )
  213. ],
  214. ),
  215. );
  216. }
  217. Future _onRefresh() async {
  218. _page = 1;
  219. await presenter.searchLift(context,widget.projectId, _keyword, _page, false);
  220. }
  221. Future _loadMore() async {
  222. _page++;
  223. await presenter.searchLift(context,widget.projectId, _keyword, _page, false);
  224. }
  225. @override
  226. LiftListPresenter createPresenter() {
  227. return LiftListPresenter();
  228. }
  229. }