hospital_page.dart 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. _locationListener = _locationPlugin
  88. .onLocationChanged()
  89. .listen((Map<String, Object> result) {
  90. setState(() {
  91. _locationPlugin.stopLocation();
  92. _locationResult = result;
  93. // address latitude longitude
  94. _locationResult.forEach((key, value) {
  95. if(key == 'city'){
  96. cityName = '$value';
  97. setState(() {
  98. });
  99. }
  100. print(111);
  101. print('key:$key :');
  102. print('value:$value :');
  103. });
  104. });
  105. });
  106. // Future.delayed(Duration.zero, () {
  107. // //执行代码写在这里
  108. // if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  109. // toasts("请登录");
  110. // NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  111. // }else {
  112. // provider.setStateTypeNotNotify(StateType.loading);
  113. // _onRefresh();
  114. // getBannerList();
  115. // getLocation();
  116. // // getQuestionList();
  117. // print(66666);
  118. // }
  119. // });
  120. provider.setStateTypeNotNotify(StateType.loading);
  121. _onRefresh();
  122. getBannerList();
  123. getLocation();
  124. // getQuestionList();
  125. print(66666);
  126. }
  127. List<dynamic> bannerList;
  128. Future getBannerList() async {
  129. await NewApiService().getBanner(1, 3,
  130. onSuccess: (prefix.BannerModel res) {
  131. bannerList = res.records;
  132. print(bannerList.length);
  133. setState(() {});
  134. }, onError: (code, msg) {
  135. toasts(msg);
  136. });
  137. }
  138. @override
  139. void dispose() {
  140. _tabController?.dispose();
  141. // _timer.cancel();
  142. _pageController.dispose();
  143. ///移除定位监听
  144. if (null != _locationListener) {
  145. _locationListener.cancel();
  146. }
  147. ///销毁定位
  148. if (null != _locationPlugin) {
  149. _locationPlugin.destroy();
  150. }
  151. super.dispose();
  152. }
  153. @override
  154. Widget build(BuildContext context) {
  155. return ChangeNotifierProvider<BaseListProvider<Records>>(
  156. create: (_) => provider,
  157. child: Scaffold(
  158. appBar: AppCitySearchAppBar(
  159. city: "${cityName}",
  160. ),
  161. body: Container(
  162. color: ThemeUtils.getTabsBg(context),
  163. child: Column(
  164. crossAxisAlignment: CrossAxisAlignment.start,
  165. children: <Widget>[
  166. Container(
  167. color: ThemeUtils.getTabsBg(context),
  168. child: Column(
  169. children: <Widget>[
  170. Container(
  171. child: Diagnosis(),
  172. ),
  173. Container(
  174. height: 5,
  175. color: ThemeUtils.getDialogTextFieldColor(context)),
  176. LableTitle(
  177. title: "问题",
  178. userTap: () {
  179. NavigatorUtils.push(context,
  180. BbsRouter.questionList);
  181. },
  182. ),
  183. ],
  184. ),
  185. ),
  186. Expanded(
  187. flex: 1,
  188. child: Consumer<BaseListProvider<Records>>(
  189. builder: (_, provider, __) {
  190. return MyListView(
  191. key: Key('question_list'),
  192. itemCount: provider.list.length,
  193. stateType: provider.stateType,
  194. onRefresh: _onRefresh,
  195. loadMore: _loadMore,
  196. hasMore: provider.hasMore,
  197. itemBuilder: (_, index) {
  198. return Container(
  199. child: Column(
  200. children: <Widget>[
  201. // index == 0
  202. // ? Container(
  203. // child: Column(
  204. // children: <Widget>[
  205. // Container(
  206. // child: Diagnosis(),
  207. // ),
  208. // Container(
  209. // height: 5,
  210. // color: Color(0xffeeeeee)),
  211. // LableTitle(
  212. // title: "热门问题",
  213. // userTap: () {
  214. // NavigatorUtils.push(context,
  215. // BbsRouter.questionList);
  216. // },
  217. // ),
  218. // ],
  219. // ),
  220. // )
  221. // : Container(child: null),
  222. GestureDetector(
  223. child: Container(
  224. padding: EdgeInsets.only(
  225. left: ScreenUtil().setWidth(15),
  226. right: ScreenUtil().setWidth(10),
  227. top: ScreenUtil().setHeight(10),
  228. bottom: ScreenUtil().setHeight(10)),
  229. decoration: BoxDecoration(
  230. border: Border(
  231. bottom: BorderSide(
  232. width: 0.5, color: Colours.line),
  233. ),
  234. color: ThemeUtils.getTabsBg(context)),
  235. child: Column(
  236. crossAxisAlignment:
  237. CrossAxisAlignment.start,
  238. children: <Widget>[
  239. Text(
  240. "[${provider.list[index].brandName}]${provider.list[index].title}",
  241. textAlign: TextAlign.left,
  242. style: TextStyle(
  243. fontSize:
  244. ScreenUtil().setSp(15)),
  245. maxLines: 1,
  246. overflow: TextOverflow.ellipsis,
  247. ),
  248. Container(
  249. padding: EdgeInsets.only(
  250. top: ScreenUtil().setHeight(10),
  251. bottom:
  252. ScreenUtil().setHeight(10)),
  253. child: Row(
  254. children: <Widget>[
  255. ClipRRect(
  256. borderRadius:
  257. BorderRadius.circular(
  258. ScreenUtil()
  259. .setWidth(18)),
  260. child: Container(
  261. child: LoadNetworkImage(
  262. provider.list[index]
  263. .avatarUrl,
  264. // fit: BoxFit.fitWidth,
  265. width: ScreenUtil()
  266. .setWidth(34),
  267. height: ScreenUtil()
  268. .setWidth(34),
  269. ),
  270. )),
  271. Container(
  272. padding: EdgeInsets.only(
  273. left: ScreenUtil()
  274. .setWidth(10)),
  275. child: Column(
  276. crossAxisAlignment:
  277. CrossAxisAlignment
  278. .start,
  279. children: <Widget>[
  280. Text(
  281. provider.list[index].userName ??"",
  282. style: TextStyle(
  283. fontSize:
  284. ScreenUtil()
  285. .setSp(14),
  286. ),
  287. ),
  288. Text(
  289. DateUtils.instance
  290. .getFormartData(
  291. timeSamp: provider
  292. .list[index]
  293. .createTime,
  294. format:
  295. "yyyy-MM-dd"),
  296. style: TextStyle(
  297. fontSize:
  298. ScreenUtil()
  299. .setSp(12),
  300. color: Color(
  301. 0xffaaaaaa)),
  302. ),
  303. ],
  304. ),
  305. )
  306. ],
  307. ),
  308. ),
  309. Text(
  310. provider.list[index].expression ??
  311. "",
  312. textAlign: TextAlign.left,
  313. style: TextStyle(
  314. color: Color(0xff666666),
  315. fontSize: ScreenUtil().setSp(14),
  316. ),
  317. maxLines: 2,
  318. overflow: TextOverflow.ellipsis,
  319. ),
  320. Container(
  321. padding: EdgeInsets.only(
  322. top: ScreenUtil().setHeight(5),
  323. bottom:
  324. ScreenUtil().setHeight(5)),
  325. child: Row(
  326. mainAxisAlignment:
  327. MainAxisAlignment.start,
  328. children: provider.list[index]
  329. .imgs !=
  330. null &&
  331. provider.list[index]
  332. .imgs.isNotEmpty
  333. ? List<Widget>.from(provider
  334. .list[index].imgs
  335. .split(",")
  336. .asMap()
  337. .keys
  338. .map((subindex) {
  339. // print(item);
  340. return subindex<3?Container(
  341. padding: subindex <
  342. provider
  343. .list[
  344. index]
  345. .imgs
  346. .split(
  347. ",")
  348. .length -
  349. 1
  350. ? EdgeInsets.only(
  351. right: 6)
  352. : EdgeInsets.only(
  353. right: 0),
  354. // color:Colors.red,
  355. // decoration: BoxDecoration(
  356. // borderRadius: BorderRadius.circular(20.0),
  357. // ),
  358. child: ClipRRect(
  359. borderRadius:
  360. BorderRadius
  361. .circular(
  362. 10),
  363. child:
  364. LoadNetworkImage(
  365. // imgFontUrl + item,
  366. provider
  367. .list[index]
  368. .imgs
  369. .split(
  370. ",")[
  371. subindex],
  372. fit: BoxFit.fill,
  373. height:
  374. ScreenUtil()
  375. .setWidth(
  376. 80),
  377. width:
  378. ScreenUtil()
  379. .setWidth(
  380. 110),
  381. isWater: true,
  382. ),
  383. ),
  384. ):Container(child: null,);
  385. }).toList())
  386. : <Widget>[]),
  387. ),
  388. Text(
  389. "${provider.list[index].likeNum}人赞",
  390. textAlign: TextAlign.right,
  391. style: TextStyle(
  392. color: Color(0xff999999),
  393. fontSize: ScreenUtil().setSp(14),
  394. ),
  395. )
  396. ]),
  397. ),
  398. onTap: () {
  399. // print(item);
  400. NavigatorUtils.push(context,
  401. "${BbsRouter.questionDetail}?id=${provider.list[index].id.toString()}");
  402. },
  403. )
  404. ],
  405. ),
  406. );
  407. },
  408. );
  409. }))
  410. ],
  411. ),
  412. ),
  413. ));
  414. }
  415. Widget loadCircle() {
  416. return Container(
  417. padding: EdgeInsets.only(top: 10, bottom: 10),
  418. color: ThemeUtils.getTabsBg(context),
  419. child: Center(
  420. child: SpinKitFadingCircle(
  421. color: Colors.blueAccent,
  422. size: 30.0,
  423. ),
  424. ),
  425. );
  426. }
  427. Widget lineTxt(title, value) {
  428. return Container(
  429. padding: EdgeInsets.only(left: 12, top: 5, right: 12),
  430. child: Row(
  431. children: <Widget>[
  432. Text("$title",
  433. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray)),
  434. Expanded(
  435. flex: 1,
  436. child: Text(
  437. "$value",
  438. textAlign: TextAlign.right,
  439. style: TextStyle(fontSize: 13, color: Colours.dark_text_gray),
  440. ),
  441. )
  442. ],
  443. ),
  444. );
  445. }
  446. Future _onRefresh() async {
  447. _page = 1;
  448. await presenter.getQuestionList(_page);
  449. }
  450. Future _loadMore() async {
  451. _page++;
  452. await presenter.getQuestionList(_page);
  453. }
  454. @override
  455. QuestionListPresenter createPresenter() {
  456. return QuestionListPresenter();
  457. }
  458. bool get wantKeepAlive => true;
  459. }
  460. class _ToolsItem extends StatelessWidget {
  461. _ToolsItem(this.titles, this.imgs, this.colors, this.onTap, {Key key})
  462. : super(key: key);
  463. List<String> titles;
  464. List<int> imgs;
  465. List<String> colors;
  466. Function onTap;
  467. @override
  468. Widget build(BuildContext context) {
  469. return GridView.builder(
  470. shrinkWrap: true,
  471. padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
  472. physics: NeverScrollableScrollPhysics(),
  473. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  474. crossAxisCount: 4, childAspectRatio: 0.9, crossAxisSpacing: 2),
  475. itemCount: titles.length,
  476. itemBuilder: (_, index) {
  477. return InkWell(
  478. child: Column(
  479. mainAxisAlignment: MainAxisAlignment.center,
  480. children: <Widget>[
  481. // LoadAssetImage(
  482. // "work/${imgs[index]}",
  483. // width: 45.0,
  484. // height: 45,
  485. // ),
  486. Container(
  487. width: ScreenUtil().setWidth(40),
  488. height: ScreenUtil().setWidth(40),
  489. decoration: BoxDecoration(
  490. borderRadius: BorderRadius.circular(20.0),
  491. color: Color(
  492. int.parse(colors[index]),
  493. ),
  494. ),
  495. child: Icon(
  496. IconData(imgs[index], fontFamily: "myfont"),
  497. size: 22.0,
  498. color: Color.fromRGBO(255, 255, 255, 1),
  499. ),
  500. ),
  501. Gaps.vGap8,
  502. Text(titles[index],
  503. style: TextStyle(fontSize: ScreenUtil().setSp(14))),
  504. Gaps.vGap10,
  505. ],
  506. ),
  507. onTap: () {
  508. onTap(index);
  509. });
  510. },
  511. );
  512. }
  513. }