means_page.dart 16 KB

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