1111import 'package:flutter/material.dart' ;
1212import 'package:flutter/painting.dart' ;
1313import 'package:label_storemax/helpers/tools.dart' ;
14+ import 'package:label_storemax/labelconfig.dart' ;
1415import 'package:label_storemax/models/cart.dart' ;
1516import 'package:label_storemax/models/cart_line_item.dart' ;
1617import 'package:label_storemax/widgets/app_loader.dart' ;
1718import 'package:label_storemax/widgets/buttons.dart' ;
1819import 'package:label_storemax/widgets/cart_icon.dart' ;
1920import '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 ;
2122import 'package:flutter_swiper/flutter_swiper.dart' ;
2223import 'package:label_storemax/widgets/woosignal_ui.dart' ;
2324import 'package:cached_network_image/cached_network_image.dart' ;
2425
2526class ProductDetailPage extends StatefulWidget {
26- final WS .Product product;
27+ final WSProduct .Product product;
2728 const ProductDetailPage ({Key key, @required this .product}) : super (key: key);
2829
2930 @override
@@ -34,7 +35,7 @@ class _ProductDetailState extends State<ProductDetailPage> {
3435 _ProductDetailState (this ._product);
3536
3637 bool _isLoading;
37- WS .Product _product;
38+ WSProduct .Product _product;
3839 int _quantityIndicator = 1 ;
3940 List <WS .ProductVariation > _productVariations = [];
4041
@@ -103,9 +104,8 @@ class _ProductDetailState extends State<ProductDetailPage> {
103104 void _modalBottomSheetOptionsForAttribute (int attributeIndex) {
104105 wsModalBottom (
105106 context,
106- title: trans (context, "Select a" ) +
107- " " +
108- _product.attributes[attributeIndex].name,
107+ title:
108+ "${trans (context , "Select a" )} ${_product .attributes [attributeIndex ].name }" ,
109109 bodyWidget: ListView .separated (
110110 itemCount: _product.attributes[attributeIndex].options.length,
111111 separatorBuilder: (BuildContext context, int index) => Divider (),
@@ -164,9 +164,8 @@ class _ProductDetailState extends State<ProductDetailPage> {
164164 _tmpAttributeObj.containsKey (index))
165165 ? Text (_tmpAttributeObj[index]["value" ],
166166 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 }" ),
170169 trailing: (_tmpAttributeObj.isNotEmpty &&
171170 _tmpAttributeObj.containsKey (index))
172171 ? Icon (Icons .check, color: Colors .blueAccent)
@@ -212,47 +211,48 @@ class _ProductDetailState extends State<ProductDetailPage> {
212211 return ;
213212 }
214213
215- if (findProductVariation () == null ) {
214+ WS .ProductVariation productVariation = findProductVariation ();
215+ if (productVariation == null ) {
216216 showEdgeAlertWith (context,
217217 title: trans (context, "Oops" ),
218218 desc: trans (context, "Product variation does not exist" ),
219219 style: EdgeAlertStyle .WARNING );
220220 return ;
221221 }
222222
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 ;
231229 }
232230
233231 List <String > options = [];
234232 _tmpAttributeObj.forEach ((k, v) {
235- options.add (v["name" ] + ": " + v["value" ]);
233+ options.add ("${ v ["name" ]}: ${ v ["value" ]}" );
236234 });
237235
238236 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+ );
256256
257257 _itemAddToCart (cartLineItem: cartLineItem);
258258 Navigator .of (context).pop ();
@@ -303,7 +303,9 @@ class _ProductDetailState extends State<ProductDetailPage> {
303303 child: new Swiper (
304304 itemBuilder: (BuildContext context, int index) {
305305 return CachedNetworkImage (
306- imageUrl: _product.images[index].src,
306+ imageUrl: _product.images.length == 0
307+ ? app_product_placeholder_image
308+ : _product.images[index].src,
307309 placeholder: (context, url) => Center (
308310 child: new CircularProgressIndicator (
309311 strokeWidth: 2 ,
@@ -315,7 +317,9 @@ class _ProductDetailState extends State<ProductDetailPage> {
315317 fit: BoxFit .contain,
316318 );
317319 },
318- itemCount: _product.images.length,
320+ itemCount: _product.images.length == 0
321+ ? 1
322+ : _product.images.length,
319323 viewportFraction: 0.85 ,
320324 scale: 0.9 ,
321325 onTap: _productImageTapped,
@@ -542,7 +546,9 @@ class _ProductDetailState extends State<ProductDetailPage> {
542546 isManagedStock: _product.manageStock,
543547 stockQuantity: _product.stockQuantity,
544548 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,
546552 total: _product.price,
547553 );
548554
0 commit comments