hospital_page.dart 24 KB

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