bbs_page.dart 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. Provider.of<WebSocketProvide>(context,listen: false).createWebsocket(FlutterStars.SpUtil.getString(Constant.userId));
  136. getLocation();
  137. getBannerList();
  138. getNewsList();
  139. getQuestionList();
  140. getVideoList();
  141. getShopList();
  142. getPositionList();
  143. getNotificaList();
  144. _initFluwx();
  145. FastNotification.addListener("initNotice",(initThisNotice){
  146. if(mounted){
  147. setState(() {
  148. getNotificaList();
  149. });
  150. }
  151. });
  152. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  153. isCustom = true;
  154. }
  155. }
  156. _initFluwx() async {
  157. await fluwx.registerWxApi(
  158. appId: "wx0f10e6386fb9969e",
  159. doOnAndroid: true,
  160. doOnIOS: true,
  161. universalLink: "https://www.edtyun.com/");
  162. var result = await fluwx.isWeChatInstalled();
  163. setState(() {});
  164. }
  165. Timer _timer;
  166. void startTimer(int intervalTime) {
  167. //设置 intervalTime 秒回调一次
  168. print(1234);
  169. Duration period = Duration(minutes: intervalTime);
  170. _timer = Timer.periodic(period, (timer) {
  171. print(1236);
  172. getStartDelayAddress();
  173. });
  174. }
  175. void cancelTimer() {
  176. if (_timer != null) {
  177. _timer.cancel();
  178. _timer = null;
  179. }
  180. }
  181. double lat;
  182. double lng;
  183. Widget bannerLastWidget;
  184. List<dynamic> bannerList;
  185. List<dynamic> questionsList;
  186. List<dynamic> newsList;
  187. List<dynamic> videoList;
  188. List<dynamic> shopList;
  189. List<dynamic> positionList;
  190. bool isCustom = false;
  191. Future isDelayAddress() async {
  192. await NewApiService().isDelayAddress(onSuccess: (res) {
  193. print("665-------------------////");
  194. print(res["id"]);
  195. print(jsonEncode(res));
  196. print("666-------------------////");
  197. if(res["isPush"]!=null && res["isPush"] == 1){
  198. getStartDelayAddress();
  199. startTimer(res["intervalTime"]);
  200. }
  201. //intervalTime:时间间隔分钟 ; isPush:1推送 2不推送
  202. }, onError: (code, msg) {
  203. toasts(msg);
  204. });
  205. }
  206. Future getStartDelayAddress() async {
  207. String position = lat.toString() +","+ lng.toString();
  208. await NewApiService().startDelayAddress(
  209. {
  210. "mobile":FlutterStars.SpUtil.getString(Constant.phone),
  211. "mtCompanyId":FlutterStars.SpUtil.getString(Constant.companyId)!=""?int.parse(FlutterStars.SpUtil.getString(Constant.companyId)):"",
  212. "position":position,
  213. "userId":int.parse(FlutterStars.SpUtil.getString(Constant.userId))
  214. }
  215. ,onSuccess: (res) {
  216. print("668-------------------////");
  217. }, onError: (code, msg) {
  218. toasts(msg);
  219. });
  220. }
  221. Future getBannerList() async {
  222. await NewApiService().getBanner(1, 10, onSuccess: (BannerModel res) {
  223. // print(jsonEncode(res));
  224. // print(JsonEncoder().convert(res.records));
  225. bannerList = res.records;
  226. bannerLastWidget = SwipeWidget(banners: bannerList,);
  227. // print(bannerList.length);
  228. setState(() {});
  229. }, onError: (code, msg) {
  230. toasts(msg);
  231. });
  232. }
  233. Future getNotificaList() async {
  234. display = true;
  235. await NewApiService().myNotificaList(1, 10, onSuccess: (res) {
  236. // print(jsonEncode(res));
  237. // print(JsonEncoder().convert(res.records));
  238. res.records.forEach((item){
  239. if(item.viewFlag == 0){
  240. setState(() {
  241. display = false;
  242. });
  243. return;
  244. }
  245. });
  246. // print(bannerList.length);
  247. setState(() {});
  248. }, onError: (code, msg) {
  249. toasts(msg);
  250. });
  251. }
  252. Future getNewsList() async {
  253. await NewApiService().newsList(1, 3, 1, "", cityName, onSuccess: (res) {
  254. newsList = res.topNews;
  255. // print(JsonEncoder().convert(res.topNews));
  256. setState(() {});
  257. }, onError: (code, msg) {
  258. toasts(msg);
  259. });
  260. }
  261. Future getQuestionList() async {
  262. await NewApiService().getQuestionList(1, 2, null, null, null,
  263. onSuccess: (res) {
  264. // res.records.forEach((item){
  265. // questionsList.addAll(item);
  266. // });
  267. questionsList = res.records;
  268. // print(JsonEncoder().convert(res.records));
  269. setState(() {});
  270. }, onError: (code, msg) {
  271. toasts(msg);
  272. });
  273. }
  274. Future getVideoList() async {
  275. await NewApiService().getVideoList(1, 3, null, null, null, "app",
  276. onSuccess: (res) {
  277. videoList = res.records;
  278. setState(() {});
  279. }, onError: (code, msg) {
  280. toasts(msg);
  281. });
  282. }
  283. Future getShopList() async {
  284. await NewApiService().getShopList(1, 2, null, null, onSuccess: (res) {
  285. shopList = res.records;
  286. setState(() {});
  287. }, onError: (code, msg) {
  288. toasts(msg);
  289. });
  290. }
  291. Future getPositionList() async {
  292. await NewApiService().getPositionList(1, 3, onSuccess: (res) {
  293. // res.records.forEach((item){
  294. // questionsList.addAll(item);
  295. // });
  296. positionList = res.records;
  297. // print(JsonEncoder().convert(res.records));
  298. setState(() {});
  299. }, onError: (code, msg) {
  300. toasts(msg);
  301. });
  302. }
  303. void _onPageChanged(int index) {
  304. _index = index;
  305. _tabController.animateTo(index);
  306. }
  307. @override
  308. void dispose() {
  309. _tabController?.dispose();
  310. // _timer.cancel();
  311. _pageController.dispose();
  312. ///移除定位监听
  313. if (null != _locationListener) {
  314. _locationListener.cancel();
  315. }
  316. ///销毁定位
  317. if (null != _locationPlugin) {
  318. _locationPlugin.destroy();
  319. }
  320. super.dispose();
  321. cancelTimer();
  322. }
  323. static const diagnosisObj = [
  324. {
  325. "title": "快速问诊",
  326. "img": "tab_first/Diagnosis_first",
  327. "desc": "搜电梯品牌 找专家咨询电梯疑问",
  328. },
  329. {
  330. "title": "出诊",
  331. "img": "tab_first/Diagnosis_second",
  332. "desc": "在线预约专家上门维修服务",
  333. },
  334. ];
  335. static const diagnosisObjMaster = [
  336. {
  337. "title": "工作台",
  338. "img": "tab_first/Diagnosis_third",
  339. "desc": "问诊、出诊工作快捷入口",
  340. },
  341. ];
  342. showAlertEvent(){
  343. showAlert(
  344. context,
  345. "提示",
  346. "确定登录?",
  347. "确定",
  348. () {
  349. NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  350. },
  351. txt2: "取消",
  352. onPre2: () {
  353. NavigatorUtils.goBack(context);
  354. },
  355. );
  356. }
  357. @override
  358. Widget build(BuildContext context) {
  359. return
  360. RefreshIndicator(
  361. onRefresh:()async{
  362. print("123----------------------------------");
  363. setState(() {
  364. bannerLastWidget = null;
  365. getLocation();
  366. getBannerList();
  367. getNewsList();
  368. getQuestionList();
  369. getVideoList();
  370. getShopList();
  371. getPositionList();
  372. });
  373. },
  374. child: ChangeNotifierProvider<BaseListProvider<NewsItem>>(
  375. create: (_) => provider,
  376. child: Scaffold(
  377. appBar: AppCitySearchAppBar(
  378. // city: "暂无定位",
  379. city: "${cityName}",
  380. display:display
  381. ),
  382. body: Container(
  383. color: ThemeUtils.getTabsBg(context),
  384. child: ListView(
  385. children: <Widget>[
  386. bannerLastWidget != null
  387. ? bannerLastWidget
  388. : Container(child: loadCircle()),
  389. Container(
  390. padding: EdgeInsets.only(top: 10),
  391. color: ThemeUtils.getTabsBg(context),
  392. child: _ToolsItem(menuTitle, menuImage, menuColor, (index) {
  393. if (index == 0) {
  394. if (!Utils.getAuthByRouter('question_center',false) && isCustom){
  395. showAlertEvent();
  396. }else if (Utils.getAuthByRouter('question_center')){
  397. NavigatorUtils.push(context, BbsRouter.questionList);
  398. }
  399. } else if (index == 1) {
  400. // if (Utils.getAuthByRouter('video_center')) {
  401. // NavigatorUtils.push(context, BbsRouter.videoList);
  402. // }else if (!Utils.getAuthByRouter('video_center',false) && isCustom){
  403. // showAlertEvent();
  404. // }
  405. if (!Utils.getAuthByRouter('video_center',false) && isCustom){
  406. showAlertEvent();
  407. }else if (Utils.getAuthByRouter('video_center')){
  408. NavigatorUtils.push(context, BbsRouter.videoList);
  409. }
  410. } else if (index == 2) {
  411. // if (Utils.getAuthByRouter('shopping_center')) {
  412. // NavigatorUtils.push(context, BbsRouter.productList);
  413. // }else if (!Utils.getAuthByRouter('shopping_center',false) && isCustom){
  414. // showAlertEvent();
  415. // }
  416. if (!Utils.getAuthByRouter('shopping_center',false) && isCustom){
  417. showAlertEvent();
  418. }else if (Utils.getAuthByRouter('shopping_center')){
  419. NavigatorUtils.push(context, BbsRouter.productList);
  420. }
  421. } else if (index == 3) {
  422. // if (Utils.getAuthByRouter('job_center')) {
  423. // NavigatorUtils.push(context, BbsRouter.positionList);
  424. // }else if (!Utils.getAuthByRouter('job_center',false) && isCustom){
  425. // showAlertEvent();
  426. // }
  427. if (!Utils.getAuthByRouter('job_center',false) && isCustom){
  428. showAlertEvent();
  429. }else if (Utils.getAuthByRouter('job_center')){
  430. NavigatorUtils.push(context, BbsRouter.positionList);
  431. }
  432. } else if (index == 4) {
  433. if (!Utils.getAuthByRouter('database',false) && isCustom){
  434. showAlertEvent();
  435. }else if (Utils.getAuthByRouter('database')){
  436. NavigatorUtils.push(context, MeansRouter.meansPage);
  437. }
  438. }
  439. }),
  440. ),
  441. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  442. LableTitle(
  443. title: "新闻",
  444. userTap: () {
  445. if(isCustom){
  446. showAlertEvent();
  447. }else {
  448. NavigatorUtils.push(context, NewsRouter.newsTopList);
  449. }
  450. },
  451. ),
  452. Container(
  453. color: Colors.white,
  454. // padding: EdgeInsets.only(bottom: 20),
  455. child: newsList != null && newsList != []
  456. ? HotNews(newsList: newsList)
  457. : loadCircle()),
  458. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  459. LableTitle(
  460. title: "问题",
  461. userTap: () {
  462. if (!Utils.getAuthByRouter('question_center',false) && isCustom){
  463. showAlertEvent();
  464. }
  465. else {
  466. if (Utils.getAuthByRouter('question_center')) {
  467. NavigatorUtils.push(context, BbsRouter.questionList);
  468. }
  469. }
  470. // NavigatorUtils.push(context, BbsRouter.chatRoom);
  471. },
  472. ),
  473. // Expanded(
  474. // flex: 1,
  475. // child: HotQuestion(),
  476. // )
  477. Container(
  478. child: questionsList != null && questionsList != []
  479. ? HotQuestion(initList: questionsList)
  480. : loadCircle()),
  481. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  482. LableTitle(
  483. title: "学堂",
  484. userTap: () {
  485. if (!Utils.getAuthByRouter('video_center',false) && isCustom){
  486. showAlertEvent();
  487. }else {
  488. if (Utils.getAuthByRouter('video_center')) {
  489. NavigatorUtils.push(context, BbsRouter.videoList);
  490. }
  491. }
  492. },
  493. ),
  494. videoList != null && videoList != []
  495. ? Container(
  496. color: ThemeUtils.getTabsBg(context),
  497. height: ScreenUtil().setWidth(210),
  498. padding:
  499. EdgeInsets.only(top: ScreenUtil().setWidth(10)),
  500. child: HotClass(initList: videoList),
  501. )
  502. : Container(child: loadCircle()),
  503. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  504. LableTitle(
  505. title: "商品",
  506. userTap: () {
  507. // if(isCustom){
  508. // toasts("请登录");
  509. // NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  510. // }else {
  511. // if (Utils.getAuthByRouter('shopping_center')) {
  512. // NavigatorUtils.push(context, BbsRouter.productList);
  513. // }
  514. // }
  515. if (!Utils.getAuthByRouter('shopping_center',false) && isCustom){
  516. showAlertEvent();
  517. }
  518. else {
  519. if(Utils.getAuthByRouter('shopping_center')) {
  520. NavigatorUtils.push(context, BbsRouter.productList);
  521. }
  522. }
  523. },
  524. ),
  525. Container(
  526. child: shopList != null && shopList != []
  527. ? HotProduct(productList: shopList)
  528. : loadCircle()),
  529. Container(height: 5, color: ThemeUtils.getDialogTextFieldColor(context)),
  530. LableTitle(
  531. title: "职位",
  532. userTap: () {
  533. // if(isCustom){
  534. // toasts("请登录");
  535. // NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  536. // }else {
  537. // if (Utils.getAuthByRouter('job_center')) {
  538. // NavigatorUtils.push(context, BbsRouter.positionList);
  539. // }
  540. // }
  541. if (!Utils.getAuthByRouter('job_center',false) && isCustom){
  542. showAlertEvent();
  543. }else {
  544. if (Utils.getAuthByRouter('job_center')) {
  545. NavigatorUtils.push(context, BbsRouter.positionList);
  546. }
  547. }
  548. },
  549. ),
  550. Container(
  551. color: ThemeUtils.getTabsBg(context),
  552. padding: EdgeInsets.only(bottom: 20),
  553. child: positionList != null && positionList != []
  554. ? HotPosition(positionList: positionList)
  555. : loadCircle()),
  556. // Container(
  557. // child:GestureDetector(
  558. // child: Text("0000000"),
  559. // onTap: (){
  560. // Map<String,dynamic> cc = FlutterStars.SpUtil.getObj("vgfhvfk", (v){
  561. // return v;
  562. // });
  563. // print(cc);
  564. // print(6556);
  565. // Map<String,dynamic> res = {
  566. // "one3":"1"
  567. // };
  568. // Map<String,dynamic> a = FlutterStars.SpUtil.getObj("sessionIdObj", (v){
  569. // return v;
  570. // });
  571. // a.addAll(res);
  572. // FlutterStars.SpUtil.putObject("sessionIdObj", a);
  573. // print(a["one3"]);
  574. // print(123);
  575. // },
  576. // )
  577. // ),
  578. // SizedBox(
  579. // height:300,
  580. // ),
  581. // Container(
  582. // child:GestureDetector(
  583. // child: Text("11111111"),
  584. // onTap: (){
  585. // Map<String,dynamic> res = {
  586. // "two3":"2"
  587. // };
  588. // Map<String,dynamic> a = FlutterStars.SpUtil.getObj("sessionIdObj", (v){
  589. // return v;
  590. // });
  591. // a.addAll(res);
  592. // FlutterStars.SpUtil.putObject("sessionIdObj", a);
  593. // print(a);
  594. // print(123);
  595. // print(123);
  596. // },
  597. // )
  598. // ),
  599. ],
  600. ),
  601. ),
  602. )),
  603. )
  604. ;
  605. }
  606. Widget loadCircle() {
  607. return Container(
  608. padding: EdgeInsets.only(top: 10, bottom: 10),
  609. color: ThemeUtils.getTabsBg(context),
  610. child: Center(
  611. child: SpinKitFadingCircle(
  612. color: Colors.blueAccent,
  613. size: 30.0,
  614. ),
  615. ),
  616. );
  617. }
  618. @override
  619. NewsListPresenter createPresenter() {
  620. return NewsListPresenter();
  621. }
  622. bool get wantKeepAlive => true;
  623. }
  624. class _ToolsItem extends StatelessWidget {
  625. _ToolsItem(this.titles, this.imgs, this.colors, this.onTap, {Key key})
  626. : super(key: key);
  627. List<String> titles;
  628. List<int> imgs;
  629. List<String> colors;
  630. Function onTap;
  631. @override
  632. Widget build(BuildContext context) {
  633. return GridView.builder(
  634. shrinkWrap: true,
  635. padding: const EdgeInsets.fromLTRB(8.0, 0, 8.0, 0),
  636. physics: NeverScrollableScrollPhysics(),
  637. gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
  638. crossAxisCount: 5, childAspectRatio: 0.9, crossAxisSpacing: 2),
  639. itemCount: titles.length,
  640. itemBuilder: (_, index) {
  641. return InkWell(
  642. child: Column(
  643. mainAxisAlignment: MainAxisAlignment.center,
  644. children: <Widget>[
  645. Container(
  646. width: ScreenUtil().setWidth(40),
  647. height: ScreenUtil().setWidth(40),
  648. decoration: BoxDecoration(
  649. borderRadius: BorderRadius.circular(20.0),
  650. color: Color(
  651. int.parse(colors[index]),
  652. ),
  653. ),
  654. child: Icon(
  655. IconData(imgs[index], fontFamily: "myfont"),
  656. size: 22.0,
  657. color: Color.fromRGBO(255, 255, 255, 1),
  658. ),
  659. ),
  660. Gaps.vGap8,
  661. Text(
  662. titles[index],
  663. style: TextStyle(fontSize: ScreenUtil().setSp(12)),
  664. ),
  665. Gaps.vGap10,
  666. ],
  667. ),
  668. onTap: () {
  669. onTap(index);
  670. },
  671. );
  672. },
  673. );
  674. }
  675. }