bbs_page.dart 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
  2. import 'package:amap_location_flutter_plugin/amap_location_flutter_plugin.dart';
  3. import 'package:amap_location_flutter_plugin/amap_location_option.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  6. import 'package:liftmanager/internal/bbs/model/news_comm_entity.dart';
  7. import 'package:liftmanager/internal/bbs/presenter/news_list_presenter.dart';
  8. import 'package:liftmanager/internal/search/presenter/base_list_provider.dart';
  9. import 'package:liftmanager/mvp/base_page_state.dart';
  10. import 'package:liftmanager/net/api_service.dart';
  11. import 'package:liftmanager/res/resources.dart';
  12. import 'package:liftmanager/routers/fluro_navigator.dart';
  13. import 'package:liftmanager/utils/toast.dart';
  14. import 'package:liftmanager/widgets/app_city_search_bar.dart';
  15. import 'package:liftmanager/widgets/load_image.dart';
  16. import 'package:liftmanager/widgets/my_refresh_list.dart';
  17. import 'package:liftmanager/widgets/state_layout.dart';
  18. import 'package:permission_handler/permission_handler.dart';
  19. import 'package:provider/provider.dart';
  20. import 'package:liftmanager/widgets/bbs_content.dart';
  21. import 'package:flutter_screenutil/flutter_screenutil.dart';
  22. import '../../../utils/toast.dart';
  23. import 'package:liftmanager/internal/means/means_router.dart';
  24. // import '../model/question_model.dart' as qItem;
  25. import 'dart:convert';
  26. import 'package:liftmanager/utils/fast_notification.dart';
  27. import 'package:liftmanager/internal/bbs/model/banner_model.dart';
  28. import 'package:flutter_spinkit/flutter_spinkit.dart';
  29. import 'package:liftmanager/utils/utils.dart';
  30. import 'package:flustars/flustars.dart' as FlutterStars;
  31. import 'package:liftmanager/internal/bbs/provide/websocket.dart';
  32. import 'package:liftmanager/common/common.dart';
  33. import 'package:liftmanager/internal/account/account_router.dart';
  34. import 'package:liftmanager/internal/news/news_router.dart';
  35. import 'package:uni_links/uni_links.dart';
  36. import 'package:liftmanager/utils/theme_utils.dart';
  37. import 'package:fluwx/fluwx.dart' as fluwx;
  38. import 'dart:async';
  39. class BbsPage extends StatefulWidget {
  40. @override
  41. BbsPageState createState() => BbsPageState();
  42. }
  43. const timeout = const Duration(seconds: 5);
  44. class BbsPageState extends BasePageState<BbsPage, NewsListPresenter>
  45. with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  46. BaseListProvider<NewsItem> provider = BaseListProvider<NewsItem>();
  47. TabController _tabController;
  48. PageController _pageController = PageController();
  49. AmapLocationFlutterPlugin _locationPlugin = new AmapLocationFlutterPlugin();
  50. StreamSubscription<Map<String, Object>> _locationListener;
  51. Map<String, Object> _locationResult;
  52. int _index = 0;
  53. String _keyword;
  54. int _page = 1;
  55. List<String> menuTitle = ["案例中心", "视频学堂", "在线商城", "招聘专区", "资料库"];
  56. List<int> menuImage = [0xe674, 0xe600, 0xe680, 0xe705, 0xe648];
  57. List<String> menuColor = [
  58. "0xffFE6965",
  59. "0xff5C6BFA",
  60. "0xffFA8113",
  61. "0xff2EBA7F",
  62. "0xff118DFF"
  63. ];
  64. bool display = true;
  65. // Location _location;
  66. String cityName = "暂无定位";
  67. StateType _stateType = StateType.loading;
  68. ///获取定位权限
  69. Future<bool> requestPermission() async {
  70. final permissions = await PermissionHandler()
  71. .requestPermissions([PermissionGroup.location]);
  72. if (permissions[PermissionGroup.location] == PermissionStatus.granted) {
  73. return true;
  74. } else {
  75. toasts('需要定位权限!');
  76. return false;
  77. }
  78. }
  79. ///获取位置信息
  80. getLocation() async {
  81. if (await requestPermission()) {
  82. if (null != _locationPlugin) {
  83. _locationPlugin.startLocation();
  84. }
  85. }
  86. }
  87. // ///获取位置信息
  88. // getLocation() async {
  89. // if (await requestPermission()) {
  90. // final location = await AmapLocation.fetchLocation();
  91. // cityName = await location.city;
  92. // print(cityName + "456456465");
  93. // LatLng latlng = await location.latLng;
  94. // print(latlng.latitude);
  95. // print(latlng.longitude);
  96. // print(latlng);
  97. // setState(() {});
  98. // // getCity();
  99. // }
  100. // }
  101. // getCity() async {
  102. // LatLng latlng = await _location.latLng;
  103. // ApiService().getCity(latlng.latitude,latlng.longitude,onSuccess: (res){
  104. //
  105. // },onError: (code,msg){
  106. //
  107. // });
  108. // }
  109. @override
  110. void initState() {
  111. super.initState();
  112. ///移除定位监听
  113. if (null != _locationListener) {
  114. _locationListener.cancel();
  115. }
  116. ///销毁定位
  117. if (null != _locationPlugin) {
  118. _locationPlugin.destroy();
  119. }
  120. _locationListener = _locationPlugin
  121. .onLocationChanged()
  122. .listen((Map<String, Object> result) {
  123. setState(() {
  124. _locationPlugin.stopLocation();
  125. _locationResult = result;
  126. // address latitude longitude
  127. lat = _locationResult["latitude"];
  128. lng = _locationResult["longitude"];
  129. cityName = _locationResult["city"];
  130. if(FlutterStars.SpUtil.getString(Constant.userId) != "-1") {
  131. isDelayAddress();
  132. }
  133. });
  134. });
  135. if(FlutterStars.SpUtil.getString(Constant.userId) != "-1") {
  136. Provider.of<WebSocketProvide>(context,listen: false).createWebsocket(FlutterStars.SpUtil.getString(Constant.userId));
  137. }
  138. getLocation();
  139. getBannerList();
  140. getNewsList();
  141. getQuestionList();
  142. getVideoList();
  143. getShopList();
  144. getPositionList();
  145. getNotificaList();
  146. _initFluwx();
  147. FastNotification.addListener("initNotice",(initThisNotice){
  148. if(mounted){
  149. setState(() {
  150. getNotificaList();
  151. });
  152. }
  153. });
  154. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  155. isCustom = true;
  156. }
  157. }
  158. _initFluwx() async {
  159. await fluwx.registerWxApi(
  160. appId: "wx0f10e6386fb9969e",
  161. doOnAndroid: true,
  162. doOnIOS: true,
  163. universalLink: "https://www.edtyun.com/");
  164. var result = await fluwx.isWeChatInstalled();
  165. setState(() {});
  166. }
  167. Timer _timer;
  168. void startTimer(int intervalTime) {
  169. //设置 intervalTime 秒回调一次
  170. print(1234);
  171. Duration period = Duration(minutes: intervalTime);
  172. _timer = Timer.periodic(period, (timer) {
  173. print(1236);
  174. getStartDelayAddress();
  175. });
  176. }
  177. void cancelTimer() {
  178. if (_timer != null) {
  179. _timer.cancel();
  180. _timer = null;
  181. }
  182. }
  183. double lat;
  184. double lng;
  185. Widget bannerLastWidget;
  186. List<dynamic> bannerList;
  187. List<dynamic> questionsList;
  188. List<dynamic> newsList;
  189. List<dynamic> videoList;
  190. List<dynamic> shopList;
  191. List<dynamic> positionList;
  192. bool isCustom = false;
  193. Future isDelayAddress() async {
  194. await NewApiService().isDelayAddress(onSuccess: (res) {
  195. print("665-------------------////");
  196. print(res["id"]);
  197. print(jsonEncode(res));
  198. print("666-------------------////");
  199. if(res["isPush"]!=null && res["isPush"] == 1){
  200. getStartDelayAddress();
  201. startTimer(res["intervalTime"]);
  202. }
  203. //intervalTime:时间间隔分钟 ; isPush:1推送 2不推送
  204. }, onError: (code, msg) {
  205. toasts(msg);
  206. });
  207. }
  208. Future getStartDelayAddress() async {
  209. String position = lat.toString() +","+ lng.toString();
  210. await NewApiService().startDelayAddress(
  211. {
  212. "mobile":FlutterStars.SpUtil.getString(Constant.phone),
  213. "mtCompanyId":FlutterStars.SpUtil.getString(Constant.companyId)!=""?int.parse(FlutterStars.SpUtil.getString(Constant.companyId)):"",
  214. "position":position,
  215. "userId":int.parse(FlutterStars.SpUtil.getString(Constant.userId))
  216. }
  217. ,onSuccess: (res) {
  218. print("668-------------------////");
  219. }, onError: (code, msg) {
  220. toasts(msg);
  221. });
  222. }
  223. Future getBannerList() async {
  224. await NewApiService().getBanner(1, 10, onSuccess: (BannerModel res) {
  225. // print(jsonEncode(res));
  226. // print(JsonEncoder().convert(res.records));
  227. bannerList = res.records;
  228. bannerLastWidget = SwipeWidget(banners: bannerList,);
  229. // print(bannerList.length);
  230. setState(() {});
  231. }, onError: (code, msg) {
  232. toasts(msg);
  233. });
  234. }
  235. Future getNotificaList() async {
  236. display = true;
  237. await NewApiService().myNotificaList(1, 10, onSuccess: (res) {
  238. // print(jsonEncode(res));
  239. // print(JsonEncoder().convert(res.records));
  240. res.records.forEach((item){
  241. if(item.viewFlag == 0){
  242. setState(() {
  243. display = false;
  244. });
  245. return;
  246. }
  247. });
  248. // print(bannerList.length);
  249. setState(() {});
  250. }, onError: (code, msg) {
  251. toasts(msg);
  252. });
  253. }
  254. Future getNewsList() async {
  255. await NewApiService().newsList(1, 3, 1, "", cityName, onSuccess: (res) {
  256. newsList = res.topNews;
  257. // print(JsonEncoder().convert(res.topNews));
  258. setState(() {});
  259. }, onError: (code, msg) {
  260. toasts(msg);
  261. });
  262. }
  263. Future getQuestionList() async {
  264. await NewApiService().getQuestionList(1, 2, null, null, null,
  265. onSuccess: (res) {
  266. // res.records.forEach((item){
  267. // questionsList.addAll(item);
  268. // });
  269. questionsList = res.records;
  270. // print(JsonEncoder().convert(res.records));
  271. setState(() {});
  272. }, onError: (code, msg) {
  273. toasts(msg);
  274. });
  275. }
  276. Future getVideoList() async {
  277. await NewApiService().getVideoList(1, 3, null, null, null, "app",
  278. onSuccess: (res) {
  279. videoList = res.records;
  280. setState(() {});
  281. }, onError: (code, msg) {
  282. toasts(msg);
  283. });
  284. }
  285. Future getShopList() async {
  286. await NewApiService().getShopList(1, 2, null, null, onSuccess: (res) {
  287. shopList = res.records;
  288. setState(() {});
  289. }, onError: (code, msg) {
  290. toasts(msg);
  291. });
  292. }
  293. Future getPositionList() async {
  294. await NewApiService().getPositionList(1, 3, onSuccess: (res) {
  295. // res.records.forEach((item){
  296. // questionsList.addAll(item);
  297. // });
  298. positionList = res.records;
  299. // print(JsonEncoder().convert(res.records));
  300. setState(() {});
  301. }, onError: (code, msg) {
  302. toasts(msg);
  303. });
  304. }
  305. void _onPageChanged(int index) {
  306. _index = index;
  307. _tabController.animateTo(index);
  308. }
  309. @override
  310. void dispose() {
  311. _tabController?.dispose();
  312. // _timer.cancel();
  313. _pageController.dispose();
  314. ///移除定位监听
  315. if (null != _locationListener) {
  316. _locationListener.cancel();
  317. }
  318. ///销毁定位
  319. if (null != _locationPlugin) {
  320. _locationPlugin.destroy();
  321. }
  322. super.dispose();
  323. cancelTimer();
  324. }
  325. static const diagnosisObj = [
  326. {
  327. "title": "快速问诊",
  328. "img": "tab_first/Diagnosis_first",
  329. "desc": "搜电梯品牌 找专家咨询电梯疑问",
  330. },
  331. {
  332. "title": "出诊",
  333. "img": "tab_first/Diagnosis_second",
  334. "desc": "在线预约专家上门维修服务",
  335. },
  336. ];
  337. static const diagnosisObjMaster = [
  338. {
  339. "title": "工作台",
  340. "img": "tab_first/Diagnosis_third",
  341. "desc": "问诊、出诊工作快捷入口",
  342. },
  343. ];
  344. showAlertEvent(){
  345. showAlert(
  346. context,
  347. "提示",
  348. "确定登录?",
  349. "确定",
  350. () {
  351. NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  352. },
  353. txt2: "取消",
  354. onPre2: () {
  355. NavigatorUtils.goBack(context);
  356. },
  357. );
  358. }
  359. @override
  360. Widget build(BuildContext context) {
  361. return
  362. RefreshIndicator(
  363. onRefresh:()async{
  364. print("123----------------------------------");
  365. setState(() {
  366. bannerLastWidget = null;
  367. getLocation();
  368. getBannerList();
  369. getNewsList();
  370. getQuestionList();
  371. getVideoList();
  372. getShopList();
  373. getPositionList();
  374. });
  375. },
  376. child: ChangeNotifierProvider<BaseListProvider<NewsItem>>(
  377. create: (_) => provider,
  378. child: Scaffold(
  379. appBar: AppCitySearchAppBar(
  380. // city: "暂无定位",
  381. city: "${cityName}",
  382. display:display
  383. ),
  384. body: Container(
  385. color: ThemeUtils.getTabsBg(context),
  386. child: ListView(
  387. children: <Widget>[
  388. bannerLastWidget != null
  389. ? bannerLastWidget
  390. : Container(child: loadCircle()),
  391. Container(
  392. padding: EdgeInsets.only(top: 10),
  393. color: ThemeUtils.getTabsBg(context),
  394. child: _ToolsItem(menuTitle, menuImage, menuColor, (index) {
  395. if (index == 0) {
  396. if (!Utils.getAuthByRouter('question_center',false) && isCustom){
  397. showAlertEvent();
  398. }else if (Utils.getAuthByRouter('question_center')){
  399. NavigatorUtils.push(context, BbsRouter.questionList);
  400. }
  401. } else if (index == 1) {
  402. // if (Utils.getAuthByRouter('video_center')) {
  403. // NavigatorUtils.push(context, BbsRouter.videoList);
  404. // }else if (!Utils.getAuthByRouter('video_center',false) && isCustom){
  405. // showAlertEvent();
  406. // }
  407. if (!Utils.getAuthByRouter('video_center',false) && isCustom){
  408. showAlertEvent();
  409. }else if (Utils.getAuthByRouter('video_center')){
  410. NavigatorUtils.push(context, BbsRouter.videoList);
  411. }
  412. } else if (index == 2) {
  413. // if (Utils.getAuthByRouter('shopping_center')) {
  414. // NavigatorUtils.push(context, BbsRouter.productList);
  415. // }else if (!Utils.getAuthByRouter('shopping_center',false) && isCustom){
  416. // showAlertEvent();
  417. // }
  418. if (!Utils.getAuthByRouter('shopping_center',false) && isCustom){
  419. showAlertEvent();
  420. }else if (Utils.getAuthByRouter('shopping_center')){
  421. NavigatorUtils.push(context, BbsRouter.productList);
  422. }
  423. } else if (index == 3) {
  424. // if (Utils.getAuthByRouter('job_center')) {
  425. // NavigatorUtils.push(context, BbsRouter.positionList);
  426. // }else if (!Utils.getAuthByRouter('job_center',false) && isCustom){
  427. // showAlertEvent();
  428. // }
  429. if (!Utils.getAuthByRouter('job_center',false) && isCustom){
  430. showAlertEvent();
  431. }else if (Utils.getAuthByRouter('job_center')){
  432. NavigatorUtils.push(context, BbsRouter.positionList);
  433. }
  434. } else if (index == 4) {
  435. if (!Utils.getAuthByRouter('database',false) && isCustom){
  436. showAlertEvent();
  437. }else if (Utils.getAuthByRouter('database')){
  438. NavigatorUtils.push(context, MeansRouter.meansPage);
  439. }
  440. }
  441. }),
  442. ),
  443. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  444. LableTitle(
  445. title: "新闻",
  446. userTap: () {
  447. if(isCustom){
  448. showAlertEvent();
  449. }else {
  450. NavigatorUtils.push(context, NewsRouter.newsTopList);
  451. }
  452. },
  453. ),
  454. Container(
  455. color: Colors.white,
  456. // padding: EdgeInsets.only(bottom: 20),
  457. child: newsList != null && newsList != []
  458. ? HotNews(newsList: newsList)
  459. : loadCircle()),
  460. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  461. LableTitle(
  462. title: "问题",
  463. userTap: () {
  464. if (!Utils.getAuthByRouter('question_center',false) && isCustom){
  465. showAlertEvent();
  466. }
  467. else {
  468. if (Utils.getAuthByRouter('question_center')) {
  469. NavigatorUtils.push(context, BbsRouter.questionList);
  470. }
  471. }
  472. // NavigatorUtils.push(context, BbsRouter.chatRoom);
  473. },
  474. ),
  475. // Expanded(
  476. // flex: 1,
  477. // child: HotQuestion(),
  478. // )
  479. Container(
  480. child: questionsList != null && questionsList != []
  481. ? HotQuestion(initList: questionsList)
  482. : loadCircle()),
  483. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  484. LableTitle(
  485. title: "学堂",
  486. userTap: () {
  487. if (!Utils.getAuthByRouter('video_center',false) && isCustom){
  488. showAlertEvent();
  489. }else {
  490. if (Utils.getAuthByRouter('video_center')) {
  491. NavigatorUtils.push(context, BbsRouter.videoList);
  492. }
  493. }
  494. },
  495. ),
  496. videoList != null && videoList != []
  497. ? Container(
  498. color: ThemeUtils.getTabsBg(context),
  499. height: ScreenUtil().setWidth(210),
  500. padding:
  501. EdgeInsets.only(top: ScreenUtil().setWidth(10)),
  502. child: HotClass(initList: videoList),
  503. )
  504. : Container(child: loadCircle()),
  505. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  506. LableTitle(
  507. title: "商品",
  508. userTap: () {
  509. // if(isCustom){
  510. // toasts("请登录");
  511. // NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  512. // }else {
  513. // if (Utils.getAuthByRouter('shopping_center')) {
  514. // NavigatorUtils.push(context, BbsRouter.productList);
  515. // }
  516. // }
  517. if (!Utils.getAuthByRouter('shopping_center',false) && isCustom){
  518. showAlertEvent();
  519. }
  520. else {
  521. if(Utils.getAuthByRouter('shopping_center')) {
  522. NavigatorUtils.push(context, BbsRouter.productList);
  523. }
  524. }
  525. },
  526. ),
  527. Container(
  528. child: shopList != null && shopList != []
  529. ? HotProduct(productList: shopList)
  530. : loadCircle()),
  531. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  532. LableTitle(
  533. title: "职位",
  534. userTap: () {
  535. // if(isCustom){
  536. // toasts("请登录");
  537. // NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  538. // }else {
  539. // if (Utils.getAuthByRouter('job_center')) {
  540. // NavigatorUtils.push(context, BbsRouter.positionList);
  541. // }
  542. // }
  543. if (!Utils.getAuthByRouter('job_center',false) && isCustom){
  544. showAlertEvent();
  545. }else {
  546. if (Utils.getAuthByRouter('job_center')) {
  547. NavigatorUtils.push(context, BbsRouter.positionList);
  548. }
  549. }
  550. },
  551. ),
  552. Container(
  553. color: ThemeUtils.getTabsBg(context),
  554. padding: EdgeInsets.only(bottom: 20),
  555. child: positionList != null && positionList != []
  556. ? HotPosition(positionList: positionList)
  557. : loadCircle()),
  558. // Container(
  559. // child:GestureDetector(
  560. // child: Text("0000000"),
  561. // onTap: (){
  562. // Map<String,dynamic> cc = FlutterStars.SpUtil.getObj("vgfhvfk", (v){
  563. // return v;
  564. // });
  565. // print(cc);
  566. // print(6556);
  567. // Map<String,dynamic> res = {
  568. // "one3":"1"
  569. // };
  570. // Map<String,dynamic> a = FlutterStars.SpUtil.getObj("sessionIdObj", (v){
  571. // return v;
  572. // });
  573. // a.addAll(res);
  574. // FlutterStars.SpUtil.putObject("sessionIdObj", a);
  575. // print(a["one3"]);
  576. // print(123);
  577. // },
  578. // )
  579. // ),
  580. // SizedBox(
  581. // height:300,
  582. // ),
  583. // Container(
  584. // child:GestureDetector(
  585. // child: Text("11111111"),
  586. // onTap: (){
  587. // Map<String,dynamic> res = {
  588. // "two3":"2"
  589. // };
  590. // Map<String,dynamic> a = FlutterStars.SpUtil.getObj("sessionIdObj", (v){
  591. // return v;
  592. // });
  593. // a.addAll(res);
  594. // FlutterStars.SpUtil.putObject("sessionIdObj", a);
  595. // print(a);
  596. // print(123);
  597. // print(123);
  598. // },
  599. // )
  600. // ),
  601. ],
  602. ),
  603. ),
  604. )),
  605. )
  606. ;
  607. }
  608. Widget loadCircle() {
  609. return Container(
  610. padding: EdgeInsets.only(top: 10, bottom: 10),
  611. color: ThemeUtils.getTabsBg(context),
  612. child: Center(
  613. child: SpinKitFadingCircle(
  614. color: Colors.blueAccent,
  615. size: 30.0,
  616. ),
  617. ),
  618. );
  619. }
  620. @override
  621. NewsListPresenter createPresenter() {
  622. return NewsListPresenter();
  623. }
  624. bool get wantKeepAlive => true;
  625. }
  626. class _ToolsItem extends StatelessWidget {
  627. _ToolsItem(this.titles, this.imgs, this.colors, this.onTap, {Key key})
  628. : super(key: key);
  629. List<String> titles;
  630. List<int> imgs;
  631. List<String> colors;
  632. Function onTap;
  633. @override
  634. Widget build(BuildContext context) {
  635. return GridView.builder(
  636. shrinkWrap: true,
  637. padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
  638. physics: NeverScrollableScrollPhysics(),
  639. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  640. crossAxisCount: 5, childAspectRatio: 0.9, crossAxisSpacing: 2),
  641. itemCount: titles.length,
  642. itemBuilder: (_, index) {
  643. return InkWell(
  644. child: Column(
  645. mainAxisAlignment: MainAxisAlignment.center,
  646. children: <Widget>[
  647. Container(
  648. width: ScreenUtil().setWidth(40),
  649. height: ScreenUtil().setWidth(40),
  650. decoration: BoxDecoration(
  651. borderRadius: BorderRadius.circular(20.0),
  652. color: Color(
  653. int.parse(colors[index]),
  654. ),
  655. ),
  656. child: Icon(
  657. IconData(imgs[index], fontFamily: "myfont"),
  658. size: 22.0,
  659. color: Color.fromRGBO(255, 255, 255, 1),
  660. ),
  661. ),
  662. Gaps.vGap8,
  663. Text(
  664. titles[index],
  665. style: TextStyle(fontSize: ScreenUtil().setSp(12)),
  666. ),
  667. Gaps.vGap10,
  668. ],
  669. ),
  670. onTap: () {
  671. onTap(index);
  672. },
  673. );
  674. },
  675. );
  676. }
  677. }