error_detail.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/net/api_service.dart';
  3. import 'package:liftmanager/utils/toast.dart';
  4. import 'package:liftmanager/widgets/app_bar.dart';
  5. import 'package:liftmanager/res/resources.dart';
  6. import 'package:liftmanager/widgets/load_image.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:liftmanager/internal/bbs/model/error_model.dart';
  9. import 'package:liftmanager/utils/url.dart';
  10. import 'package:liftmanager/utils/utils.dart';
  11. import 'package:liftmanager/widgets/preview_images.dart';
  12. class ErrorDetail extends StatefulWidget {
  13. ErrorDetail(this.id);
  14. final String id;
  15. @override
  16. State<StatefulWidget> createState() {
  17. return ErrorDetailState();
  18. }
  19. }
  20. class ErrorDetailState extends State<ErrorDetail> {
  21. @override
  22. void initState() {
  23. super.initState();
  24. getFaultCodeDetail();
  25. }
  26. bool _hasData = false;
  27. ErrorDetailModel detailObj;
  28. List<String> listPreview = [];
  29. getFaultCodeDetail() {
  30. NewApiService().getFaultCodeDetail(widget.id, onSuccess: (res) {
  31. detailObj = res;
  32. listPreview = [];
  33. detailObj.imgs.split(",").forEach((element) {
  34. listPreview.add(Utils.getImagePath(element,isWater: true));
  35. });
  36. _hasData = true;
  37. setState(() {});
  38. }, onError: (code, msg) {
  39. toasts(msg);
  40. });
  41. }
  42. @override
  43. Widget build(BuildContext context) {
  44. double width = MediaQuery.of(context).size.width;
  45. return Scaffold(
  46. resizeToAvoidBottomPadding: false, //不让键盘弹上去
  47. appBar: MyAppBar(
  48. centerTitle: "故障码详情",
  49. ),
  50. body: _hasData
  51. ? Container(
  52. child: ListView(
  53. children: <Widget>[
  54. Column(
  55. mainAxisAlignment: MainAxisAlignment.start,
  56. crossAxisAlignment: CrossAxisAlignment.start,
  57. children: <Widget>[
  58. Container(
  59. padding:
  60. EdgeInsets.only(left: ScreenUtil().setWidth(20)),
  61. child: Column(
  62. crossAxisAlignment: CrossAxisAlignment.start,
  63. mainAxisAlignment: MainAxisAlignment.start,
  64. children: <Widget>[
  65. Container(
  66. padding: EdgeInsets.only(
  67. top: ScreenUtil().setWidth(10),
  68. bottom: ScreenUtil().setWidth(5)),
  69. child: Text(
  70. "故障码",
  71. style: TextStyle(
  72. color: Color(0xff222222),
  73. fontSize: ScreenUtil().setSp(16),
  74. ),
  75. textAlign: TextAlign.left,
  76. ),
  77. ),
  78. SizedBox(height: 10),
  79. Container(
  80. // width: 90,
  81. // height: 30,
  82. padding: EdgeInsets.only(
  83. left: ScreenUtil().setWidth(10),
  84. right: ScreenUtil().setWidth(10),
  85. top: ScreenUtil().setWidth(5),
  86. bottom: ScreenUtil().setWidth(5)),
  87. decoration: BoxDecoration(
  88. borderRadius: BorderRadius.circular(2.0),
  89. color: Color(0xff9FD1FE),
  90. ),
  91. child: Text(
  92. detailObj.code ?? '',
  93. style: TextStyle(
  94. color: Color(0xffffffff),
  95. fontSize: ScreenUtil().setSp(14)),
  96. textAlign: TextAlign.center,
  97. ),
  98. ),
  99. SizedBox(height: 20)
  100. ],
  101. ),
  102. ),
  103. Container(height: 5, color: Color(0xffFAF7FA)),
  104. Column(
  105. crossAxisAlignment: CrossAxisAlignment.start,
  106. mainAxisAlignment: MainAxisAlignment.start,
  107. children: <Widget>[
  108. Container(
  109. padding: EdgeInsets.only(
  110. left: ScreenUtil().setWidth(20),
  111. top: ScreenUtil().setWidth(10),
  112. bottom: ScreenUtil().setWidth(5)),
  113. child: Text(
  114. "故障描述",
  115. style: TextStyle(
  116. color: Color(0xff222222),
  117. fontSize: ScreenUtil().setSp(16),
  118. ),
  119. textAlign: TextAlign.left,
  120. ),
  121. ),
  122. Container(
  123. padding: EdgeInsets.only(
  124. left: ScreenUtil().setWidth(15),
  125. right: ScreenUtil().setWidth(15),
  126. top: ScreenUtil().setWidth(10),
  127. bottom: ScreenUtil().setWidth(20)),
  128. child: Text(
  129. detailObj.descr ?? '',
  130. style: TextStyle(
  131. color: Color(0xff666666),
  132. fontSize: ScreenUtil().setSp(16),
  133. ),
  134. textAlign: TextAlign.left,
  135. ),
  136. ),
  137. ],
  138. ),
  139. Container(height: 5, color: Color(0xffFAF7FA)),
  140. Column(
  141. crossAxisAlignment: CrossAxisAlignment.start,
  142. mainAxisAlignment: MainAxisAlignment.start,
  143. children: <Widget>[
  144. Container(
  145. padding: EdgeInsets.only(
  146. left: ScreenUtil().setWidth(15),
  147. top: ScreenUtil().setWidth(10),
  148. bottom: ScreenUtil().setWidth(5)),
  149. child: Text(
  150. "问题现象",
  151. style: TextStyle(
  152. color: Color(0xff222222),
  153. fontSize: ScreenUtil().setSp(16),
  154. ),
  155. textAlign: TextAlign.left,
  156. ),
  157. ),
  158. Container(
  159. padding: EdgeInsets.only(
  160. left: ScreenUtil().setWidth(15),
  161. right: ScreenUtil().setWidth(15),
  162. top: ScreenUtil().setWidth(10),
  163. bottom: ScreenUtil().setWidth(20)),
  164. child: Text(
  165. detailObj.cause ?? '',
  166. style: TextStyle(
  167. color: Color(0xff666666),
  168. fontSize: ScreenUtil().setSp(14),
  169. ),
  170. textAlign: TextAlign.left,
  171. ),
  172. ),
  173. ],
  174. ),
  175. Container(height: 5, color: Color(0xffFAF7FA)),
  176. Column(
  177. crossAxisAlignment: CrossAxisAlignment.start,
  178. mainAxisAlignment: MainAxisAlignment.start,
  179. children: <Widget>[
  180. Container(
  181. padding: EdgeInsets.only(
  182. left: ScreenUtil().setWidth(15),
  183. top: ScreenUtil().setWidth(10),
  184. bottom: ScreenUtil().setWidth(5)),
  185. child: Text(
  186. "解决方法",
  187. style: TextStyle(
  188. color: Color(0xff222222),
  189. fontSize: ScreenUtil().setSp(16),
  190. ),
  191. textAlign: TextAlign.left,
  192. ),
  193. ),
  194. Container(
  195. padding: EdgeInsets.only(
  196. left: ScreenUtil().setWidth(15),
  197. right: ScreenUtil().setWidth(15),
  198. top: ScreenUtil().setWidth(10),
  199. bottom: ScreenUtil().setWidth(20)),
  200. child: Text(
  201. detailObj.recoveryMethod ?? '',
  202. style: TextStyle(
  203. color: Color(0xff666666),
  204. fontSize: ScreenUtil().setSp(14),
  205. ),
  206. textAlign: TextAlign.left,
  207. ),
  208. ),
  209. ],
  210. ),
  211. Container(height: 5, color: Color(0xffFAF7FA)),
  212. Container(
  213. padding: EdgeInsets.only(
  214. left: ScreenUtil().setWidth(15),
  215. right: ScreenUtil().setWidth(15),
  216. top: ScreenUtil().setWidth(10),
  217. bottom: ScreenUtil().setWidth(10)),
  218. decoration: BoxDecoration(
  219. border: Border(
  220. bottom: BorderSide(width: 0.5, color: Colours.line),
  221. ),
  222. ),
  223. child: Column(
  224. mainAxisAlignment: MainAxisAlignment.start,
  225. crossAxisAlignment: CrossAxisAlignment.start,
  226. children: <Widget>[
  227. ErrorImages(
  228. imgList: listPreview)
  229. // Container(
  230. // child: Stack(
  231. // children: <Widget>[
  232. // ClipRRect(
  233. // borderRadius: BorderRadius.circular(5),
  234. // child: Container(
  235. // width: width,
  236. // height: 220,
  237. // child: LoadAssetImage(
  238. // "temporary/xue1",
  239. // fit: BoxFit.cover,
  240. // ),
  241. // ),
  242. // ),
  243. // ],
  244. // ),
  245. // ),
  246. ]),
  247. ),
  248. ],
  249. ),
  250. ],
  251. ),
  252. )
  253. : Center(
  254. child: Text("正在加载..."),
  255. ),
  256. );
  257. }
  258. }
  259. class ErrorImages extends StatelessWidget {
  260. ErrorImages({Key key, this.imgList}) : super(key: key);
  261. List<dynamic> imgList = [];
  262. List<Widget> imageList(context) => imgList.asMap().keys.map((index) {
  263. double width = MediaQuery.of(context).size.width;
  264. return Container(
  265. margin: EdgeInsets.only(
  266. bottom: ScreenUtil().setWidth(10),
  267. ),
  268. child: GestureDetector(
  269. onTap: (){
  270. Navigator.of(context).push(
  271. new FadeRoute(
  272. page: PhotoViewGalleryScreen(
  273. images: imgList, //传入图片list
  274. index: index, //传入当前点击的图片的index
  275. // heroTag: img,//传入当前点击的图片的hero tag (可选)
  276. ),
  277. ),
  278. );
  279. },
  280. child: ClipRRect(
  281. borderRadius: BorderRadius.circular(5),
  282. child: Container(
  283. width: width,
  284. height: 220,
  285. child: LoadNetworkImage(
  286. imgList[index],
  287. fit: BoxFit.cover,
  288. ),
  289. ),
  290. ),
  291. )
  292. );
  293. }).toList();
  294. @override
  295. Widget build(BuildContext context) {
  296. return Container(
  297. padding: EdgeInsets.only(
  298. top: ScreenUtil().setWidth(5),
  299. left: ScreenUtil().setWidth(15),
  300. right: ScreenUtil().setWidth(15)),
  301. child: Wrap(
  302. spacing: 6,
  303. alignment: WrapAlignment.spaceBetween,
  304. crossAxisAlignment: WrapCrossAlignment.center,
  305. children: imageList(context),
  306. ));
  307. }
  308. }
  309. class FadeRoute extends PageRouteBuilder {
  310. final Widget page;
  311. FadeRoute({this.page})
  312. : super(
  313. pageBuilder: (
  314. BuildContext context,
  315. Animation<double> animation,
  316. Animation<double> secondaryAnimation,
  317. ) =>
  318. page,
  319. transitionsBuilder: (
  320. BuildContext context,
  321. Animation<double> animation,
  322. Animation<double> secondaryAnimation,
  323. Widget child,
  324. ) =>
  325. FadeTransition(
  326. opacity: animation,
  327. child: child,
  328. ),
  329. );
  330. }