|
|
|
@ -2,23 +2,24 @@ 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/shoppingCart.dart'; |
|
|
|
|
import 'package:huixiang/store/sku.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'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
|
|
|
|
|
class ShopCar extends StatefulWidget { |
|
|
|
|
final List<ProductListBean> productLists; |
|
|
|
|
final Function(String id) queryMiNiDetail; |
|
|
|
|
final Function() clearShopCar; |
|
|
|
|
final Function() toDownOrder; |
|
|
|
|
final List<Map<String, dynamic>> shopCarGoods; |
|
|
|
|
|
|
|
|
|
final List<ShoppingCart> shopingCar; |
|
|
|
|
|
|
|
|
|
final Function(int count, String productId, int allCount, double allPrice) fc; |
|
|
|
|
|
|
|
|
|
ShopCar( |
|
|
|
|
this.productLists, |
|
|
|
|
this.shopCarGoods, |
|
|
|
|
this.shopingCar, |
|
|
|
|
this.clearShopCar, |
|
|
|
|
this.toDownOrder, |
|
|
|
|
this.fc, { |
|
|
|
@ -27,7 +28,7 @@ class ShopCar extends StatefulWidget {
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
|
return _ShopCar(this.shopCarGoods); |
|
|
|
|
return _ShopCar(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -35,30 +36,9 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
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 |
|
|
|
@ -103,8 +83,8 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
onTap: () { |
|
|
|
|
allPrice = 0; |
|
|
|
|
allCount = 0; |
|
|
|
|
widget.productLists.clear(); |
|
|
|
|
state((){}); |
|
|
|
|
|
|
|
|
|
state(() {}); |
|
|
|
|
widget.clearShopCar(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
@ -117,152 +97,144 @@ class _ShopCar extends State<ShopCar> {
|
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
padding: EdgeInsets.only( |
|
|
|
|
top: 8, |
|
|
|
|
left: 16, |
|
|
|
|
right: 16, |
|
|
|
|
), |
|
|
|
|
child: ListView.builder( |
|
|
|
|
itemCount: widget.productLists == null |
|
|
|
|
? 0 |
|
|
|
|
: widget.productLists.length, |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
|
itemBuilder: (context, position) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
onTap: () {}, |
|
|
|
|
child: ShopGoods( |
|
|
|
|
widget.productLists[position], |
|
|
|
|
(int count, String productId) { |
|
|
|
|
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["count"] = count; |
|
|
|
|
shopCarGoods[index] = map; |
|
|
|
|
} |
|
|
|
|
child: Stack( |
|
|
|
|
children: [ |
|
|
|
|
Positioned( |
|
|
|
|
top: 0, |
|
|
|
|
left: 0, |
|
|
|
|
right: 0, |
|
|
|
|
bottom: 54, |
|
|
|
|
child: Container( |
|
|
|
|
padding: EdgeInsets.only( |
|
|
|
|
top: 8, |
|
|
|
|
left: 16, |
|
|
|
|
right: 16, |
|
|
|
|
), |
|
|
|
|
child: ListView.builder( |
|
|
|
|
itemCount: widget.shopingCar == null |
|
|
|
|
? 0 |
|
|
|
|
: widget.shopingCar.length, |
|
|
|
|
physics: BouncingScrollPhysics(), |
|
|
|
|
itemBuilder: (context, position) { |
|
|
|
|
return GestureDetector( |
|
|
|
|
onTap: () {}, |
|
|
|
|
child: ShopGoods( |
|
|
|
|
widget.shopingCar[position], |
|
|
|
|
(int count, List<Attr> attr, String productId) { |
|
|
|
|
|
|
|
|
|
allCount = 0; |
|
|
|
|
allPrice = 0; |
|
|
|
|
shopCarGoods.forEach((element) { |
|
|
|
|
if (element["price"] != null && |
|
|
|
|
element["price"] != "") { |
|
|
|
|
double singlePrice = |
|
|
|
|
double.tryParse(element["price"]); |
|
|
|
|
allCount += element["count"]; |
|
|
|
|
allPrice += (singlePrice * element["count"]); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
widget.fc(count, productId, allCount, allPrice); |
|
|
|
|
widget.fc( |
|
|
|
|
count, productId, allCount, allPrice); |
|
|
|
|
|
|
|
|
|
state(() {}); |
|
|
|
|
state(() {}); |
|
|
|
|
}, |
|
|
|
|
count: _shopCarGoods(position).count, |
|
|
|
|
shopCarGoods: _shopCarGoods(position), |
|
|
|
|
queryMiNiDetail: widget.queryMiNiDetail, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
shopCarGoods: _shopCarGoods(position), |
|
|
|
|
queryMiNiDetail: widget.queryMiNiDetail, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Stack( |
|
|
|
|
alignment: Alignment.bottomLeft, |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
height: 54.h, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFFAFAFA), |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
|
color: Colors.black.withAlpha(8), |
|
|
|
|
offset: Offset(0, -1), |
|
|
|
|
blurRadius: 3, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
children: [ |
|
|
|
|
Spacer(), |
|
|
|
|
Text( |
|
|
|
|
S.of(context).heji, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Text( |
|
|
|
|
"¥" + allPrice.toString(), |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 20.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
color: Color(0xFF32A060), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Spacer(), |
|
|
|
|
GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
widget.toDownOrder(); |
|
|
|
|
}, |
|
|
|
|
child: RoundButton( |
|
|
|
|
width: 103.w, |
|
|
|
|
Positioned( |
|
|
|
|
bottom: 0, |
|
|
|
|
left: 0, |
|
|
|
|
right: 0, |
|
|
|
|
child: Stack( |
|
|
|
|
alignment: Alignment.bottomLeft, |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
height: 54.h, |
|
|
|
|
text: S.current.jiesuan, |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
|
radius: 0, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 5.h), |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Color(0xFFFAFAFA), |
|
|
|
|
boxShadow: [ |
|
|
|
|
BoxShadow( |
|
|
|
|
color: Colors.black.withAlpha(8), |
|
|
|
|
offset: Offset(0, -1), |
|
|
|
|
blurRadius: 3, |
|
|
|
|
spreadRadius: 0, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
children: [ |
|
|
|
|
Spacer(), |
|
|
|
|
Text( |
|
|
|
|
S.of(context).heji, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Text( |
|
|
|
|
"¥" + allPrice.toString(), |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 20.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
color: Color(0xFF32A060), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Spacer(), |
|
|
|
|
GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
widget.toDownOrder(); |
|
|
|
|
}, |
|
|
|
|
child: RoundButton( |
|
|
|
|
width: 103.w, |
|
|
|
|
height: 54.h, |
|
|
|
|
text: S.current.jiesuan, |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
|
radius: 0, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
padding: |
|
|
|
|
EdgeInsets.symmetric(vertical: 5.h), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Stack( |
|
|
|
|
children: [ |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () { |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/shopp.png", |
|
|
|
|
width: 88, |
|
|
|
|
height: 88, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Positioned( |
|
|
|
|
right: 15, |
|
|
|
|
top: 14, |
|
|
|
|
child: RoundButton( |
|
|
|
|
width: 17, |
|
|
|
|
height: 17, |
|
|
|
|
text: allCount.toString(), |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
radius: 100, |
|
|
|
|
callback: () { |
|
|
|
|
Navigator.of(context) |
|
|
|
|
.pushNamed('/router/test_page'); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
Stack( |
|
|
|
|
children: [ |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () { |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/shopp.png", |
|
|
|
|
width: 88, |
|
|
|
|
height: 88, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Positioned( |
|
|
|
|
right: 15, |
|
|
|
|
top: 14, |
|
|
|
|
child: RoundButton( |
|
|
|
|
width: 17, |
|
|
|
|
height: 17, |
|
|
|
|
text: allCount.toString(), |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
radius: 100, |
|
|
|
|
callback: () { |
|
|
|
|
Navigator.of(context) |
|
|
|
|
.pushNamed('/router/test_page'); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
flex: 1, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
@ -271,13 +243,14 @@ 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"]) { |
|
|
|
|
map = element; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
Sku _shopCarGoods(int position) { |
|
|
|
|
Sku map = widget.shopCarGoods[position]; |
|
|
|
|
// widget.shopCarGoods.forEach((element) { |
|
|
|
|
// if (widget.productLists[position].id == element.id) { |
|
|
|
|
// map = element; |
|
|
|
|
// } |
|
|
|
|
// }); |
|
|
|
|
// print("shopCarGoods123123: ${map.toJson()}"); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|