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

购物车 条目左滑删除

上级 7233760d
...@@ -29,7 +29,8 @@ class CourseModel { ...@@ -29,7 +29,8 @@ class CourseModel {
this.price, this.price,
this.vipPrice, this.vipPrice,
this.status, this.status,
this.cartId this.cartId,
this.selected = false
/// ///
}); });
...@@ -47,6 +48,13 @@ class CourseModel { ...@@ -47,6 +48,13 @@ class CourseModel {
readNum = json['read_num']; readNum = json['read_num'];
isCollection = json['is_collection']; isCollection = json['is_collection'];
collectionId = json['collection_id']; collectionId = json['collection_id'];
/// 购物车列表需要参数
price = json['price'];
vipPrice = json['vip_price'];
status = json['status'];
cartId = json['cart_id'];
selected = false;
///
} }
num? bookId; num? bookId;
String? bookName; String? bookName;
...@@ -66,10 +74,14 @@ class CourseModel { ...@@ -66,10 +74,14 @@ class CourseModel {
String? vipPrice; String? vipPrice;
num? status; num? status;
num? cartId; num? cartId;
// 选中状态
late bool selected;
/// ///
int get type { int get type {
if (progress == '0.00%'){ if (progress == '0.00%'){
return 0; return 0;
......
...@@ -3,8 +3,12 @@ library book_pay; ...@@ -3,8 +3,12 @@ library book_pay;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/theme.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'; import '../book_shop/index.dart';
part 'controller.dart'; part 'controller.dart';
part 'view.dart'; part 'view.dart';
part 'widgets/item.dart';
\ No newline at end of file
...@@ -34,7 +34,7 @@ class _BookPayPageState extends State<BookPayPage> { ...@@ -34,7 +34,7 @@ class _BookPayPageState extends State<BookPayPage> {
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
children: [ children: [
const BookCell(type: BookCellType.pay,), const BuildItem(),
const SizedBox(height: 10,), const SizedBox(height: 10,),
Container( Container(
height: 100, 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 { ...@@ -20,7 +20,16 @@ class BookshopController extends GetxController {
super.onClose(); 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 { Future<void> _getCart([bool isRefresh = false]) async {
...@@ -33,12 +42,14 @@ class BookshopController extends GetxController { ...@@ -33,12 +42,14 @@ class BookshopController extends GetxController {
// 如果是刷新 清理数据 // 如果是刷新 清理数据
if (isRefresh) carts.clear(); if (isRefresh) carts.clear();
carts.addAll(result); carts.addAll(result);
carts.addAll(_test());
_page ++; _page ++;
_noMore = result.length < _limit; _noMore = result.length < _limit;
update(); update();
} }
void onRefresh() async { void onRefresh() async {
try { try {
await _getCart(true); await _getCart(true);
...@@ -62,4 +73,12 @@ class BookshopController extends GetxController { ...@@ -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'; ...@@ -4,6 +4,7 @@ import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_book/utils/index.dart'; import 'package:flutter_book/utils/index.dart';
import 'package:flutter_book/widgets/index.dart'; import 'package:flutter_book/widgets/index.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
......
...@@ -25,69 +25,20 @@ class _BookShopPageState extends State<BookShopPage> { ...@@ -25,69 +25,20 @@ class _BookShopPageState extends State<BookShopPage> {
onLoading: controller.onLoading, onLoading: controller.onLoading,
child: ListView.builder( child: ListView.builder(
itemBuilder: (BuildContext context,int index){ 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, 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; part of book_shop;
enum BookCellType {
normal,
pay,
}
class BookCell extends StatelessWidget { class BookCell extends StatelessWidget {
final BookCellType? type; final CourseModel model;
final CourseModel? model; final void Function() onTap;
const BookCell({ const BookCell({
super.key, super.key,
this.type = BookCellType.normal, required this.model,
this.model required this.onTap
}); });
@override @override
...@@ -23,14 +18,31 @@ class BookCell extends StatelessWidget { ...@@ -23,14 +18,31 @@ class BookCell extends StatelessWidget {
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: const Color(0xFFC7C7C7).withOpacity(0.5), color: const Color(0xFFC7C7C7).withOpacity(0.5),
spreadRadius: 2, spreadRadius: 0,
blurRadius: 5, blurRadius: 10,
offset: const Offset(3, 0), // changes the position of the shadow 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), margin: const EdgeInsets.only(left: 10,right: 10,top: 10),
height: 110, height: 110,
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( child: Row(
children: [ children: [
///左侧 ///左侧
...@@ -38,12 +50,12 @@ class BookCell extends StatelessWidget { ...@@ -38,12 +50,12 @@ class BookCell extends StatelessWidget {
margin: const EdgeInsets.only(left: 12,right: 11), margin: const EdgeInsets.only(left: 12,right: 11),
child: Row( child: Row(
children: [ children: [
type == BookCellType.normal?Container( Container(
height: 17, height: 17,
width: 17, width: 17,
color: Colors.cyan, color: Colors.cyan,
):const SizedBox(), ),
type == BookCellType.normal?const SizedBox(width: 12,):const SizedBox(), const SizedBox(width: 12,),
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.cyan, color: Colors.cyan,
...@@ -93,6 +105,7 @@ class BookCell extends StatelessWidget { ...@@ -93,6 +105,7 @@ class BookCell extends StatelessWidget {
), ),
) )
], ],
),
) )
); );
} }
......
part of book_shop; part of book_shop;
class Counter extends StatelessWidget { class BuildCounter extends StatelessWidget {
const Counter({Key? key}) : super(key: key); const BuildCounter({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Row( return Container(
color: Colors.white,
padding: const EdgeInsets.only(left: 20,right: 15),
child: Column(
children: [ 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( GestureDetector(
onTap: (){ onTap: (){
context.pushNamed(Routes.bookPay);
}, },
child: Row( child: Container(
children: [ margin: const EdgeInsets.symmetric(vertical: 9),
Container(width: 20,height: 20,color: Colors.cyan,), decoration: BoxDecoration(
const SizedBox(width: 11,), color: AppTheme.primary,
const Text('全选',style: TextStyle(color: Color(0xFF333333),fontSize: 12,fontWeight:FontWeight.w500)), 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: ...@@ -187,6 +187,14 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "5.8.2" 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: flutter_sound:
dependency: "direct main" dependency: "direct main"
description: description:
......
...@@ -79,6 +79,8 @@ dependencies: ...@@ -79,6 +79,8 @@ dependencies:
flutter_star: ^1.2.0 flutter_star: ^1.2.0
# toast # toast
oktoast: ^3.0.0 oktoast: ^3.0.0
# 策划
flutter_slidable: ^3.0.1
dev_dependencies: dev_dependencies:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论