|
|
|
@ -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.queryMiNiDetail, |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
this.clearShopCar, |
|
|
|
|
this.fc, { |
|
|
|
|
this.queryMiNiDetail, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
@ -30,213 +30,251 @@ 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 Container( |
|
|
|
|
alignment: Alignment.topCenter, |
|
|
|
|
width: double.infinity, |
|
|
|
|
height: MediaQuery.of(context).size.height / 2, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Colors.white, |
|
|
|
|
borderRadius: BorderRadius.only( |
|
|
|
|
topLeft: Radius.circular(8), |
|
|
|
|
topRight: Radius.circular(8), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
padding: EdgeInsets.only( |
|
|
|
|
top: 16, |
|
|
|
|
left: 16, |
|
|
|
|
right: 16, |
|
|
|
|
bottom: 8, |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
"已选商品", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Colors.black, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () { |
|
|
|
|
state(() {}); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/delete.png", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
return StatefulBuilder( |
|
|
|
|
builder: (context1, state) { |
|
|
|
|
return Container( |
|
|
|
|
alignment: Alignment.topCenter, |
|
|
|
|
width: double.infinity, |
|
|
|
|
height: MediaQuery.of(context).size.height / 2, |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Colors.white, |
|
|
|
|
borderRadius: BorderRadius.only( |
|
|
|
|
topLeft: Radius.circular(8), |
|
|
|
|
topRight: Radius.circular(8), |
|
|
|
|
), |
|
|
|
|
Expanded( |
|
|
|
|
child: Container( |
|
|
|
|
), |
|
|
|
|
child: Column( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
padding: EdgeInsets.only( |
|
|
|
|
top: 8, |
|
|
|
|
top: 16, |
|
|
|
|
left: 16, |
|
|
|
|
right: 16, |
|
|
|
|
bottom: 8, |
|
|
|
|
), |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
Map<String, dynamic> map = shopCarGoods.firstWhere((element) => element["id"] == productId); |
|
|
|
|
map["count"] = count; |
|
|
|
|
shopCarGoods[index] = map; |
|
|
|
|
|
|
|
|
|
shopCarGoods.forEach((element) { |
|
|
|
|
if (element["price"] != null && element["price"] != "") { |
|
|
|
|
double singlePrice = double.tryParse(element["price"]); |
|
|
|
|
allCount += element["count"]; |
|
|
|
|
allPrice += (singlePrice * element["count"]); |
|
|
|
|
child: Row( |
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
"已选商品", |
|
|
|
|
style: TextStyle( |
|
|
|
|
color: Colors.black, |
|
|
|
|
fontSize: 14.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
InkWell( |
|
|
|
|
onTap: () { |
|
|
|
|
widget.clearShopCar(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/delete.png", |
|
|
|
|
width: 22, |
|
|
|
|
height: 22, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
widget.fc(count, productId, allCount, allPrice); |
|
|
|
|
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"]); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
state((){}); |
|
|
|
|
}, |
|
|
|
|
shopCarGoods: _shopCarGoods(position), |
|
|
|
|
queryMiNiDetail: widget.queryMiNiDetail, |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
widget.fc(count, productId, allCount, allPrice); |
|
|
|
|
|
|
|
|
|
state(() {}); |
|
|
|
|
}, |
|
|
|
|
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, |
|
|
|
|
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, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Text( |
|
|
|
|
"¥" + allPrice.toString(), |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 20.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
color: Color(0xFF32A060), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
children: [ |
|
|
|
|
Spacer(), |
|
|
|
|
Text( |
|
|
|
|
S.of(context).heji, |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 12.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Spacer(), |
|
|
|
|
GestureDetector( |
|
|
|
|
Text( |
|
|
|
|
"¥" + allPrice.toString(), |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 20.sp, |
|
|
|
|
fontWeight: MyFontWeight.medium, |
|
|
|
|
color: Color(0xFF32A060), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Spacer(), |
|
|
|
|
GestureDetector( |
|
|
|
|
onTap: () { |
|
|
|
|
Navigator.of(context).pushNamed( |
|
|
|
|
'/router/settlement', |
|
|
|
|
arguments: {}, |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
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).pushNamed( |
|
|
|
|
'/router/settlement', |
|
|
|
|
arguments: {}, |
|
|
|
|
); |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
}, |
|
|
|
|
child: Image.asset( |
|
|
|
|
"assets/image/shopp.png", |
|
|
|
|
width: 88, |
|
|
|
|
height: 88, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
Positioned( |
|
|
|
|
right: 15, |
|
|
|
|
top: 14, |
|
|
|
|
child: RoundButton( |
|
|
|
|
width: 103.w, |
|
|
|
|
height: 54.h, |
|
|
|
|
text: S.current.jiesuan, |
|
|
|
|
width: 17, |
|
|
|
|
height: 17, |
|
|
|
|
text: allCount.toString(), |
|
|
|
|
textColor: Colors.white, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
backgroup: Color(0xFF32A060), |
|
|
|
|
radius: 0, |
|
|
|
|
fontSize: 16.sp, |
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 5.h), |
|
|
|
|
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'); |
|
|
|
|
}, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|