means_page.dart 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. Navigator.push(
  206. context,
  207. MaterialPageRoute(
  208. builder: (context) => PDFScreen(
  209. f.path,
  210. fileUrl,
  211. guanList[index]
  212. .id
  213. .toString()),
  214. ),
  215. );
  216. },
  217. );
  218. },
  219. );
  220. }
  221. } else {
  222. toasts("暂无文件");
  223. }
  224. },
  225. );
  226. }).toList(),
  227. ),
  228. )
  229. : loadCircle(),
  230. Container(
  231. height: ScreenUtil().setWidth(5),
  232. color: ThemeUtils.getDialogTextFieldColor(context),
  233. ),
  234. SectionHeader(
  235. title: '电梯品牌',
  236. onTap: () {
  237. NavigatorUtils.push(context, MeansRouter.brandList);
  238. },
  239. showMore: true,
  240. ),
  241. brandListPage != null && brandListPage != []
  242. ? Brand(
  243. initList: brandListPage,
  244. fun: (id) {
  245. NavigatorUtils.push(
  246. context, "${MeansRouter.brandDetail}?id=$id");
  247. })
  248. : loadCircle(),
  249. Container(
  250. height: ScreenUtil().setWidth(5),
  251. color: ThemeUtils.getDialogTextFieldColor(context),
  252. ),
  253. SectionHeader(
  254. title: '控制系统',
  255. onTap: () {
  256. NavigatorUtils.push(context, MeansRouter.controlList);
  257. },
  258. showMore: true,
  259. ),
  260. controlListPage != null && controlListPage != []
  261. ? Brand(
  262. initList: controlListPage,
  263. fun: (id) {
  264. NavigatorUtils.push(
  265. context, "${MeansRouter.controlDetail}?id=$id");
  266. })
  267. : loadCircle()
  268. ]),
  269. ),
  270. ],
  271. )));
  272. }
  273. Widget loadCircle() {
  274. return Container(
  275. padding: EdgeInsets.only(top: 10, bottom: 10),
  276. color: ThemeUtils.getTabsBg(context),
  277. child: Center(
  278. child: SpinKitFadingCircle(
  279. color: Colors.blueAccent,
  280. size: 30.0,
  281. ),
  282. ),
  283. );
  284. }
  285. @override
  286. bool get wantKeepAlive => true;
  287. }
  288. class Brand extends StatelessWidget {
  289. const Brand({Key key, this.initList, this.fun}) : super(key: key);
  290. final Function fun;
  291. final List<dynamic> initList;
  292. List<Widget> brandList(context) => initList.map((item) {
  293. double width = MediaQuery.of(context).size.width;
  294. return Container(
  295. // color:Colors.yellow,
  296. child: FlatButton(
  297. padding: EdgeInsets.all(0),
  298. highlightColor: Colors.white,
  299. splashColor: Colors.white,
  300. child: Container(
  301. width: width / 4,
  302. height: ScreenUtil().setWidth(100),
  303. // color: Colors.red,
  304. padding: EdgeInsets.only(
  305. left: ScreenUtil().setWidth(10),
  306. right: ScreenUtil().setWidth(10),
  307. top: ScreenUtil().setWidth(10)),
  308. child: Column(
  309. mainAxisAlignment: MainAxisAlignment.start,
  310. children: <Widget>[
  311. Container(
  312. child: LoadNetworkImageAlt(
  313. item.logo,
  314. width: ScreenUtil().setWidth(50),
  315. height: ScreenUtil().setWidth(50),
  316. // alignment: Alignment.centerLeft,
  317. ),
  318. ),
  319. SizedBox(height: 10,),
  320. Container(
  321. child: Text(
  322. item.name ?? "",
  323. style: TextStyle(
  324. color: Color(0xff333333),
  325. fontSize: 12),
  326. textAlign: TextAlign.start,
  327. maxLines: 1,
  328. overflow: TextOverflow.ellipsis,
  329. ),
  330. ),
  331. ]),
  332. ),
  333. onPressed: () {
  334. fun(item.id);
  335. },
  336. ),
  337. );
  338. }).toList();
  339. @override
  340. Widget build(BuildContext context) {
  341. return Container(
  342. padding: EdgeInsets.only(top: 5),
  343. child: Wrap(
  344. // spacing: 16,
  345. alignment: WrapAlignment.start,
  346. crossAxisAlignment: WrapCrossAlignment.center,
  347. children: brandList(context),
  348. ));
  349. }
  350. }
  351. class FadeRoute extends PageRouteBuilder {
  352. final Widget page;
  353. FadeRoute({this.page})
  354. : super(
  355. pageBuilder: (
  356. BuildContext context,
  357. Animation<double> animation,
  358. Animation<double> secondaryAnimation,
  359. ) =>
  360. page,
  361. transitionsBuilder: (
  362. BuildContext context,
  363. Animation<double> animation,
  364. Animation<double> secondaryAnimation,
  365. Widget child,
  366. ) =>
  367. FadeTransition(
  368. opacity: animation,
  369. child: child,
  370. ),
  371. );
  372. }