means_page.dart 16 KB

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