提交 6dc2c36c authored 作者: yueweilu's avatar yueweilu

购物车 条目左滑删除

上级 7233760d
......@@ -29,7 +29,8 @@ class CourseModel {
this.price,
this.vipPrice,
this.status,
this.cartId
this.cartId,
this.selected = false
///
});
......@@ -47,6 +48,13 @@ class CourseModel {
readNum = json['read_num'];
isCollection = json['is_collection'];
collectionId = json['collection_id'];
/// 购物车列表需要参数
price = json['price'];
vipPrice = json['vip_price'];
status = json['status'];
cartId = json['cart_id'];
selected = false;
///
}
num? bookId;
String? bookName;
......@@ -66,10 +74,14 @@ class CourseModel {
String? vipPrice;
num? status;
num? cartId;
// 选中状态
late bool selected;
///
int get type {
if (progress == '0.00%'){
return 0;
......
......@@ -3,8 +3,12 @@ library book_pay;
import 'package:flutter/material.dart';
import 'package:flutter_book/theme.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import '../../models/index.dart';
import '../../utils/index.dart';
import '../book_shop/index.dart';
part 'controller.dart';
part 'view.dart';
\ No newline at end of file
part 'view.dart';
part 'widgets/item.dart';
\ No newline at end of file
......@@ -34,7 +34,7 @@ class _BookPayPageState extends State<BookPayPage> {
child: SingleChildScrollView(
child: Column(
children: [
const BookCell(type: BookCellType.pay,),
const BuildItem(),
const SizedBox(height: 10,),
Container(
height: 100,
......
part of book_pay;
class BuildItem extends StatelessWidget {
final CourseModel? model;
const BuildItem({
super.key,
this.model,
});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
borderRadius:BorderRadius.circular(5),
color: Colors.white,
boxShadow: [
BoxShadow(
color: const Color(0xFFC7C7C7).withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: const Offset(3, 0), // changes the position of the shadow
),
]
),
margin: const EdgeInsets.only(left: 10,right: 10,top: 10),
height: 110,
child: Row(
children: [
///左侧
Container(
margin: const EdgeInsets.only(left: 12,right: 11),
child: Row(
children: [
Container(
height: 17,
width: 17,
color: Colors.cyan,
),
const SizedBox(width: 12,),
Container(
decoration: BoxDecoration(
color: Colors.cyan,
borderRadius: BorderRadius.circular(3),
boxShadow: [
BoxShadow(
color: const Color(0xFF707070).withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: const Offset(3, 0), // changes the position of the shadow
),
]
),
// color: Colors.white,
height: 86,
width: 72,
child: Container(
padding: const EdgeInsets.all(2),
child: Container(
color: Colors.cyan,
),
),
)
],
),
),
///右侧
Expanded(
child: Container(
padding: const EdgeInsets.only(top: 12,bottom: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(model != null?model!.bookName.toString():'',style: const TextStyle(fontSize: 13,fontWeight: Fonts.medium,color: Colours.c3),maxLines: 2,overflow: TextOverflow.ellipsis,),
const SizedBox(height: 5,),
Text(model != null?model!.authors.toString():'',style: const TextStyle(fontSize: 11,color: Colours.c9)),
],
),
Text('¥${model != null?model!.authors.toString():''}',style: const TextStyle(fontSize: 14,fontWeight: FontWeight.w500,color: AppTheme.primary)),
],
),
),
)
],
)
);
}
}
......@@ -20,7 +20,16 @@ class BookshopController extends GetxController {
super.onClose();
}
/// 删除购物车 单个书籍
void delCart({
required String cartId,
}) async {
bool result = await ShopAPI.delCart(
cartId: cartId);
if (result) {
onRefresh();
}
}
/// 获取课程内图书列表
Future<void> _getCart([bool isRefresh = false]) async {
......@@ -33,12 +42,14 @@ class BookshopController extends GetxController {
// 如果是刷新 清理数据
if (isRefresh) carts.clear();
carts.addAll(result);
carts.addAll(_test());
_page ++;
_noMore = result.length < _limit;
update();
}
void onRefresh() async {
try {
await _getCart(true);
......@@ -62,4 +73,12 @@ class BookshopController extends GetxController {
}
}
List<CourseModel> _test(){
return [
CourseModel(),
CourseModel(),
CourseModel(),
];
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_book/utils/index.dart';
import 'package:flutter_book/widgets/index.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:go_router/go_router.dart';
......
......@@ -25,69 +25,20 @@ class _BookShopPageState extends State<BookShopPage> {
onLoading: controller.onLoading,
child: ListView.builder(
itemBuilder: (BuildContext context,int index){
return BookCell(model: controller.carts[index],);
CourseModel model = controller.carts[index];
return BookCell(model:model ,onTap: (){
controller.delCart(cartId: model.cartId.toString());
},);
},
itemCount: controller.carts.length,
),
),
),
createCounter()
BuildCounter()
],
),
),
);
}
Widget createCounter() {
return Container(
color: Colors.white,
padding: const EdgeInsets.only(left: 20,right: 15),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
height: 17,
width: 17,
color: Colors.yellow,
),
const SizedBox(width: 11),
const Text('全选',style: TextStyle(color: Color(0xFF333333),fontSize: 12,fontWeight: FontWeight.w500)),
const SizedBox(width: 15,),
const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('合计 ¥98.9',style: TextStyle(color: AppTheme.primary,fontSize: 12,fontWeight: FontWeight.w500)),
Text('已选 2 件',style: TextStyle(color: Color(0xFF999999),fontSize: 10,))
],
)
],
),
GestureDetector(
onTap: (){
context.pushNamed(Routes.bookPay);
},
child: Container(
margin: const EdgeInsets.symmetric(vertical: 9),
decoration: BoxDecoration(
color: AppTheme.primary,
borderRadius: BorderRadius.circular(15),
),
padding: const EdgeInsets.symmetric(vertical: 5,horizontal: 18),
child: const Text('结算(2)',style: TextStyle(color: Colors.white,fontSize: 12,fontWeight: FontWeight.w500),),
),
)
],
),
Container(
height: 1,
color: const Color(0xFFF9F9F9),
)
],
),
);
}
}
part of book_shop;
enum BookCellType {
normal,
pay,
}
class BookCell extends StatelessWidget {
final BookCellType? type;
final CourseModel? model;
final CourseModel model;
final void Function() onTap;
const BookCell({
super.key,
this.type = BookCellType.normal,
this.model
required this.model,
required this.onTap
});
@override
......@@ -23,76 +18,94 @@ class BookCell extends StatelessWidget {
boxShadow: [
BoxShadow(
color: const Color(0xFFC7C7C7).withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
spreadRadius: 0,
blurRadius: 10,
offset: const Offset(3, 0), // changes the position of the shadow
),
]
],
border:Border.all(width: 0.5,color: AppTheme.primary)
),
margin: const EdgeInsets.only(left: 10,right: 10,top: 10),
height: 110,
child: Row(
children: [
///左侧
Container(
margin: const EdgeInsets.only(left: 12,right: 11),
child: Row(
children: [
type == BookCellType.normal?Container(
height: 17,
width: 17,
color: Colors.cyan,
):const SizedBox(),
type == BookCellType.normal?const SizedBox(width: 12,):const SizedBox(),
Container(
decoration: BoxDecoration(
color: Colors.cyan,
borderRadius: BorderRadius.circular(3),
boxShadow: [
BoxShadow(
color: const Color(0xFF707070).withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: const Offset(3, 0), // changes the position of the shadow
),
]
child: Slidable(
endActionPane: ActionPane(
motion: const ScrollMotion(),
children: [
SlidableAction(
// An action can be bigger than the others.
onPressed: (BuildContext context){
onTap;
},
backgroundColor: AppTheme.primary,
foregroundColor: Colors.white,
// icon: Icons.archive,
label: '删除',
),
],
),
child: Row(
children: [
///左侧
Container(
margin: const EdgeInsets.only(left: 12,right: 11),
child: Row(
children: [
Container(
height: 17,
width: 17,
color: Colors.cyan,
),
// color: Colors.white,
height: 86,
width: 72,
child: Container(
padding: const EdgeInsets.all(2),
const SizedBox(width: 12,),
Container(
decoration: BoxDecoration(
color: Colors.cyan,
borderRadius: BorderRadius.circular(3),
boxShadow: [
BoxShadow(
color: const Color(0xFF707070).withOpacity(0.5),
spreadRadius: 2,
blurRadius: 5,
offset: const Offset(3, 0), // changes the position of the shadow
),
]
),
// color: Colors.white,
height: 86,
width: 72,
child: Container(
color: Colors.cyan,
padding: const EdgeInsets.all(2),
child: Container(
color: Colors.cyan,
),
),
),
)
],
),
),
///右侧
Expanded(
child: Container(
padding: const EdgeInsets.only(top: 12,bottom: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(model != null?model!.bookName.toString():'',style: const TextStyle(fontSize: 13,fontWeight: Fonts.medium,color: Colours.c3),maxLines: 2,overflow: TextOverflow.ellipsis,),
const SizedBox(height: 5,),
Text(model != null?model!.authors.toString():'',style: const TextStyle(fontSize: 11,color: Colours.c9)),
],
),
Text('¥${model != null?model!.authors.toString():''}',style: const TextStyle(fontSize: 14,fontWeight: FontWeight.w500,color: AppTheme.primary)),
],
),
)
],
),
),
)
],
///右侧
Expanded(
child: Container(
padding: const EdgeInsets.only(top: 12,bottom: 10),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(model != null?model!.bookName.toString():'',style: const TextStyle(fontSize: 13,fontWeight: Fonts.medium,color: Colours.c3),maxLines: 2,overflow: TextOverflow.ellipsis,),
const SizedBox(height: 5,),
Text(model != null?model!.authors.toString():'',style: const TextStyle(fontSize: 11,color: Colours.c9)),
],
),
Text('¥${model != null?model!.authors.toString():''}',style: const TextStyle(fontSize: 14,fontWeight: FontWeight.w500,color: AppTheme.primary)),
],
),
),
)
],
),
)
);
}
......
part of book_shop;
class Counter extends StatelessWidget {
const Counter({Key? key}) : super(key: key);
class BuildCounter extends StatelessWidget {
const BuildCounter({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Row(
children: [
GestureDetector(
onTap: (){
},
child: Row(
return Container(
color: Colors.white,
padding: const EdgeInsets.only(left: 20,right: 15),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(width: 20,height: 20,color: Colors.cyan,),
const SizedBox(width: 11,),
const Text('全选',style: TextStyle(color: Color(0xFF333333),fontSize: 12,fontWeight:FontWeight.w500)),
Row(
children: [
Container(
height: 17,
width: 17,
color: Colors.yellow,
),
const SizedBox(width: 11),
const Text('全选',style: TextStyle(color: Color(0xFF333333),fontSize: 12,fontWeight: FontWeight.w500)),
const SizedBox(width: 15,),
const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('合计 ¥98.9',style: TextStyle(color: AppTheme.primary,fontSize: 12,fontWeight: FontWeight.w500)),
Text('已选 2 件',style: TextStyle(color: Color(0xFF999999),fontSize: 10,))
],
)
],
),
GestureDetector(
onTap: (){
context.pushNamed(Routes.bookPay);
},
child: Container(
margin: const EdgeInsets.symmetric(vertical: 9),
decoration: BoxDecoration(
color: AppTheme.primary,
borderRadius: BorderRadius.circular(15),
),
padding: const EdgeInsets.symmetric(vertical: 5,horizontal: 18),
child: const Text('结算(2)',style: TextStyle(color: Colors.white,fontSize: 12,fontWeight: FontWeight.w500),),
),
)
],
),
),
Column(
children: [
Text('合计',style: TextStyle(color: AppTheme.primary)),
Text('已选1件',style: TextStyle(color: Color(0xFF333333)),)
],
),
],
Container(
height: 1,
color: const Color(0xFFF9F9F9),
)
],
),
);
}
}
......@@ -187,6 +187,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "5.8.2"
flutter_slidable:
dependency: "direct main"
description:
name: flutter_slidable
sha256: "19ed4813003a6ff4e9c6bcce37e792a2a358919d7603b2b31ff200229191e44c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.1"
flutter_sound:
dependency: "direct main"
description:
......
......@@ -79,6 +79,8 @@ dependencies:
flutter_star: ^1.2.0
# toast
oktoast: ^3.0.0
# 策划
flutter_slidable: ^3.0.1
dev_dependencies:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论