7
7
import 'package:flutter/material.dart' ;
8
8
import 'package:flutter_swiper/flutter_swiper.dart' ;
9
9
import 'package:cached_network_image/cached_network_image.dart' ;
10
- import 'package:provider/provider.dart' ;
11
- import 'package:easy_market/model/index.dart' ;
12
10
import 'package:easy_market/utils/rem.dart' ;
11
+ import 'package:easy_market/utils/cache.dart' ;
13
12
import 'package:easy_market/api/index.dart' ;
14
13
import 'package:easy_market/component/bottom_sheet.dart' ;
15
14
import 'package:easy_market/component/SliverCustomHeader.dart' ;
16
15
import 'package:easy_market/component/count.dart' ;
17
16
import 'package:easy_market/router/index.dart' ;
17
+ import 'package:flutter_html/flutter_html.dart' ;
18
18
19
19
class GoodsDetail extends StatefulWidget {
20
20
GoodsDetail ({this .arguments});
@@ -50,27 +50,27 @@ class _GoodsDetail extends State<GoodsDetail> {
50
50
51
51
int userHasCollect; //用户是否收藏0:否;1:是
52
52
53
- // 我不知道是否应该在这里进行数据请求,但我需要获取provider的值
54
53
@override
55
- void didChangeDependencies () {
56
- super .didChangeDependencies ();
54
+ void initState () {
55
+ super .initState ();
57
56
getInitData ();
58
57
}
59
58
60
59
getInitData () async {
61
60
int id = widget.arguments['id' ];
62
- final model = Provider .of <Model >(this .context);
61
+ var sq = await SpUtil .getInstance ();
62
+ final token = sq.getString ('token' );
63
63
List <Future > api = [
64
- Api .getGoodsMSG (id: id, token: model. token == null ? null : model. token)
64
+ Api .getGoodsMSG (id: id, token: token == null ? null : token)
65
65
];
66
- if (model. token != null ) {
66
+ if (token != null ) {
67
67
api.add (
68
- Api .getCartMsg (token: model. token, id: id),
68
+ Api .getCartMsg (token: token, id: id),
69
69
);
70
70
}
71
71
var data = await Future .wait (api);
72
72
var goodsMsg = data[0 ].data;
73
- var cartData = model. token != null ? data[1 ].data : null ;
73
+ var cartData = token != null ? data[1 ].data : null ;
74
74
75
75
var specificationList = goodsMsg['specificationList' ];
76
76
List <int > sizeIndex = [];
@@ -94,9 +94,8 @@ class _GoodsDetail extends State<GoodsDetail> {
94
94
chooseSizeIndex = sizeIndex;
95
95
chooseSizeStr = sizeNameList.join ('、' );
96
96
goodsStockPrice = goodsStockPriceAny;
97
- userToken = model.token;
98
- goodsCount =
99
- model.token != null ? cartData['cartTotal' ]['goodsCount' ] : 0 ;
97
+ userToken = token;
98
+ goodsCount = token != null ? cartData['cartTotal' ]['goodsCount' ] : 0 ;
100
99
});
101
100
}
102
101
@@ -154,7 +153,11 @@ class _GoodsDetail extends State<GoodsDetail> {
154
153
userHasCollect = userHasCollect == 1 ? 0 : 1 ;
155
154
});
156
155
} else {
157
- Router .push ('/login' , context);
156
+ Router .push ('/login' , context, null , () async {
157
+ var sq = await SpUtil .getInstance ();
158
+ final token = sq.getString ('token' );
159
+ print (token);
160
+ });
158
161
}
159
162
},
160
163
),
@@ -277,9 +280,9 @@ class _GoodsDetail extends State<GoodsDetail> {
277
280
color: Colors .white,
278
281
boxShadow: [
279
282
new BoxShadow (
280
- color: Colors .grey[200 ],
283
+ color: Colors .grey[300 ],
281
284
blurRadius: Rem .getPxToRem (1 ),
282
- spreadRadius: 0.1 ,
285
+ spreadRadius: 0.2 ,
283
286
)
284
287
],
285
288
),
@@ -318,9 +321,31 @@ class _GoodsDetail extends State<GoodsDetail> {
318
321
buildOneWidget (
319
322
buildSize (context),
320
323
),
321
- buildOneWidget (Container (
322
- height: 500 ,
323
- ))
324
+ buildOneWidget (
325
+ buildComment (context),
326
+ ),
327
+ buildOneWidget (Column (
328
+ children: < Widget > [
329
+ Container (
330
+ margin: EdgeInsets .only (top: 10 ),
331
+ height: Rem .getPxToRem (100 ),
332
+ color: Colors .white,
333
+ width: double .infinity,
334
+ alignment: Alignment .center,
335
+ child: Text (
336
+ '商品详情' ,
337
+ style: TextStyle (
338
+ color: Colors .orange,
339
+ fontWeight: FontWeight .bold,
340
+ ),
341
+ ),
342
+ ),
343
+ Html (
344
+ data: goodsMsgs['info' ]['goods_desc' ]
345
+ .replaceAll ('<p><br/></p>' , '' ),
346
+ ),
347
+ ],
348
+ )),
324
349
],
325
350
);
326
351
}
@@ -480,49 +505,166 @@ class _GoodsDetail extends State<GoodsDetail> {
480
505
481
506
// 选择规格
482
507
Widget buildSize (BuildContext context) {
508
+ return InkResponse (
509
+ child: Container (
510
+ height: Rem .getPxToRem (100 ),
511
+ margin: EdgeInsets .only (top: 10 ),
512
+ decoration: BoxDecoration (
513
+ color: Colors .white,
514
+ ),
515
+ child: Row (
516
+ children: < Widget > [
517
+ Padding (
518
+ padding: EdgeInsets .all (5 ),
519
+ child: Text (
520
+ '已选' ,
521
+ style: TextStyle (color: Colors .grey),
522
+ ),
523
+ ),
524
+ Expanded (
525
+ child: Padding (
526
+ padding: EdgeInsets .all (5 ),
527
+ child: Row (
528
+ children: < Widget > [
529
+ Expanded (
530
+ child: Text (
531
+ '${chooseSizeStr .length > 0 ? chooseSizeStr : '该商品没有size!' }' ,
532
+ overflow: TextOverflow .ellipsis,
533
+ ),
534
+ ),
535
+ Text ('x$goodsNumber ' ),
536
+ ],
537
+ ),
538
+ ),
539
+ ),
540
+ Padding (
541
+ padding: EdgeInsets .all (5 ),
542
+ child: Icon (
543
+ Icons .keyboard_arrow_right,
544
+ color: Colors .grey,
545
+ ),
546
+ ),
547
+ ],
548
+ ),
549
+ ),
550
+ onTap: () {
551
+ buildSizeModel (context);
552
+ },
553
+ );
554
+ }
555
+
556
+ // 商品评论
557
+ Widget buildComment (BuildContext context) {
558
+ List <Widget > imgs = [];
559
+ if (goodsMsgs['comment' ]['count' ] > 0 ) {
560
+ var imgListMap = goodsMsgs['comment' ]['data' ]['pic_list' ];
561
+ for (int i = 0 ; i < imgListMap.length; i++ ) {
562
+ imgs.add (Container (
563
+ height: Rem .getPxToRem (200 ),
564
+ width: Rem .getPxToRem (200 ),
565
+ child: CachedNetworkImage (
566
+ imageUrl: imgListMap[i]['pic_url' ],
567
+ fit: BoxFit .cover,
568
+ ),
569
+ ));
570
+ }
571
+ }
483
572
return Container (
484
- height: Rem .getPxToRem (100 ),
485
573
margin: EdgeInsets .only (top: 10 ),
486
574
decoration: BoxDecoration (
487
575
color: Colors .white,
488
576
),
489
- child: Row (
577
+ child: Column (
490
578
children: < Widget > [
491
- Padding (
492
- padding: EdgeInsets .all (5 ),
493
- child: Text (
494
- '已选' ,
495
- style: TextStyle (color: Colors .grey),
496
- ),
497
- ),
498
- Expanded (
499
- child: Padding (
500
- padding: EdgeInsets .all (5 ),
579
+ InkResponse (
580
+ child: Container (
581
+ height: Rem .getPxToRem (100 ),
501
582
child: Row (
502
583
children: < Widget > [
503
- Expanded (
584
+ Container (
585
+ padding: EdgeInsets .only (left: 5 ),
504
586
child: Text (
505
- '${chooseSizeStr .length > 0 ? chooseSizeStr : '该商品没有size!' }' ,
506
- overflow: TextOverflow .ellipsis,
587
+ '评论' ,
588
+ style: TextStyle (color: Colors .grey),
589
+ ),
590
+ ),
591
+ Expanded (
592
+ child: Container (
593
+ padding: EdgeInsets .only (left: 10 ),
594
+ child: Text (
595
+ '${goodsMsgs ['comment' ]['count' ]}条' ,
596
+ ),
597
+ ),
598
+ ),
599
+ Padding (
600
+ padding: EdgeInsets .only (right: 5 ),
601
+ child: Icon (
602
+ Icons .keyboard_arrow_right,
603
+ color: Colors .grey,
507
604
),
508
605
),
509
- Text ('x$goodsNumber ' ),
510
606
],
511
607
),
512
608
),
513
- ),
514
- InkResponse (
515
- child: Padding (
516
- padding: EdgeInsets .all (5 ),
517
- child: Icon (
518
- Icons .keyboard_arrow_right,
519
- color: Colors .grey,
520
- ),
521
- ),
522
609
onTap: () {
523
- buildSizeModel (context);
610
+ if (goodsMsgs['comment' ]['count' ] > 0 ) {
611
+ Router .push (
612
+ '/moreComment' , context, {'id' : widget.arguments['id' ]});
613
+ }
524
614
},
525
615
),
616
+ goodsMsgs['comment' ]['count' ] > 0
617
+ ? Container (
618
+ height: Rem .getPxToRem (80 ),
619
+ decoration: BoxDecoration (
620
+ border: Border (
621
+ top: BorderSide (
622
+ color: Colors .grey,
623
+ width: .5 ,
624
+ ),
625
+ ),
626
+ ),
627
+ padding: EdgeInsets .symmetric (horizontal: 5 ),
628
+ child: Row (
629
+ children: < Widget > [
630
+ Expanded (
631
+ child: Text ('匿名用户' ),
632
+ ),
633
+ Text (
634
+ '${goodsMsgs ['comment' ]['data' ]['add_time' ]}' ,
635
+ style: TextStyle (
636
+ color: Colors .grey,
637
+ ),
638
+ ),
639
+ ],
640
+ ),
641
+ )
642
+ : Container (),
643
+ goodsMsgs['comment' ]['count' ] > 0
644
+ ? Container (
645
+ height: Rem .getPxToRem (80 ),
646
+ width: double .infinity,
647
+ padding: EdgeInsets .symmetric (horizontal: 5 ),
648
+ child: Text (
649
+ '${goodsMsgs ['comment' ]['data' ]['content' ]}' ,
650
+ softWrap: true ,
651
+ maxLines: 2 ,
652
+ overflow: TextOverflow .ellipsis,
653
+ style: TextStyle (
654
+ color: Colors .grey,
655
+ ),
656
+ ),
657
+ )
658
+ : Container (),
659
+ goodsMsgs['comment' ]['count' ] > 0
660
+ ? Container (
661
+ padding: EdgeInsets .fromLTRB (5 , 0 , 5 , 5 ),
662
+ width: double .infinity,
663
+ child: Wrap (
664
+ children: imgs,
665
+ ),
666
+ )
667
+ : Container ()
526
668
],
527
669
),
528
670
);
0 commit comments