|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
import 'package:ai_decimal_accuracy/ai_decimal_accuracy.dart'; |
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:huixiang/generated/l10n.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/findMiNiGroupList.dart'; |
|
|
|
|
import 'package:huixiang/retrofit/data/order_info.dart'; |
|
|
|
|
import 'package:huixiang/store/store_view/shop_goods.dart'; |
|
|
|
|
import 'package:huixiang/utils/font_weight.dart'; |
|
|
|
|
import 'package:huixiang/view_widget/round_button.dart'; |
|
|
|
@ -10,6 +10,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
|
class ShopCar extends StatefulWidget { |
|
|
|
|
final List<ProductListBean> productLists; |
|
|
|
|
final Function(String id) queryMiNiDetail; |
|
|
|
|
final Function() clearShopCar; |
|
|
|
|
final List<Map<String, dynamic>> shopCarGoods; |
|
|
|
|
|
|
|
|
|
final Function(int count, String productId, int allCount, double allPrice) fc; |
|
|
|
@ -17,11 +18,10 @@ class ShopCar extends StatefulWidget {
|
|
|
|
|
ShopCar( |
|
|
|
|
this.productLists, |
|
|
|
|
this.shopCarGoods, |
|
|
|
|
this.fc, |
|
|
|
|
{ |
|
|
|
|
this.clearShopCar, |
|
|
|
|
this.fc, { |
|
|
|
|
this.queryMiNiDetail, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
@ -30,17 +30,39 @@ class ShopCar extends StatefulWidget {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class _ShopCar extends State<ShopCar> { |
|
|
|
|
|
|
|
|
|
int allCount; |
|
|
|
|
double allPrice; |
|
|
|
|
int allCount = 0; |
|
|
|
|
double allPrice = 0.0; |
|
|
|
|
|
|
|
|
|
final List<Map<String, dynamic>> shopCarGoods; |
|
|
|
|
|
|
|
|
|
_ShopCar(this.shopCarGoods); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
void initState() { |
|
|
|
|
super.initState(); |
|
|
|
|
|
|
|
|
|
if (shopCarGoods != null) { |
|
|
|
|
AiDecimalAccuracy allPriceDecimal = AiDecimalAccuracy.zero; |
|
|
|
|
shopCarGoods.forEach((element) { |
|
|
|
|
if (element["price"] != null && element["price"] != "") { |
|
|
|
|
double singlePrice = double.tryParse(element["price"]); |
|
|
|
|
allCount += element["count"]; |
|
|
|
|
|
|
|
|
|
AiDecimalAccuracy aiDecimalAccuracy = AiDecimalAccuracy.fromInt(element["count"]); |
|
|
|
|
AiDecimalAccuracy aiPrice = AiDecimalAccuracy.tryParse("$singlePrice"); |
|
|
|
|
|
|
|
|
|
allPriceDecimal += (aiPrice * aiDecimalAccuracy); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
allPrice = allPriceDecimal.toDouble(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
return StatefulBuilder(builder: (context1, state) { |
|
|
|
|
return StatefulBuilder( |
|
|
|
|
builder: (context1, state) { |
|
|
|
|
return Container( |
|
|
|
|
alignment: Alignment.topCenter, |
|
|
|
|
width: double.infinity, |
|
|
|
@ -77,7 +99,7 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
), |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () { |
|
|
|
|
state(() {}); |
|
|
|
|
widget.clearShopCar(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/delete.png", |
|
|
|
@ -97,7 +119,8 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
), |
|
|
|
|
child: ListView.builder( |
|
|
|
|
itemCount: widget.productLists == null |
|
|
|
|
? 0 : widget.productLists.length, |
|
|
|
|
? 0 |
|
|
|
|
: widget.productLists.length, |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
|
itemBuilder: (context, position) { |
|
|
|
|
return GestureDetector( |
|
|
|
@ -108,14 +131,27 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
int index = shopCarGoods.indexWhere((element) => element["id"] == productId); |
|
|
|
|
if (count == 0) { |
|
|
|
|
shopCarGoods.removeAt(index); |
|
|
|
|
int index1 = widget.productLists.indexWhere((element) => element.id == productId); |
|
|
|
|
widget.productLists.removeAt(index1); |
|
|
|
|
} else { |
|
|
|
|
Map<String, dynamic> map; |
|
|
|
|
print("productId: $productId"); |
|
|
|
|
shopCarGoods.forEach((element) { |
|
|
|
|
if (element["id"] == productId) { |
|
|
|
|
map = element; |
|
|
|
|
} |
|
|
|
|
Map<String, dynamic> map = shopCarGoods.firstWhere((element) => element["id"] == productId); |
|
|
|
|
}); |
|
|
|
|
map["count"] = count; |
|
|
|
|
shopCarGoods[index] = map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
allCount = 0; |
|
|
|
|
allPrice = 0; |
|
|
|
|
shopCarGoods.forEach((element) { |
|
|
|
|
if (element["price"] != null && element["price"] != "") { |
|
|
|
|
double singlePrice = double.tryParse(element["price"]); |
|
|
|
|
if (element["price"] != null && |
|
|
|
|
element["price"] != "") { |
|
|
|
|
double singlePrice = |
|
|
|
|
double.tryParse(element["price"]); |
|
|
|
|
allCount += element["count"]; |
|
|
|
|
allPrice += (singlePrice * element["count"]); |
|
|
|
|
} |
|
|
|
@ -123,7 +159,7 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
|
|
|
|
|
widget.fc(count, productId, allCount, allPrice); |
|
|
|
|
|
|
|
|
|
state((){}); |
|
|
|
|
state(() {}); |
|
|
|
|
}, |
|
|
|
|
shopCarGoods: _shopCarGoods(position), |
|
|
|
|
queryMiNiDetail: widget.queryMiNiDetail, |
|
|
|
@ -216,7 +252,8 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
radius: 100, |
|
|
|
|
callback: () { |
|
|
|
|
Navigator.of(context).pushNamed('/router/test_page'); |
|
|
|
|
Navigator.of(context) |
|
|
|
|
.pushNamed('/router/test_page'); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
@ -227,16 +264,17 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Map<String, dynamic> _shopCarGoods(int position) { |
|
|
|
|
Map<String, dynamic> map; |
|
|
|
|
widget.shopCarGoods.forEach((element) { |
|
|
|
|
if (widget.productLists[position].id == element["id"]) { |
|
|
|
|
return element; |
|
|
|
|
map = element; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return null; |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|