11
11
import 'package:flutter/material.dart' ;
12
12
import 'package:flutter/painting.dart' ;
13
13
import 'package:label_storemax/helpers/tools.dart' ;
14
+ import 'package:label_storemax/labelconfig.dart' ;
14
15
import 'package:label_storemax/models/cart.dart' ;
15
16
import 'package:label_storemax/models/cart_line_item.dart' ;
16
17
import 'package:label_storemax/widgets/app_loader.dart' ;
17
18
import 'package:label_storemax/widgets/buttons.dart' ;
18
19
import 'package:label_storemax/widgets/cart_icon.dart' ;
19
20
import 'package:woosignal/models/response/product_variation.dart' as WS;
20
- import 'package:woosignal/models/response/products.dart' as WS ;
21
+ import 'package:woosignal/models/response/products.dart' as WSProduct ;
21
22
import 'package:flutter_swiper/flutter_swiper.dart' ;
22
23
import 'package:label_storemax/widgets/woosignal_ui.dart' ;
23
24
import 'package:cached_network_image/cached_network_image.dart' ;
24
25
25
26
class ProductDetailPage extends StatefulWidget {
26
- final WS .Product product;
27
+ final WSProduct .Product product;
27
28
const ProductDetailPage ({Key key, @required this .product}) : super (key: key);
28
29
29
30
@override
@@ -34,7 +35,7 @@ class _ProductDetailState extends State<ProductDetailPage> {
34
35
_ProductDetailState (this ._product);
35
36
36
37
bool _isLoading;
37
- WS .Product _product;
38
+ WSProduct .Product _product;
38
39
int _quantityIndicator = 1 ;
39
40
List <WS .ProductVariation > _productVariations = [];
40
41
@@ -103,9 +104,8 @@ class _ProductDetailState extends State<ProductDetailPage> {
103
104
void _modalBottomSheetOptionsForAttribute (int attributeIndex) {
104
105
wsModalBottom (
105
106
context,
106
- title: trans (context, "Select a" ) +
107
- " " +
108
- _product.attributes[attributeIndex].name,
107
+ title:
108
+ "${trans (context , "Select a" )} ${_product .attributes [attributeIndex ].name }" ,
109
109
bodyWidget: ListView .separated (
110
110
itemCount: _product.attributes[attributeIndex].options.length,
111
111
separatorBuilder: (BuildContext context, int index) => Divider (),
@@ -164,9 +164,8 @@ class _ProductDetailState extends State<ProductDetailPage> {
164
164
_tmpAttributeObj.containsKey (index))
165
165
? Text (_tmpAttributeObj[index]["value" ],
166
166
style: Theme .of (context).primaryTextTheme.bodyText1)
167
- : Text (trans (context, "Select a" ) +
168
- " " +
169
- _product.attributes[index].name),
167
+ : Text (
168
+ "${trans (context , "Select a" )} ${_product .attributes [index ].name }" ),
170
169
trailing: (_tmpAttributeObj.isNotEmpty &&
171
170
_tmpAttributeObj.containsKey (index))
172
171
? Icon (Icons .check, color: Colors .blueAccent)
@@ -212,47 +211,48 @@ class _ProductDetailState extends State<ProductDetailPage> {
212
211
return ;
213
212
}
214
213
215
- if (findProductVariation () == null ) {
214
+ WS .ProductVariation productVariation = findProductVariation ();
215
+ if (productVariation == null ) {
216
216
showEdgeAlertWith (context,
217
217
title: trans (context, "Oops" ),
218
218
desc: trans (context, "Product variation does not exist" ),
219
219
style: EdgeAlertStyle .WARNING );
220
220
return ;
221
221
}
222
222
223
- if (findProductVariation () != null ) {
224
- if (findProductVariation ().stockStatus != "instock" ) {
225
- showEdgeAlertWith (context,
226
- title: trans (context, "Sorry" ),
227
- desc: trans (context, "This item is not in stock" ),
228
- style: EdgeAlertStyle .WARNING );
229
- return ;
230
- }
223
+ if (productVariation.stockStatus != "instock" ) {
224
+ showEdgeAlertWith (context,
225
+ title: trans (context, "Sorry" ),
226
+ desc: trans (context, "This item is not in stock" ),
227
+ style: EdgeAlertStyle .WARNING );
228
+ return ;
231
229
}
232
230
233
231
List <String > options = [];
234
232
_tmpAttributeObj.forEach ((k, v) {
235
- options.add (v["name" ] + ": " + v["value" ]);
233
+ options.add ("${ v ["name" ]}: ${ v ["value" ]}" );
236
234
});
237
235
238
236
CartLineItem cartLineItem = CartLineItem (
239
- name: _product.name,
240
- productId: _product.id,
241
- variationId: findProductVariation ().id,
242
- quantity: 1 ,
243
- taxStatus: findProductVariation ().taxStatus,
244
- shippingClassId:
245
- findProductVariation ().shippingClassId.toString (),
246
- subtotal: findProductVariation ().price,
247
- stockQuantity: findProductVariation ().stockQuantity,
248
- isManagedStock: findProductVariation ().manageStock,
249
- taxClass: findProductVariation ().taxClass,
250
- imageSrc: (findProductVariation ().image != null
251
- ? findProductVariation ().image.src
252
- : _product.images.first.src),
253
- shippingIsTaxable: _product.shippingTaxable,
254
- variationOptions: options.join (", " ),
255
- total: findProductVariation ().price);
237
+ name: _product.name,
238
+ productId: _product.id,
239
+ variationId: productVariation.id,
240
+ quantity: 1 ,
241
+ taxStatus: productVariation.taxStatus,
242
+ shippingClassId: productVariation.shippingClassId.toString (),
243
+ subtotal: productVariation.price,
244
+ stockQuantity: productVariation.stockQuantity,
245
+ isManagedStock: productVariation.manageStock,
246
+ taxClass: productVariation.taxClass,
247
+ imageSrc: (productVariation.image != null
248
+ ? productVariation.image.src
249
+ : _product.images.length == 0
250
+ ? app_product_placeholder_image
251
+ : _product.images.first.src),
252
+ shippingIsTaxable: _product.shippingTaxable,
253
+ variationOptions: options.join (", " ),
254
+ total: productVariation.price,
255
+ );
256
256
257
257
_itemAddToCart (cartLineItem: cartLineItem);
258
258
Navigator .of (context).pop ();
@@ -303,7 +303,9 @@ class _ProductDetailState extends State<ProductDetailPage> {
303
303
child: new Swiper (
304
304
itemBuilder: (BuildContext context, int index) {
305
305
return CachedNetworkImage (
306
- imageUrl: _product.images[index].src,
306
+ imageUrl: _product.images.length == 0
307
+ ? app_product_placeholder_image
308
+ : _product.images[index].src,
307
309
placeholder: (context, url) => Center (
308
310
child: new CircularProgressIndicator (
309
311
strokeWidth: 2 ,
@@ -315,7 +317,9 @@ class _ProductDetailState extends State<ProductDetailPage> {
315
317
fit: BoxFit .contain,
316
318
);
317
319
},
318
- itemCount: _product.images.length,
320
+ itemCount: _product.images.length == 0
321
+ ? 1
322
+ : _product.images.length,
319
323
viewportFraction: 0.85 ,
320
324
scale: 0.9 ,
321
325
onTap: _productImageTapped,
@@ -542,7 +546,9 @@ class _ProductDetailState extends State<ProductDetailPage> {
542
546
isManagedStock: _product.manageStock,
543
547
stockQuantity: _product.stockQuantity,
544
548
shippingIsTaxable: _product.shippingTaxable,
545
- imageSrc: _product.images.first.src,
549
+ imageSrc: _product.images.length == 0
550
+ ? app_product_placeholder_image
551
+ : _product.images.first.src,
546
552
total: _product.price,
547
553
);
548
554
0 commit comments