Skip to content

Commit

Permalink
56/57change
Browse files Browse the repository at this point in the history
  • Loading branch information
newlycn committed Apr 18, 2019
1 parent 752af0d commit cd274de
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 14 deletions.
5 changes: 4 additions & 1 deletion lib/model/cartInfo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ class CartInfoModel {
int count;
double price;
String images;
bool isCheck;

CartInfoModel(
{this.goodsId, this.goodsName, this.count, this.price, this.images});
{this.goodsId, this.goodsName, this.count, this.price, this.images,this.isCheck});

CartInfoModel.fromJson(Map<String, dynamic> json) {
goodsId = json['goodsId'];
goodsName = json['goodsName'];
count = json['count'];
price = json['price'];
images = json['images'];
isCheck = json['isCheck'];
}

Map<String, dynamic> toJson() {
Expand All @@ -23,6 +25,7 @@ class CartInfoModel {
data['count'] = this.count;
data['price'] = this.price;
data['images'] = this.images;
data['isCheck'] = this.isCheck;
return data;
}
}
17 changes: 9 additions & 8 deletions lib/pages/cart_page/cart_bottom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class CartBottom extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(5.0),
margin: EdgeInsets.all(3.0),
color: Colors.white,
width: ScreenUtil().setWidth(750),
child: Row(
Expand All @@ -22,6 +22,7 @@ class CartBottom extends StatelessWidget {
//全选按钮
Widget _selectAllBtn(){
return Container(
width: ScreenUtil().setWidth(180),
child: Row(
children: <Widget>[
Checkbox(
Expand All @@ -39,29 +40,29 @@ class CartBottom extends StatelessWidget {
Widget _allPriceArea(){

return Container(
width: ScreenUtil().setWidth(430),
width: ScreenUtil().setWidth(400),
alignment: Alignment.centerRight,
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
alignment: Alignment.centerRight,
width: ScreenUtil().setWidth(280),
width: ScreenUtil().setWidth(250),
child: Text(
'合计:',
style:TextStyle(
fontSize: ScreenUtil().setSp(36)
fontSize: ScreenUtil().setSp(32)
)
),
),
Container(
alignment: Alignment.centerLeft,
width: ScreenUtil().setWidth(150),
width: ScreenUtil().setWidth(140),
child: Text(
'¥1922',
style:TextStyle(
fontSize: ScreenUtil().setSp(36),
fontSize: ScreenUtil().setSp(32),
color: Colors.red,
)
),
Expand All @@ -72,8 +73,8 @@ class CartBottom extends StatelessWidget {
],
),
Container(
width: ScreenUtil().setWidth(430),
alignment: Alignment.centerRight,
width: ScreenUtil().setWidth(400),
alignment: Alignment.center,
child: Text(
'满10元免配送费,预购免配送费',
style: TextStyle(
Expand Down
73 changes: 73 additions & 0 deletions lib/pages/cart_page/cart_count.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CartCount extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
width: ScreenUtil().setWidth(165),
margin: EdgeInsets.only(top:5.0),
decoration: BoxDecoration(
border:Border.all(width: 1 , color:Colors.black12)
),
child: Row(
children: <Widget>[
_reduceBtn(),
_countArea(),
_addBtn(),
],
),
);
}

// 减少按钮
Widget _reduceBtn(){
return InkWell(
onTap: (){},
child: Container(
width: ScreenUtil().setWidth(45),
height: ScreenUtil().setHeight(45),
alignment: Alignment.center,

decoration: BoxDecoration(
color: Colors.white,
border:Border(
right:BorderSide(width:1,color:Colors.black12)
)
),
child: Text('-'),
),
);
}

//添加按钮
Widget _addBtn(){
return InkWell(
onTap: (){},
child: Container(
width: ScreenUtil().setWidth(45),
height: ScreenUtil().setHeight(45),
alignment: Alignment.center,

decoration: BoxDecoration(
color: Colors.white,
border:Border(
left:BorderSide(width:1,color:Colors.black12)
)
),
child: Text('+'),
),
);
}

//中间数量显示区域
Widget _countArea(){
return Container(
width: ScreenUtil().setWidth(70),
height: ScreenUtil().setHeight(45),
alignment: Alignment.center,
color: Colors.white,
child: Text('1'),
);
}
}
6 changes: 4 additions & 2 deletions lib/pages/cart_page/cart_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../model/cartInfo.dart';
import './cart_count.dart';


class CartItem extends StatelessWidget {
Expand Down Expand Up @@ -34,7 +35,7 @@ class CartItem extends StatelessWidget {
Widget _cartCheckBt(item){
return Container(
child: Checkbox(
value: true,
value: item.isCheck,
activeColor:Colors.pink,
onChanged: (bool val){},
),
Expand Down Expand Up @@ -62,7 +63,8 @@ class CartItem extends StatelessWidget {
alignment: Alignment.topLeft,
child: Column(
children: <Widget>[
Text(item.goodsName)
Text(item.goodsName),
CartCount()
],
),
);
Expand Down
7 changes: 4 additions & 3 deletions lib/provide/cart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ class CartProvide with ChangeNotifier{
'goodsName':goodsName,
'count':count,
'price':price,
'images':images
'images':images,
'isCheck': true //是否已经选择
};
tempList.add(newGoods);
cartList.add(CartInfoModel.fromJson(newGoods));
}
//把字符串进行encode操作,
cartString= json.encode(tempList).toString();
print("字符串>>>>>>>>>>>>>>>>>>>${cartString}");
print("数据模型>>>>>>>>>>>>>>>>>>>${cartList}");
//print("字符串>>>>>>>>>>>>>>>>>>>${cartString}");
//print("数据模型>>>>>>>>>>>>>>>>>>>${cartList}");

prefs.setString('cartInfo', cartString);//进行持久化
notifyListeners();
Expand Down

0 comments on commit cd274de

Please sign in to comment.