hospital_page.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. import 'dart:async';
  2. // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
  3. import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:liftmanager/internal/bbs/bbs_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/net/api_service.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/routers/fluro_navigator.dart';
  11. import 'package:liftmanager/utils/toast.dart';
  12. import 'package:liftmanager/widgets/app_city_search_bar.dart';
  13. import 'package:liftmanager/widgets/load_image.dart';
  14. import 'package:liftmanager/widgets/my_refresh_list.dart';
  15. import 'package:liftmanager/widgets/state_layout.dart';
  16. import 'package:permission_handler/permission_handler.dart';
  17. import 'package:provider/provider.dart';
  18. import 'package:liftmanager/widgets/bbs_content.dart';
  19. import 'package:flutter_screenutil/flutter_screenutil.dart';
  20. import 'package:liftmanager/internal/means/means_router.dart';
  21. import 'package:flutter_spinkit/flutter_spinkit.dart';
  22. import 'dart:convert';
  23. import 'package:liftmanager/internal/bbs/model/banner_model.dart' as prefix;
  24. import 'package:liftmanager/internal/bbs/presenter/question_list_presenter.dart';
  25. import 'package:liftmanager/internal/bbs/model/mix_model.dart';
  26. import 'package:liftmanager/utils/time_format.dart';
  27. import 'package:liftmanager/utils/url.dart';
  28. import 'package:liftmanager/utils/utils.dart';
  29. import 'package:flustars/flustars.dart' as FlutterStars;
  30. import 'package:liftmanager/common/common.dart';
  31. import 'package:liftmanager/internal/account/account_router.dart';
  32. import 'package:liftmanager/utils/theme_utils.dart';
  33. class HospitalPage extends StatefulWidget {
  34. @override
  35. HospitalPageState createState() => HospitalPageState();
  36. }
  37. // const timeout = const Duration(seconds: 5);
  38. class HospitalPageState
  39. extends BasePageState<HospitalPage, QuestionListPresenter>
  40. with AutomaticKeepAliveClientMixin {
  41. BaseListProvider<Records> provider = BaseListProvider<Records>();
  42. AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
  43. StreamSubscription<Map<String, Object>> _locationListener;
  44. Map<String, Object> _locationResult;
  45. TabController _tabController;
  46. PageController _pageController = PageController();
  47. int _index = 0;
  48. Timer _timer;
  49. String _keyword;
  50. int _page = 1;
  51. // Location _location;
  52. String cityName = "暂无定位";
  53. ///获取定位权限
  54. Future<bool> requestPermission() async {
  55. final permissions = await PermissionHandler()
  56. .requestPermissions([PermissionGroup.location]);
  57. if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
  58. return true;
  59. } else {
  60. toasts('需要定位权限!');
  61. return false;
  62. }
  63. }
  64. ///获取位置信息
  65. getLocation() async {
  66. if (await requestPermission()) {
  67. if (null != _locationPlugin) {
  68. _locationPlugin.startLocation();
  69. }
  70. }
  71. }
  72. // getCity() async {
  73. // LatLng latlng = await _location.latLng;
  74. // ApiService().getCity(latlng.latitude,latlng.longitude,onSuccess: (res){
  75. //
  76. // },onError: (code,msg){
  77. //
  78. // });
  79. // }
  80. void _onPageChanged(int index) {
  81. _index = index;
  82. _tabController.animateTo(index);
  83. }
  84. @override
  85. void initState() {
  86. super.initState();
  87. ///移除定位监听
  88. if (null != _locationListener) {
  89. _locationListener.cancel();
  90. }
  91. ///销毁定位
  92. if (null != _locationPlugin) {
  93. _locationPlugin.destroy();
  94. }
  95. _locationListener = _locationPlugin
  96. .onLocationChanged()
  97. .listen((Map<String, Object> result) {
  98. setState(() {
  99. _locationPlugin.stopLocation();
  100. _locationResult = result;
  101. // address latitude longitude
  102. _locationResult.forEach((key, value) {
  103. if(key == 'city'){
  104. cityName = '$value';
  105. setState(() {
  106. });
  107. }
  108. print(111);
  109. print('key:$key :');
  110. print('value:$value :');
  111. });
  112. });
  113. });
  114. // Future.delayed(Duration.zero, () {
  115. // //执行代码写在这里
  116. // if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  117. // toasts("请登录");
  118. // NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  119. // }else {
  120. // provider.setStateTypeNotNotify(StateType.loading);
  121. // _onRefresh();
  122. // getBannerList();
  123. // getLocation();
  124. // // getQuestionList();
  125. // print(66666);
  126. // }
  127. // });
  128. provider.setStateTypeNotNotify(StateType.loading);
  129. _onRefresh();
  130. getBannerList();
  131. getLocation();
  132. if (!Utils.getAuthByRouter(context,'question_center',false)) {
  133. getQuestionList();
  134. }
  135. print(66666);
  136. }
  137. List<dynamic> questionsList;
  138. Future getQuestionList() async {
  139. await NewApiService().getQuestionList(1, 4, null, null, null,
  140. onSuccess: (res) {
  141. // res.records.forEach((item){
  142. // questionsList.addAll(item);
  143. // });
  144. questionsList = res.records;
  145. // print(JsonEncoder().convert(res.records));
  146. setState(() {});
  147. }, onError: (code, msg) {
  148. toasts(msg);
  149. });
  150. }
  151. List<dynamic> bannerList;
  152. Future getBannerList() async {
  153. await NewApiService().getBanner(1, 3,
  154. onSuccess: (prefix.BannerModel res) {
  155. bannerList = res.records;
  156. print(bannerList.length);
  157. setState(() {});
  158. }, onError: (code, msg) {
  159. toasts(msg);
  160. });
  161. }
  162. @override
  163. void dispose() {
  164. _tabController?.dispose();
  165. // _timer.cancel();
  166. _pageController.dispose();
  167. ///移除定位监听
  168. if (null != _locationListener) {
  169. _locationListener.cancel();
  170. }
  171. ///销毁定位
  172. if (null != _locationPlugin) {
  173. _locationPlugin.destroy();
  174. }
  175. super.dispose();
  176. }
  177. @override
  178. Widget build(BuildContext context) {
  179. return ChangeNotifierProvider<BaseListProvider<Records>>(
  180. create: (_) => provider,
  181. child: Scaffold(
  182. appBar: AppCitySearchAppBar(
  183. city: "${cityName}",
  184. ),
  185. body: Container(
  186. color: ThemeUtils.getTabsBg(context),
  187. child: Column(
  188. crossAxisAlignment: CrossAxisAlignment.start,
  189. children: <Widget>[
  190. Container(
  191. color: ThemeUtils.getTabsBg(context),
  192. child: Column(
  193. children: <Widget>[
  194. Container(
  195. child: Diagnosis(),
  196. ),
  197. Container(
  198. height: 5,
  199. color: ThemeUtils.getDialogTextFieldColor(context)),
  200. LableTitle(
  201. title: "问题",
  202. userTap: () {
  203. if (Utils.getAuthByRouter(context,'question_center')) {
  204. NavigatorUtils.push(context, BbsRouter.questionList);
  205. }
  206. },
  207. ),
  208. ],
  209. ),
  210. ),
  211. Utils.getAuthByRouter(context,'question_center',false)?Expanded(
  212. flex: 1,
  213. child: Consumer<BaseListProvider<Records>>(
  214. builder: (_, provider, __) {
  215. return MyListView(
  216. key: Key('question_list'),
  217. itemCount: provider.list.length,
  218. stateType: provider.stateType,
  219. onRefresh: _onRefresh,
  220. loadMore: _loadMore,
  221. hasMore: provider.hasMore,
  222. itemBuilder: (_, index) {
  223. return Container(
  224. child: Column(
  225. children: <Widget>[
  226. // index == 0
  227. // ? Container(
  228. // child: Column(
  229. // children: <Widget>[
  230. // Container(
  231. // child: Diagnosis(),
  232. // ),
  233. // Container(
  234. // height: 5,
  235. // color: Color(0xffeeeeee)),
  236. // LableTitle(
  237. // title: "热门问题",
  238. // userTap: () {
  239. // NavigatorUtils.push(context,
  240. // BbsRouter.questionList);
  241. // },
  242. // ),
  243. // ],
  244. // ),
  245. // )
  246. // : Container(child: null),
  247. GestureDetector(
  248. child: Container(
  249. padding: EdgeInsets.only(
  250. left: ScreenUtil().setWidth(15),
  251. right: ScreenUtil().setWidth(10),
  252. top: ScreenUtil().setHeight(10),
  253. bottom: ScreenUtil().setHeight(10)),
  254. decoration: BoxDecoration(
  255. border: Border(
  256. bottom: BorderSide(
  257. width: 0.5, color: Colours.line),
  258. ),
  259. color: ThemeUtils.getTabsBg(context)),
  260. child: Column(
  261. crossAxisAlignment:
  262. CrossAxisAlignment.start,
  263. children: <Widget>[
  264. Text(
  265. "[${provider.list[index].brandName}]${provider.list[index].title}",
  266. textAlign: TextAlign.left,
  267. style: TextStyle(
  268. fontSize:
  269. ScreenUtil().setSp(15)),
  270. maxLines: 1,
  271. overflow: TextOverflow.ellipsis,
  272. ),
  273. Container(
  274. padding: EdgeInsets.only(
  275. top: ScreenUtil().setHeight(10),
  276. bottom:
  277. ScreenUtil().setHeight(10)),
  278. child: Row(
  279. children: <Widget>[
  280. ClipRRect(
  281. borderRadius:
  282. BorderRadius.circular(
  283. ScreenUtil()
  284. .setWidth(18)),
  285. child: Container(
  286. child: LoadNetworkImage(
  287. provider.list[index]
  288. .avatarUrl,
  289. // fit: BoxFit.fitWidth,
  290. width: ScreenUtil()
  291. .setWidth(34),
  292. height: ScreenUtil()
  293. .setWidth(34),
  294. ),
  295. )),
  296. Container(
  297. padding: EdgeInsets.only(
  298. left: ScreenUtil()
  299. .setWidth(10)),
  300. child: Column(
  301. crossAxisAlignment:
  302. CrossAxisAlignment
  303. .start,
  304. children: <Widget>[
  305. Text(
  306. provider.list[index].userName ??"",
  307. style: TextStyle(
  308. fontSize:
  309. ScreenUtil()
  310. .setSp(14),
  311. ),
  312. ),
  313. Text(
  314. DateUtils.instance
  315. .getFormartData(
  316. timeSamp: provider
  317. .list[index]
  318. .createTime,
  319. format:
  320. "yyyy-MM-dd"),
  321. style: TextStyle(
  322. fontSize:
  323. ScreenUtil()
  324. .setSp(12),
  325. color: Color(
  326. 0xffaaaaaa)),
  327. ),
  328. ],
  329. ),
  330. )
  331. ],
  332. ),
  333. ),
  334. Text(
  335. provider.list[index].expression ??
  336. "",
  337. textAlign: TextAlign.left,
  338. style: TextStyle(
  339. color: Color(0xff666666),
  340. fontSize: ScreenUtil().setSp(14),
  341. ),
  342. maxLines: 2,
  343. overflow: TextOverflow.ellipsis,
  344. ),
  345. Container(
  346. padding: EdgeInsets.only(
  347. top: ScreenUtil().setHeight(5),
  348. bottom:
  349. ScreenUtil().setHeight(5)),
  350. child: Row(
  351. mainAxisAlignment:
  352. MainAxisAlignment.start,
  353. children: provider.list[index]
  354. .imgs !=
  355. null &&
  356. provider.list[index]
  357. .imgs.isNotEmpty
  358. ? List<Widget>.from(provider
  359. .list[index].imgs
  360. .split(",")
  361. .asMap()
  362. .keys
  363. .map((subindex) {
  364. // print(item);
  365. return subindex<3?Container(
  366. padding: subindex <
  367. provider
  368. .list[
  369. index]
  370. .imgs
  371. .split(
  372. ",")
  373. .length -
  374. 1
  375. ? EdgeInsets.only(
  376. right: 6)
  377. : EdgeInsets.only(
  378. right: 0),
  379. // color:Colors.red,
  380. // decoration: BoxDecoration(
  381. // borderRadius: BorderRadius.circular(20.0),
  382. // ),
  383. child: ClipRRect(
  384. borderRadius:
  385. BorderRadius
  386. .circular(
  387. 10),
  388. child:
  389. LoadNetworkImage(
  390. // imgFontUrl + item,
  391. provider
  392. .list[index]
  393. .imgs
  394. .split(
  395. ",")[
  396. subindex],
  397. fit: BoxFit.fill,
  398. height:
  399. ScreenUtil()
  400. .setWidth(
  401. 80),
  402. width:
  403. ScreenUtil()
  404. .setWidth(
  405. 110),
  406. isWater: true,
  407. ),
  408. ),
  409. ):Container(child: null,);
  410. }).toList())
  411. : <Widget>[]),
  412. ),
  413. Text(
  414. "${provider.list[index].likeNum}人赞",
  415. textAlign: TextAlign.right,
  416. style: TextStyle(
  417. color: Color(0xff999999),
  418. fontSize: ScreenUtil().setSp(14),
  419. ),
  420. )
  421. ]),
  422. ),
  423. onTap: () {
  424. // print(item);
  425. NavigatorUtils.push(context,
  426. "${BbsRouter.questionDetail}?id=${provider.list[index].id.toString()}");
  427. },
  428. )
  429. ],
  430. ),
  431. );
  432. },
  433. );
  434. })):
  435. Expanded(
  436. child: ListView(
  437. children: <Widget>[
  438. Container(
  439. child: questionsList != null && questionsList != []
  440. ? HotQuestion(initList: questionsList)
  441. : loadCircle()),
  442. ],
  443. ),
  444. )
  445. ],
  446. ),
  447. ),
  448. ));
  449. }
  450. Widget loadCircle() {
  451. return Container(
  452. padding: EdgeInsets.only(top: 10, bottom: 10),
  453. color: ThemeUtils.getTabsBg(context),
  454. child: Center(
  455. child: SpinKitFadingCircle(
  456. color: Colors.blueAccent,
  457. size: 30.0,
  458. ),
  459. ),
  460. );
  461. }
  462. Widget lineTxt(title, value) {
  463. return Container(
  464. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  465. child: Row(
  466. children: <Widget>[
  467. Text("$title",
  468. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  469. Expanded(
  470. flex: 1,
  471. child: Text(
  472. "$value",
  473. textAlign: TextAlign.right,
  474. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  475. ),
  476. )
  477. ],
  478. ),
  479. );
  480. }
  481. Future _onRefresh() async {
  482. _page = 1;
  483. await presenter.getQuestionList(_page);
  484. }
  485. Future _loadMore() async {
  486. _page++;
  487. await presenter.getQuestionList(_page);
  488. }
  489. @override
  490. QuestionListPresenter createPresenter() {
  491. return QuestionListPresenter();
  492. }
  493. bool get wantKeepAlive => true;
  494. }
  495. class _ToolsItem extends StatelessWidget {
  496. _ToolsItem(this.titles, this.imgs, this.colors, this.onTap, {Key key})
  497. : super(key: key);
  498. List<String> titles;
  499. List<int> imgs;
  500. List<String> colors;
  501. Function onTap;
  502. @override
  503. Widget build(BuildContext context) {
  504. return GridView.builder(
  505. shrinkWrap: true,
  506. padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
  507. physics: NeverScrollableScrollPhysics(),
  508. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  509. crossAxisCount: 4, childAspectRatio: 0.9, crossAxisSpacing: 2),
  510. itemCount: titles.length,
  511. itemBuilder: (_, index) {
  512. return InkWell(
  513. child: Column(
  514. mainAxisAlignment: MainAxisAlignment.center,
  515. children: <Widget>[
  516. // LoadAssetImage(
  517. // "work/${imgs[index]}",
  518. // width: 45.0,
  519. // height: 45,
  520. // ),
  521. Container(
  522. width: ScreenUtil().setWidth(40),
  523. height: ScreenUtil().setWidth(40),
  524. decoration: BoxDecoration(
  525. borderRadius: BorderRadius.circular(20.0),
  526. color: Color(
  527. int.parse(colors[index]),
  528. ),
  529. ),
  530. child: Icon(
  531. IconData(imgs[index], fontFamily: "myfont"),
  532. size: 22.0,
  533. color: Color.fromRGBO(255, 255, 255, 1),
  534. ),
  535. ),
  536. Gaps.vGap8,
  537. Text(titles[index],
  538. style: TextStyle(fontSize: ScreenUtil().setSp(14))),
  539. Gaps.vGap10,
  540. ],
  541. ),
  542. onTap: () {
  543. onTap(index);
  544. });
  545. },
  546. );
  547. }
  548. }