From 158892393a4ba6c5d3316068ceac1c424f66ff8e Mon Sep 17 00:00:00 2001 From: hanandjun Date: Tue, 13 Oct 2020 15:04:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96=E7=BA=BF?= =?UTF-8?q?=E8=B7=AF=E7=9A=84=E6=97=B6=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 嗯哼,曲线救国 --- lib/view/home/home_page.dart | 105 +++++++++++++-------------- lib/view/home/line/route_detail.dart | 2 +- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/lib/view/home/home_page.dart b/lib/view/home/home_page.dart index 758834b..2ba0d1d 100644 --- a/lib/view/home/home_page.dart +++ b/lib/view/home/home_page.dart @@ -20,8 +20,8 @@ import 'package:weifangbus/view/home/guide/guide.dart'; import 'package:weifangbus/view/home/line/route_detail.dart'; import 'package:weifangbus/view/home/news/news_detail.dart'; import 'package:weifangbus/view/home/news/news_list.dart'; -import 'package:weifangbus/view/home/searchbar/search_input.dart'; import 'package:weifangbus/view/home/searchbar/search_bar.dart'; +import 'package:weifangbus/view/home/searchbar/search_input.dart'; import 'package:weifangbus/view/store/news_model.dart'; /// 首页 @@ -33,13 +33,13 @@ class HomePage extends StatefulWidget { class _HomePageState extends State with AutomaticKeepAliveClientMixin { /// 菜单项 - List menuEntityList = List(); + List _menuEntityList = List(); /// 初始页json数据实体类 Future _startUpBasicInfoFuture; /// 所有线路 - List> allRouteList = List(); + List> _allRouteList = List(); /// [_startUpBasicInfoFuture] 请求成功后的数据 StartUpBasicInfoEntity _startUpBasicInfoEntity; @@ -58,7 +58,7 @@ class _HomePageState extends State super.initState(); setMenuEntityList(); _startUpBasicInfoFuture = _getStartUpBasicInfoFuture(); - getAllRoute(); + // getAllRoute(); } @override @@ -89,7 +89,7 @@ class _HomePageState extends State child: MaterialSearch( barBackgroundColor: Theme.of(context).primaryColor, placeholder: "搜索线路", - results: allRouteList, + results: _allRouteList, filter: (dynamic value, String criteria) { return value.toLowerCase().trim().contains( RegExp(r'' + criteria.toLowerCase().trim() + '')); @@ -101,7 +101,7 @@ class _HomePageState extends State ); }, ); - menuEntityList.add(lineInquiry); + _menuEntityList.add(lineInquiry); MenuEntity guide = MenuEntity( Colors.lightBlue, MyIcons.guide, @@ -117,7 +117,7 @@ class _HomePageState extends State ); }, ); - menuEntityList.add(guide); + _menuEntityList.add(guide); MenuEntity news = MenuEntity( Colors.orangeAccent, MyIcons.news, @@ -133,7 +133,7 @@ class _HomePageState extends State ); }, ); - menuEntityList.add(news); + _menuEntityList.add(news); } /// 请求首页数据 @@ -141,6 +141,8 @@ class _HomePageState extends State var connectivityResult = await (Connectivity().checkConnectivity()); if (connectivityResult != ConnectivityResult.none) { try { + // todo 应该作用线路搜索页上 + _getAllRoute(); var uri = "/BusService/Query_StartUpBasicInfo?" + getSignString(); Response response = await dio.get(uri); var startUpBasicInfoEntity = @@ -162,54 +164,51 @@ class _HomePageState extends State } /// 请求所有的路线 - void getAllRoute() async { - try { - Response response; - var uri = "/BusService/Require_AllRouteData/?" + getSignString(); - // print('$uri'); - response = await dio.get(uri); - AllroutedataEntity allRouteDataEntity = - EntityFactory.generateOBJ(response.data); - print("请求全部线路完成"); - setState(() { - var routeList = allRouteDataEntity.routelist; - for (var i = 0; i < routeList.length; ++i) { - var route = routeList[i]; - var materialSearchResult = MaterialSearchResult( - index: i, - value: route.routename, - // icon: Icons.directions_bus, - routeName: route.routename, - routeNameExt: route.routenameext.substring( - route.routenameext.indexOf('(') + 1, - route.routenameext.length - 1), - onTap: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) { - return RouteDetail( - title: route.routenameext, - routeId: route.routeid, - ); - }, - ), - ); - }, + _getAllRoute() async { + Response response; + var uri = "/BusService/Require_AllRouteData/?" + getSignString(); + // print('$uri'); + response = await dio.get(uri); + AllroutedataEntity allRouteDataEntity = + EntityFactory.generateOBJ(response.data); + print("请求全部线路完成"); + var routeList = allRouteDataEntity.routelist; + List> materialSearchResultList = List(); + for (var i = 0; i < routeList.length; ++i) { + var route = routeList[i]; + var materialSearchResult = MaterialSearchResult( + index: i, + value: route.routename, + // icon: Icons.directions_bus, + routeName: route.routename, + routeNameExt: route.routenameext.substring( + route.routenameext.indexOf('(') + 1, route.routenameext.length - 1), + onTap: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) { + return RouteDetail( + title: route.routenameext, + routeId: route.routeid, + ); + }, + ), ); - allRouteList.add(materialSearchResult); - } - }); - } catch (e) { - print('请求所有的路线异常::: $e'); + }, + ); + materialSearchResultList.add(materialSearchResult); } + setState(() { + _allRouteList = materialSearchResultList; + }); } /// 重试处理 reTry() { setState(() { _startUpBasicInfoFuture = _getStartUpBasicInfoFuture(); - getAllRoute(); Future.microtask(() => context.read().refreshNewsList()); + // getAllRoute(); }); } @@ -420,7 +419,7 @@ class _HomePageState extends State height: ScreenUtil().setHeight(180), child: DecoratedBox( decoration: BoxDecoration( - color: menuEntityList[index].color, + color: _menuEntityList[index].color, shape: BoxShape.circle, boxShadow: [ BoxShadow( @@ -434,7 +433,7 @@ class _HomePageState extends State ), child: Center( child: Icon( - menuEntityList[index].icon, + _menuEntityList[index].icon, size: ScreenUtil().setWidth(80), color: Colors.white, ), @@ -449,7 +448,7 @@ class _HomePageState extends State ScreenUtil().setHeight(0), ), child: Text( - menuEntityList[index].menuText, + _menuEntityList[index].menuText, style: TextStyle( fontSize: ScreenUtil().setSp(40), ), @@ -458,10 +457,10 @@ class _HomePageState extends State ], ), ), - onTap: menuEntityList[index].function, + onTap: _menuEntityList[index].function, ); }, - childCount: menuEntityList.length, + childCount: _menuEntityList.length, ), ), ); @@ -492,7 +491,7 @@ class _HomePageState extends State super.build(context); return Scaffold( appBar: AppBar( - title: SearchBar(allRouteList: allRouteList), + title: SearchBar(allRouteList: _allRouteList), ), body: FutureBuilder( future: _startUpBasicInfoFuture, diff --git a/lib/view/home/line/route_detail.dart b/lib/view/home/line/route_detail.dart index 6431f95..e7aaa16 100644 --- a/lib/view/home/line/route_detail.dart +++ b/lib/view/home/line/route_detail.dart @@ -297,7 +297,7 @@ class _RouteDetailState extends State flex: 6, child: AutoSizeText( e.stationname, - maxLines: 1, + maxLines: 2, overflow: TextOverflow.ellipsis, ), ),