control_detail.dart 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import 'dart:io';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:liftmanager/internal/bbs/model/control_model.dart';
  6. import 'package:liftmanager/internal/means/page/means_pdf.dart';
  7. import 'package:liftmanager/net/api_service.dart';
  8. import 'package:liftmanager/res/iconfont.dart';
  9. import 'package:liftmanager/res/resources.dart';
  10. import 'package:liftmanager/utils/toast.dart';
  11. import 'package:liftmanager/utils/utils.dart';
  12. import 'package:liftmanager/widgets/app_bar.dart';
  13. import 'package:liftmanager/widgets/bbs_content.dart';
  14. import 'package:liftmanager/widgets/load_image.dart';
  15. import 'package:liftmanager/widgets/preview_images.dart';
  16. import 'package:path_provider/path_provider.dart';
  17. class ControlDetail extends StatefulWidget {
  18. ControlDetail(this.id);
  19. final String id;
  20. @override
  21. State<StatefulWidget> createState() {
  22. return ControlDetailState();
  23. }
  24. }
  25. class ControlDetailState extends State<ControlDetail> {
  26. ScrollController _scrollController = new ScrollController();
  27. @override
  28. void dispose() {
  29. _scrollController.dispose();
  30. super.dispose();
  31. }
  32. @override
  33. void initState() {
  34. super.initState();
  35. this.getControlDetail();
  36. }
  37. bool _hasData = false;
  38. Records detailObj;
  39. getControlDetail() {
  40. NewApiService().getControlDetail(widget.id, onSuccess: (res) {
  41. detailObj = res;
  42. print("获取详情成功");
  43. print(res);
  44. _hasData = true;
  45. setState(() {});
  46. }, onError: (code, msg) {
  47. toasts(msg);
  48. });
  49. }
  50. @override
  51. Widget build(BuildContext context) {
  52. double width = MediaQuery.of(context).size.width;
  53. return Scaffold(
  54. appBar: MyAppBar(
  55. centerTitle: "控制系统资料",
  56. ),
  57. body: _hasData
  58. ? Container(
  59. child:
  60. ListView(controller: _scrollController, children: <Widget>[
  61. SectionHeader(
  62. title: '控制系统简介',
  63. ),
  64. Container(
  65. height: ScreenUtil().setWidth(130),
  66. padding: EdgeInsets.only(
  67. left: ScreenUtil().setWidth(15),
  68. right: ScreenUtil().setWidth(15),
  69. bottom: ScreenUtil().setWidth(30),
  70. top: ScreenUtil().setWidth(30)),
  71. child: Row(
  72. crossAxisAlignment: CrossAxisAlignment.start,
  73. mainAxisAlignment: MainAxisAlignment.center,
  74. children: <Widget>[
  75. Container(
  76. width: ScreenUtil().setWidth(55),
  77. height: ScreenUtil().setWidth(55),
  78. color: Colors.red,
  79. child: LoadNetworkImage(
  80. detailObj.logo,
  81. fit: BoxFit.cover,
  82. // alignment: Alignment.centerLeft,
  83. ),
  84. ),
  85. SizedBox(width: ScreenUtil().setWidth(20)),
  86. Expanded(
  87. child: Column(
  88. crossAxisAlignment: CrossAxisAlignment.start,
  89. children: [
  90. Text(
  91. detailObj.name ?? '',
  92. style: TextStyle(
  93. color: Color(0xff000000),
  94. fontSize: 15,
  95. ),
  96. textAlign: TextAlign.start,
  97. ),
  98. SizedBox(
  99. height: 10,
  100. ),
  101. Text(
  102. detailObj.descr ?? '',
  103. overflow: TextOverflow.ellipsis,
  104. maxLines: 3,
  105. style: TextStyle(
  106. color: Color(0xff999999), fontSize: 12),
  107. textAlign: TextAlign.start,
  108. ),
  109. ],
  110. ),
  111. )
  112. ]),
  113. ),
  114. Container(
  115. height: 5,
  116. color: Color(0xffFAF7FA),
  117. ),
  118. SectionHeader(
  119. title: '文件列表',
  120. ),
  121. Container(child: WorkFile(fileList: detailObj.listFile))
  122. ]),
  123. )
  124. : Center(
  125. child: Text("正在加载..."),
  126. ));
  127. }
  128. }
  129. class WorkFile extends StatelessWidget {
  130. WorkFile({Key key, this.fileList}) : super(key: key);
  131. List<dynamic> fileList = [];
  132. List<Widget> listWidget(context) => fileList.map((item) {
  133. return InkWell(
  134. child: Container(
  135. padding: EdgeInsets.only(
  136. left: ScreenUtil().setWidth(15),
  137. right: ScreenUtil().setWidth(15),
  138. top: ScreenUtil().setWidth(10),
  139. bottom: ScreenUtil().setWidth(10)),
  140. decoration: BoxDecoration(
  141. border: Border(
  142. bottom: BorderSide(width: 0.5, color: Colours.line),
  143. ),
  144. ),
  145. child: Row(
  146. crossAxisAlignment: CrossAxisAlignment.center,
  147. children: <Widget>[
  148. Container(
  149. padding: EdgeInsets.only(right: 10),
  150. child: ClipRRect(
  151. borderRadius:
  152. BorderRadius.circular(ScreenUtil().setWidth(18)),
  153. child: Container(
  154. width: ScreenUtil().setWidth(36),
  155. height: ScreenUtil().setWidth(36),
  156. color: Color(0xffF7FAFF),
  157. // padding: EdgeInsets.only(right:10),
  158. child: Icon(
  159. Iconfont.wenjian,
  160. size: 24.0,
  161. color: Color(0xff5589FF),
  162. ),
  163. ),
  164. ),
  165. ),
  166. Expanded(
  167. child: Text(
  168. item.name ?? '',
  169. textAlign: TextAlign.left,
  170. style: TextStyle(
  171. fontSize: 14,
  172. color: Color(0xff555A64),
  173. ),
  174. ),
  175. ),
  176. ]),
  177. ),
  178. onTap: () {
  179. var fileUrl = item.url;
  180. if (fileUrl != null && fileUrl != '') {
  181. fileUrl = Utils.getImagePath(item.url);
  182. print(fileUrl);
  183. if (Utils.getFileType(fileUrl) == 'image') {
  184. Navigator.of(context).push(new FadeRoute(
  185. page: PhotoViewGalleryScreen(
  186. images: [fileUrl], //传入图片list
  187. index: 0, //传入当前点击的图片的index
  188. // heroTag: img,//传入当前点击的图片的hero tag (可选)
  189. )));
  190. } else if (Utils.getFileType(fileUrl) == 'pdf') {
  191. createFileOfPdfUrl(fileUrl).then((f) {
  192. // setState(() {
  193. // pathPDF = f.path;
  194. Navigator.push(
  195. context,
  196. MaterialPageRoute(
  197. builder: (context) =>
  198. PDFScreen(f.path, fileUrl, item.id.toString())),
  199. );
  200. // });
  201. });
  202. }
  203. } else {
  204. toasts("暂无文件");
  205. }
  206. },
  207. );
  208. }).toList();
  209. @override
  210. Widget build(BuildContext context) {
  211. return Container(
  212. color: Colors.white,
  213. child: Column(children: listWidget(context)),
  214. );
  215. }
  216. Future<File> createFileOfPdfUrl(url) async {
  217. final filename = url.substring(url.lastIndexOf("/") + 1);
  218. var request = await HttpClient().getUrl(Uri.parse(url));
  219. var response = await request.close();
  220. var bytes = await consolidateHttpClientResponseBytes(response);
  221. String dir = (await getApplicationDocumentsDirectory()).path;
  222. File file = new File('$dir/$filename');
  223. await file.writeAsBytes(bytes);
  224. return file;
  225. }
  226. }
  227. class FadeRoute extends PageRouteBuilder {
  228. final Widget page;
  229. FadeRoute({this.page})
  230. : super(
  231. pageBuilder: (
  232. BuildContext context,
  233. Animation<double> animation,
  234. Animation<double> secondaryAnimation,
  235. ) =>
  236. page,
  237. transitionsBuilder: (
  238. BuildContext context,
  239. Animation<double> animation,
  240. Animation<double> secondaryAnimation,
  241. Widget child,
  242. ) =>
  243. FadeTransition(
  244. opacity: animation,
  245. child: child,
  246. ),
  247. );
  248. }