product_detail.dart 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. import 'package:flutter/material.dart';
  2. import 'package:liftmanager/res/gaps.dart';
  3. import 'package:liftmanager/net/api_service.dart';
  4. import 'package:liftmanager/utils/toast.dart';
  5. import 'package:liftmanager/widgets/app_bar.dart';
  6. import 'package:liftmanager/internal/search/search_router.dart';
  7. import 'package:liftmanager/widgets/app_search_bar.dart';
  8. import 'package:liftmanager/res/resources.dart';
  9. import 'package:liftmanager/routers/fluro_navigator.dart';
  10. import 'package:liftmanager/widgets/load_image.dart';
  11. import 'package:liftmanager/widgets/selected_image.dart';
  12. import 'package:image_picker/image_picker.dart';
  13. import 'package:liftmanager/internal/bbs/bbs_router.dart';
  14. import 'dart:io';
  15. import 'package:flutter_screenutil/flutter_screenutil.dart';
  16. import 'dart:convert';
  17. import 'package:liftmanager/utils/url.dart';
  18. import 'package:liftmanager/utils/time_format.dart';
  19. import 'package:liftmanager/utils/fast_notification.dart';
  20. import 'package:liftmanager/internal/bbs/model/shop_detail.dart';
  21. import 'package:url_launcher/url_launcher.dart';
  22. import 'package:flutter_swiper/flutter_swiper.dart';
  23. import 'dart:math';
  24. import 'package:fluwx/fluwx.dart' as fluwx;
  25. import 'package:flustars/flustars.dart' as FlutterStars;
  26. import 'package:liftmanager/common/common.dart';
  27. import 'package:liftmanager/internal/account/account_router.dart';
  28. import 'package:liftmanager/utils/theme_utils.dart';
  29. class ProductDetail extends StatefulWidget {
  30. ProductDetail(this.id);
  31. final String id;
  32. @override
  33. State<StatefulWidget> createState() {
  34. return ProductDetailState();
  35. }
  36. }
  37. class ProductDetailState extends State<ProductDetail> {
  38. @override
  39. void initState() {
  40. super.initState();
  41. getShopDetail();
  42. }
  43. bool _hasData = false;
  44. ShopDetailModel detailObj;
  45. Future getShopDetail() async {
  46. await NewApiService().getShopDetail(int.parse(widget.id),1,
  47. onSuccess: (res) {
  48. if (res != null) {
  49. _hasData = true;
  50. detailObj = res;
  51. setState(() {});
  52. }
  53. }, onError: (code, msg) {
  54. toasts(msg);
  55. });
  56. }
  57. showAlertEvent(){
  58. showAlert(
  59. context,
  60. "提示",
  61. "确定登录?",
  62. "确定",
  63. () {
  64. NavigatorUtils.push(context, AccountRouter.loginPage, clearStack: true);
  65. },
  66. txt2: "取消",
  67. onPre2: () {
  68. NavigatorUtils.goBack(context);
  69. },
  70. );
  71. }
  72. Future changeFav(type) async {
  73. await NewApiService().shopFav(detailObj.id, type, 1, onSuccess: (res) {
  74. toasts("收藏成功");
  75. initCollect();
  76. getShopDetail();
  77. }, onError: (code, msg) {
  78. toasts(msg);
  79. });
  80. }
  81. Future cancelFav() async {
  82. await NewApiService().shopFavCancel(detailObj.favoriteId, onSuccess: (res) {
  83. toasts("取消收藏成功");
  84. initCollect();
  85. getShopDetail();
  86. }, onError: (code, msg) {
  87. toasts(msg);
  88. });
  89. }
  90. _launchPhone(url) async {
  91. if (await canLaunch(url)) {
  92. await launch(url);
  93. } else {
  94. throw 'Could not launch $url';
  95. }
  96. }
  97. initCollect(){
  98. String collectInit = randomInt(1111,9999).toString() + DateTime.now().millisecondsSinceEpoch.toString();
  99. FastNotification.push("collectAction",collectInit);
  100. }
  101. randomInt(int min, int max) {
  102. return new Random().nextInt(max) % (max - min + 1) + min;
  103. }
  104. @override
  105. Widget build(BuildContext context) {
  106. double width = MediaQuery.of(context).size.width;
  107. return Scaffold(
  108. resizeToAvoidBottomPadding: false,//不让键盘弹上去
  109. appBar: MyAppBar(
  110. centerTitle: "商品详情",
  111. ),
  112. body: _hasData?Stack(
  113. children: <Widget>[
  114. Container(
  115. child: ListView(
  116. children: <Widget>[
  117. Column(
  118. mainAxisAlignment: MainAxisAlignment.start,
  119. crossAxisAlignment: CrossAxisAlignment.start,
  120. children: <Widget>[
  121. Container(
  122. padding: EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(10)),
  123. decoration: BoxDecoration(
  124. border: Border(
  125. bottom: BorderSide(width: 0.5, color: Colours.line),
  126. ),
  127. ),
  128. child: Column(
  129. mainAxisAlignment: MainAxisAlignment.start,
  130. crossAxisAlignment: CrossAxisAlignment.start,
  131. children:<Widget>[
  132. // Column(
  133. // children: detailObj.imgs.split(",").asMap().keys.map((i){
  134. // return
  135. // Container(
  136. // padding: EdgeInsets.only(bottom:10),
  137. // child: ClipRRect(
  138. // borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
  139. // child: Container(
  140. // // width:width,
  141. // // height: ScreenUtil().setWidth(220),
  142. // child:
  143. // Swiper(
  144. // itemBuilder: (BuildContext context, index) {
  145. // return Container(
  146. // width: width,
  147. // height: ScreenUtil().setWidth(220),
  148. // key: Key(detailObj.imgs.split(",")[index]),
  149. // child:
  150. // LoadNetworkImage(
  151. // detailObj.imgs.split(",")[index],
  152. // width: width,
  153. // height: ScreenUtil().setWidth(220),
  154. // fit: BoxFit.fill,
  155. // ),
  156. // );
  157. // },
  158. // pagination: SwiperPagination(
  159. // builder: DotSwiperPaginationBuilder(
  160. // color: Colors.grey,
  161. // activeColor: Colors.white,
  162. // size: 6,
  163. // activeSize: 6)),
  164. // itemCount: detailObj.imgs.split(",").length,
  165. // scrollDirection: Axis.horizontal,
  166. // autoplay: true,
  167. // onTap: (index) {
  168. // // print(index);
  169. // },
  170. // ),
  171. // // LoadNetworkImage(
  172. // // detailObj.imgs.split(",")[i],
  173. // // fit: BoxFit.cover,
  174. // // ),
  175. // ),
  176. // ),
  177. // );
  178. // }).toList(),
  179. // ),
  180. Container(
  181. width: width,
  182. height: ScreenUtil().setWidth(220),
  183. padding: EdgeInsets.only(bottom:10),
  184. child: ClipRRect(
  185. borderRadius: BorderRadius.circular(ScreenUtil().setWidth(10)),
  186. child: Container(
  187. // width:width,
  188. // height: ScreenUtil().setWidth(220),
  189. child:
  190. Swiper(
  191. itemBuilder: (BuildContext context, index) {
  192. return Container(
  193. width: width,
  194. height: ScreenUtil().setWidth(220),
  195. key: Key(detailObj.imgs.split(",")[index]),
  196. child:
  197. LoadNetworkImage(
  198. detailObj.imgs.split(",")[index],
  199. width: width,
  200. height: ScreenUtil().setWidth(220),
  201. fit: BoxFit.fill,
  202. isWater: true,
  203. ),
  204. );
  205. },
  206. pagination: SwiperPagination(
  207. builder: DotSwiperPaginationBuilder(
  208. color: Colors.grey,
  209. activeColor: Colors.white,
  210. size: 6,
  211. activeSize: 6)),
  212. itemCount: detailObj.imgs.split(",").length,
  213. scrollDirection: Axis.horizontal,
  214. autoplay: false,
  215. onTap: (index) {
  216. // print(index);
  217. },
  218. ),
  219. // LoadNetworkImage(
  220. // detailObj.imgs.split(",")[i],
  221. // fit: BoxFit.cover,
  222. // ),
  223. ),
  224. ),
  225. ),
  226. SizedBox(
  227. height:5
  228. ),
  229. Text(
  230. detailObj.name??"",
  231. style: TextStyle(
  232. fontSize:ScreenUtil().setSp(16)
  233. ),
  234. textAlign:TextAlign.start,
  235. ),
  236. Text(
  237. detailObj.brandName??"",
  238. style: TextStyle(
  239. color:Color(0xff666666),
  240. fontSize:ScreenUtil().setSp(14)
  241. ),
  242. textAlign:TextAlign.start,
  243. ),
  244. Row(
  245. children: <Widget>[
  246. Text(
  247. "推荐价格:",
  248. style: TextStyle(
  249. color:Color(0xff666666),
  250. fontSize:ScreenUtil().setSp(14)
  251. ),
  252. textAlign:TextAlign.start,
  253. ),
  254. Text(
  255. detailObj.price!=null?detailObj.price.toString():"",
  256. style: TextStyle(
  257. color:Color(0xffff0000),
  258. fontSize:ScreenUtil().setSp(16)
  259. ),
  260. textAlign:TextAlign.start,
  261. ),
  262. ],
  263. ),
  264. SizedBox(
  265. height:15
  266. ),
  267. ]
  268. ),
  269. ),
  270. Column(
  271. crossAxisAlignment: CrossAxisAlignment.start,
  272. mainAxisAlignment: MainAxisAlignment.start,
  273. children: <Widget>[
  274. Container(
  275. padding:EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(5)),
  276. child: Text(
  277. "商品简介",
  278. style: TextStyle(
  279. fontSize:ScreenUtil().setSp(16),
  280. ),
  281. textAlign:TextAlign.left,
  282. ),
  283. ),
  284. Container(
  285. padding:EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(50)),
  286. child: Text(
  287. detailObj.descr,
  288. style: TextStyle(
  289. color:Color(0xff999999),
  290. fontSize:ScreenUtil().setSp(14),
  291. ),
  292. textAlign:TextAlign.left,
  293. ),
  294. ),
  295. ],
  296. ),
  297. Container(
  298. height:5,
  299. color:ThemeUtils.getDialogTextFieldColor(context)
  300. ),
  301. Column(
  302. crossAxisAlignment: CrossAxisAlignment.start,
  303. mainAxisAlignment: MainAxisAlignment.start,
  304. children: <Widget>[
  305. Container(
  306. padding:EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(5)),
  307. child: Text(
  308. "供应商: ${detailObj.manufacturer}",
  309. style: TextStyle(
  310. color:Color(0xff999999),
  311. fontSize:ScreenUtil().setSp(14),
  312. ),
  313. textAlign:TextAlign.left,
  314. ),
  315. ),
  316. Container(
  317. padding:EdgeInsets.only(left:ScreenUtil().setWidth(15),right:ScreenUtil().setWidth(15),top:ScreenUtil().setWidth(10),bottom:ScreenUtil().setWidth(50)),
  318. child: Text(
  319. "Tel: ${detailObj.telephone} ${detailObj.contactPerson != null ? '(' + detailObj.contactPerson + ')' : ''}",
  320. style: TextStyle(
  321. color:Color(0xff999999),
  322. fontSize:ScreenUtil().setSp(14),
  323. ),
  324. textAlign:TextAlign.left,
  325. ),
  326. ),
  327. ],
  328. ),
  329. SizedBox(height:ScreenUtil().setWidth(70))
  330. ],
  331. ),
  332. ]
  333. )
  334. ),
  335. Positioned(
  336. bottom:0,
  337. left:0,
  338. child:Container(
  339. width: width,
  340. child: Row(
  341. children:<Widget>[
  342. Container(
  343. height:ScreenUtil().setWidth(70),
  344. width:width/2,
  345. color:Colors.white,
  346. padding: EdgeInsets.only(left:ScreenUtil().setWidth(10),right:ScreenUtil().setWidth(10),top:ScreenUtil().setWidth(10)),
  347. child: Row(
  348. mainAxisAlignment: MainAxisAlignment.spaceAround,
  349. children: <Widget>[
  350. GestureDetector(
  351. onTap: (){
  352. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  353. showAlertEvent();
  354. }else {
  355. String initThis = randomInt(1111,9999).toString() + DateTime.now().millisecondsSinceEpoch.toString();
  356. fluwx.shareToWeChat(fluwx.WeChatShareWebPageModel(
  357. scene: fluwx.WeChatScene.SESSION,
  358. webPage: "http://lift.whlhcx.com/h5/index.html?num=$initThis&page=/bbs/productDetail&id=${widget.id}",
  359. title: detailObj.name,
  360. description: detailObj.descr,
  361. thumbnail: detailObj.imgs.split(",")[0],
  362. )).then((result){
  363. },
  364. onError: (msg){
  365. // print(msg);
  366. });
  367. }
  368. },
  369. child: Container(
  370. // padding: EdgeInsets.only(left:25,right:30),
  371. child:Column(
  372. children:<Widget>[
  373. Icon(
  374. IconData(
  375. 0xe6f4,
  376. fontFamily:"myfont"
  377. ),
  378. size: 26.0,
  379. color:Color(0xff333333),
  380. ),
  381. Text(
  382. "分享",
  383. style: TextStyle(
  384. color:Color(0xff000000),
  385. fontSize:ScreenUtil().setSp(14)
  386. ),
  387. textAlign:TextAlign.start,
  388. ),
  389. ]
  390. )
  391. ),
  392. ),
  393. GestureDetector(
  394. onTap: () {
  395. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  396. showAlertEvent();
  397. }else {
  398. if (detailObj.isFavorite == 1) {
  399. cancelFav();
  400. } else {
  401. changeFav(3);
  402. }
  403. }
  404. },
  405. child: Container(
  406. child:Column(
  407. children:<Widget>[
  408. Icon(
  409. IconData(
  410. detailObj.isFavorite == 1
  411. ? 0xe654
  412. : 0xe604,
  413. fontFamily:"myfont"
  414. ),
  415. size: 26.0,
  416. color:Color(detailObj.isFavorite == 1
  417. ? 0xff0388FD
  418. : 0xff333333),
  419. ),
  420. Text(
  421. detailObj.isFavorite == 1
  422. ? "已收藏"
  423. : "收藏",
  424. style: TextStyle(
  425. color:Color(detailObj.isFavorite == 1
  426. ? 0xff0388FD
  427. : 0xff000000),
  428. fontSize:ScreenUtil().setSp(14)
  429. ),
  430. textAlign:TextAlign.start,
  431. ),
  432. ]
  433. )
  434. ),
  435. )
  436. ],
  437. )
  438. ),
  439. Container(
  440. height:ScreenUtil().setWidth(70),
  441. width:width/2,
  442. color: Color(0xff0388FD),
  443. child: FlatButton(
  444. // padding: EdgeInsets.all(15.0),
  445. child: Text("联系卖家",style: TextStyle(fontSize:ScreenUtil().setSp(16)),),
  446. textColor: Colors.white,
  447. onPressed: () {
  448. print(222);
  449. if(FlutterStars.SpUtil.getString(Constant.userId) == "-1"){
  450. showAlertEvent();
  451. }else {
  452. _launchPhone("tel:"+detailObj.telephone);}
  453. },
  454. ),
  455. ),
  456. ]
  457. )
  458. )
  459. )
  460. ],
  461. ): Center(
  462. child: Text("正在加载..."),
  463. ),
  464. );
  465. }
  466. }