means_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/gaps.dart';
  3. import 'package:liftmanager/net/api_service.dart';
  4. import 'package:liftmanager/utils/toast.dart';
  5. import 'package:liftmanager/widgets/app_bar.dart';
  6. import 'package:liftmanager/internal/search/search_router.dart';
  7. import 'package:liftmanager/widgets/app_search_bar.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/widgets/load_image.dart';
  11. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  12. import 'package:liftmanager/internal/means/means_router.dart';
  13. import 'package:liftmanager/widgets/bbs_content.dart';
  14. // import 'package:amap_all_fluttify/amap_all_fluttify.dart';
  15. import 'package:provider/provider.dart';
  16. import 'package:permission_handler/permission_handler.dart';
  17. import 'package:liftmanager/mvp/base_page_state.dart';
  18. import 'package:liftmanager/net/api_service.dart';
  19. import 'package:liftmanager/res/resources.dart';
  20. import 'package:liftmanager/internal/means/presenter/means_list_presenter.dart';
  21. import 'dart:async';
  22. import 'package:liftmanager/widgets/preview_images.dart';
  23. import 'dart:io';
  24. import 'package:flutter_screenutil/flutter_screenutil.dart';
  25. import 'package:liftmanager/utils/url.dart';
  26. import 'dart:convert';
  27. import 'package:flutter_spinkit/flutter_spinkit.dart';
  28. import 'package:liftmanager/utils/theme_utils.dart';
  29. import 'package:flutter/foundation.dart';
  30. import 'package:path_provider/path_provider.dart';
  31. import 'package:liftmanager/utils/utils.dart';
  32. import 'package:liftmanager/internal/means/page/means_pdf.dart';
  33. class MeansPage extends StatefulWidget {
  34. String index = "1";
  35. @override
  36. State<StatefulWidget> createState() {
  37. return MeansPageState();
  38. }
  39. }
  40. class MeansPageState extends State<MeansPage> with AutomaticKeepAliveClientMixin {
  41. // NewsDetailItem item = NewsDetailItem();
  42. ScrollController _scrollController = new ScrollController();
  43. String pathPDF = "";
  44. @override
  45. void initState() {
  46. super.initState();
  47. getBrandList();
  48. getControlList();
  49. getGuanList();
  50. }
  51. List<dynamic> brandListPage;
  52. Future getBrandList() async {
  53. await NewApiService().getBrandListPage(1, 8, onSuccess: (res) {
  54. brandListPage = res.records;
  55. setState(() {});
  56. }, onError: (code, msg) {
  57. toasts(msg);
  58. });
  59. }
  60. List<dynamic> controlListPage;
  61. List<dynamic> guanList;
  62. Future getControlList() async {
  63. await NewApiService().getControlListPage(1, 8, topFlag: 1, onSuccess: (res) {
  64. controlListPage = res.records;
  65. setState(() {});
  66. }, onError: (code, msg) {
  67. toasts(msg);
  68. });
  69. }
  70. Future getGuanList() async {
  71. await NewApiService().getMeansList(1,3,1, null, null,searchWord:"", onSuccess: (res) {
  72. guanList = res.records;
  73. setState(() {});
  74. }, onError: (code, msg) {
  75. toasts(msg);
  76. });
  77. }
  78. Future<File> createFileOfPdfUrl(url) async {
  79. final filename = url.substring(url.lastIndexOf("/") + 1);
  80. var request = await HttpClient().getUrl(Uri.parse(url));
  81. var response = await request.close();
  82. var bytes = await consolidateHttpClientResponseBytes(response);
  83. String dir = (await getApplicationDocumentsDirectory()).path;
  84. File file = new File('$dir/$filename');
  85. await file.writeAsBytes(bytes);
  86. return file;
  87. }
  88. @override
  89. void dispose() {
  90. _scrollController.dispose();
  91. super.dispose();
  92. }
  93. // @override
  94. // void initState() {
  95. // super.initState();
  96. // getNewsDetail();
  97. // }
  98. // getNewsDetail() {
  99. // ApiService().newsDetail(widget.id, onSuccess: (res) {
  100. // item = res;
  101. // setState(() {});
  102. // }, onError: (code, msg) {
  103. // toasts(msg);
  104. // });
  105. // }
  106. @override
  107. Widget build(BuildContext context) {
  108. double width = MediaQuery.of(context).size.width;
  109. return Scaffold(
  110. appBar: MyAppBar(
  111. centerTitle: "电梯资料库",
  112. isBack:true
  113. ),
  114. body:Container(
  115. child: Stack(
  116. children: <Widget>[
  117. Container(
  118. child:ListView(
  119. controller:_scrollController,
  120. children:<Widget>[
  121. LableTitle(
  122. title:"官方文件",
  123. userTap: (){
  124. NavigatorUtils.push(context, "${MeansRouter.meansList}?catagoryId=&dataTable=1&brandId=");
  125. },
  126. isMore: true,
  127. ),
  128. guanList != null && guanList != []? Container(
  129. child: Column(
  130. children: guanList.asMap().keys.map((index){
  131. return GestureDetector(
  132. child: Container(
  133. padding: EdgeInsets.only(
  134. left: ScreenUtil().setWidth(15),
  135. right: ScreenUtil().setWidth(15),
  136. top: ScreenUtil().setHeight(10),
  137. bottom: ScreenUtil().setHeight(10),
  138. ),
  139. decoration: BoxDecoration(
  140. border: Border(
  141. bottom:
  142. BorderSide(width: 0.5, color: Colours.line),
  143. ),
  144. ),
  145. child: Column(
  146. children: <Widget>[
  147. Container(
  148. padding: EdgeInsets.only(
  149. bottom: ScreenUtil().setHeight(5)),
  150. child: Row(
  151. mainAxisAlignment:
  152. MainAxisAlignment.spaceBetween,
  153. children: <Widget>[
  154. Container(
  155. padding: EdgeInsets.only(
  156. right: ScreenUtil().setWidth(10)),
  157. child: ClipRRect(
  158. borderRadius: BorderRadius.circular(
  159. ScreenUtil().setWidth(18)),
  160. child: Container(
  161. width: ScreenUtil().setWidth(36),
  162. height: ScreenUtil().setWidth(36),
  163. color: Color(0xffFAF7FA),
  164. // padding: EdgeInsets.only(right:10),
  165. child: Icon(
  166. IconData(0xe648,
  167. fontFamily: "myfont"),
  168. size: 24.0,
  169. color: Color(0xff53C3FA),
  170. ),
  171. ),
  172. ),
  173. ),
  174. Expanded(
  175. child: Text(
  176. guanList[index].name ?? '',
  177. textAlign: TextAlign.left,
  178. style: TextStyle(
  179. fontSize: ScreenUtil().setSp(14),
  180. ),
  181. ),
  182. ),
  183. ],
  184. ),
  185. ),
  186. ],
  187. ),
  188. ),
  189. onTap: () {
  190. var fileUrl = guanList[index].url;
  191. if (fileUrl != null && fileUrl != '') {
  192. fileUrl = Utils.getImagePath(guanList[index].url);
  193. print(fileUrl);
  194. if (Utils.getFileType(fileUrl) == 'image') {
  195. Navigator.of(context).push(
  196. new FadeRoute(
  197. page: PhotoViewGalleryScreen(
  198. images: [fileUrl], //传入图片list
  199. index: index, //传入当前点击的图片的index
  200. // heroTag: img,//传入当前点击的图片的hero tag (可选)
  201. ),
  202. ),
  203. );
  204. } else if (Utils.getFileType(fileUrl) == 'pdf') {
  205. createFileOfPdfUrl(fileUrl).then(
  206. (f) {
  207. setState(
  208. () {
  209. pathPDF = f.path;
  210. print(f.path);
  211. print("123456789-----");
  212. Navigator.push(
  213. context,
  214. MaterialPageRoute(
  215. builder: (context) =>
  216. PDFScreen(f.path, fileUrl,guanList[index].id.toString()),
  217. ),
  218. );
  219. },
  220. );
  221. },
  222. );
  223. }
  224. } else {
  225. toasts("暂无文件");
  226. }
  227. },
  228. );
  229. }).toList(),
  230. ),
  231. ):loadCircle(),
  232. Container(
  233. height:ScreenUtil().setWidth(5),
  234. color: ThemeUtils.getDialogTextFieldColor(context),
  235. ),
  236. LableTitle(
  237. title:"电梯品牌",
  238. userTap: (){
  239. NavigatorUtils.push(context, MeansRouter.brandList);
  240. },
  241. ),
  242. brandListPage != null && brandListPage != []?Brand(initList:brandListPage,fun:(id){
  243. NavigatorUtils.push(context, "${MeansRouter.brandDetail}?id=$id");
  244. }):loadCircle(),
  245. Container(
  246. height:ScreenUtil().setWidth(5),
  247. color: ThemeUtils.getDialogTextFieldColor(context),
  248. ),
  249. LableTitle(
  250. title:"控制系统",
  251. userTap: (){
  252. // NavigatorUtils.push(context, MeansRouter.controlList);
  253. NavigatorUtils.push(context, MeansRouter.controlList);
  254. },
  255. ),
  256. controlListPage != null && controlListPage != []?Brand(initList:controlListPage,fun:(id){
  257. NavigatorUtils.push(context, "${MeansRouter.controlDetail}?id=$id");
  258. }):loadCircle()
  259. ]
  260. ),
  261. ),
  262. ],
  263. )
  264. )
  265. );
  266. }
  267. Widget loadCircle() {
  268. return Container(
  269. padding: EdgeInsets.only(top: 10, bottom: 10),
  270. color: ThemeUtils.getTabsBg(context),
  271. child: Center(
  272. child: SpinKitFadingCircle(
  273. color: Colors.blueAccent,
  274. size: 30.0,
  275. ),
  276. ),
  277. );
  278. }
  279. @override
  280. bool get wantKeepAlive => true;
  281. }
  282. class Brand extends StatelessWidget {
  283. const Brand({Key key,this.initList,this.fun}) : super(key: key);
  284. final Function fun;
  285. final List<dynamic> initList;
  286. List<Widget> brandList(context) => initList.map((item){
  287. double width = MediaQuery.of(context).size.width;
  288. return Container(
  289. // color:Colors.yellow,
  290. child: FlatButton(
  291. padding: EdgeInsets.all(0),
  292. highlightColor:Colors.white,
  293. splashColor: Colors.white,
  294. child:Container(
  295. width: width/4,
  296. height: ScreenUtil().setWidth(100),
  297. // color: Colors.red,
  298. padding: EdgeInsets.only(left:ScreenUtil().setWidth(10),right:ScreenUtil().setWidth(10),top:ScreenUtil().setWidth(10)),
  299. child: Column(
  300. mainAxisAlignment: MainAxisAlignment.start,
  301. children:<Widget>[
  302. Container(
  303. // height: 70,
  304. // color: Colors.red,
  305. child: LoadNetworkImage(
  306. item.logo,
  307. width: ScreenUtil().setWidth(60),
  308. height:ScreenUtil().setWidth(50),
  309. // alignment: Alignment.centerLeft,
  310. ),
  311. ),
  312. Container(
  313. child: Text(
  314. item.name??"",
  315. style: TextStyle(
  316. color:Color(0xff666666),
  317. fontSize:ScreenUtil().setSp(15)
  318. ),
  319. textAlign:TextAlign.start,
  320. maxLines: 1,
  321. overflow: TextOverflow.ellipsis,
  322. ),
  323. ),
  324. ]
  325. ),
  326. ),
  327. onPressed: (){
  328. print(999);
  329. // NavigatorUtils.push(context, BbsRouter.visitPage);
  330. fun(item.id);
  331. },
  332. ),
  333. );
  334. }).toList();
  335. @override
  336. Widget build(BuildContext context) {
  337. return Container(
  338. padding: EdgeInsets.only(top:5),
  339. child: Wrap(
  340. // spacing: 16,
  341. alignment: WrapAlignment.start,
  342. crossAxisAlignment: WrapCrossAlignment.center,
  343. children: brandList(context),
  344. )
  345. );
  346. }
  347. }
  348. class FadeRoute extends PageRouteBuilder {
  349. final Widget page;
  350. FadeRoute({this.page})
  351. : super(
  352. pageBuilder: (
  353. BuildContext context,
  354. Animation<double> animation,
  355. Animation<double> secondaryAnimation,
  356. ) =>
  357. page,
  358. transitionsBuilder: (
  359. BuildContext context,
  360. Animation<double> animation,
  361. Animation<double> secondaryAnimation,
  362. Widget child,
  363. ) =>
  364. FadeTransition(
  365. opacity: animation,
  366. child: child,
  367. ),
  368. );
  369. }