diff --git a/lib/pages/favorites_page/favorites_page.dart b/lib/pages/favorites_page/favorites_page.dart index d7364a7..e359d94 100644 --- a/lib/pages/favorites_page/favorites_page.dart +++ b/lib/pages/favorites_page/favorites_page.dart @@ -171,6 +171,7 @@ class _FavoritesPageContainerState extends State<_FavoritesPageContainer> with T if (length > 0) { int index = -1; return TabBarView( + physics: NeverScrollableScrollPhysics(), controller: _tabController, children: model.tabList.map((e) { ++index; diff --git a/lib/widgets/favorites/dialog/favorites_dialog_widget.dart b/lib/widgets/favorites/dialog/favorites_dialog_widget.dart index 39ecb24..1790f47 100644 --- a/lib/widgets/favorites/dialog/favorites_dialog_widget.dart +++ b/lib/widgets/favorites/dialog/favorites_dialog_widget.dart @@ -23,7 +23,7 @@ class FavoritesDialogWidget extends StatelessWidget { child: Column( children: [ /// 标题 - Text(styleModel?.bgText, style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: HexColor.fromHex(styleModel?.bgTextColor ?? '#333333'))), + Text(styleModel?.bgText ?? '', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: HexColor.fromHex(styleModel?.bgTextColor ?? '#333333'))), const SizedBox(height: 44), Row( children: [ diff --git a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart index 4ca4489..871e0aa 100644 --- a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart +++ b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart @@ -60,10 +60,16 @@ class FavoritesGoodsListBloc extends Bloc _mapSlideDeleteEventToState(FavoritesGoodsListSlideDeleteEvent event) async*{ + var result = await repository.slideDeleteData(event.index); + if (!EmptyUtil.isEmpty(result)) { + yield FavoritesGoodsListLoadedState(dataModel: result); + } else { + yield FavoritesGoodsListErrorState(); + } + } // /// 切换样式 diff --git a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart index d687a76..e601921 100644 --- a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart +++ b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart @@ -19,6 +19,12 @@ class FavoritesGoodsListSearchEvent extends FavoritesGoodsListEvent { FavoritesGoodsListSearchEvent(this.keyword); } +/// 右滑动删除 +class FavoritesGoodsListSlideDeleteEvent extends FavoritesGoodsListEvent{ + final int index; + FavoritesGoodsListSlideDeleteEvent(this.index); +} + /// 删除 class FavoritesGoodsListDeleteEvent extends FavoritesGoodsListEvent {} diff --git a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart index 42d3572..e0529d3 100644 --- a/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart +++ b/lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart @@ -22,17 +22,33 @@ class FavoritesGoodsListRepository { return _selectIndex.length; } - /// 选中所有 - Future selectAllData() async { + /// 右滑动删除当个商品 + Future slideDeleteData(int index) async{ _selectIndex.clear(); - int index = 0; _oldData.lists.forEach((element) { - element.isSelect = true; - _selectIndex[index] = index; - ++index; + element.isSelect = false; }); - _oldData.isAllSelect = true; - return _oldData; + _oldData.isAllSelect = false; + _selectIndex[index] = index; + return delete(); + } + + /// 选中所有 + Future selectAllData() async { + try { + _selectIndex.clear(); + int index = 0; + _oldData.lists.forEach((element) { + element.isSelect = true; + _selectIndex[index] = index; + ++index; + }); + _oldData.isAllSelect = true; + return _oldData; + }catch(e, s){ + Logger.error(e,s); + } + return null; } /// 单个选中状态 diff --git a/lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart b/lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart index 7f3bb6c..1f458ec 100644 --- a/lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart +++ b/lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart @@ -1,6 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:zhiying_base_widget/dialog/tip_dialog/tip_dialog.dart'; import 'package:zhiying_base_widget/pages/favorites_page/model/favorites_style_model.dart'; @@ -46,6 +47,7 @@ class _FavoritesGoodsListWidgetContainer extends StatefulWidget { class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsListWidgetContainer> with AutomaticKeepAliveClientMixin { RefreshController _refreshController; + SlidableController _slidableController; // 是否编辑中 bool isEditing = false; @@ -61,6 +63,21 @@ class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsList BlocProvider.of(context).add(FavoritesGoodsListOnLoadEvent()); } + /// 右边划删除 + void _onSlideDelete(ConfirmDialog styleModel,int index) async{ + var result = await showDialog(context: context, child: FavoritesDialogWidget(styleModel: styleModel,)); + if(result == 1){ + BlocProvider.of(context).add(FavoritesGoodsListSlideDeleteEvent(index)); + // Slidable.of(context)?.renderingMode == SlidableRenderingMode.none ? Slidable.of(context)?.open() : Slidable.of(context)?.close(); + // Slidable.of(context)?.close(); + } + } + + /// 分享商品 + void _onSlideShare() async{ + // TODO 分享商品还没弄 + } + /// 商品点击选中 void _onClickGoods(int index){ BlocProvider.of(context).add(FavoritesGoodsListSignGoodsSelectEvent(index)); @@ -92,6 +109,7 @@ class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsList @override void initState() { _refreshController = RefreshController(); + _slidableController = SlidableController(); BlocProvider.of(context).add(FavoritesGoodsListInitEvent()); super.initState(); } @@ -214,13 +232,40 @@ class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsList ), ), Expanded( - child: HomeGoodsItemSingle( - item, - HomeGoodsStyleModel()..listStyle = styleModel?.listStyle, - marginBottom: 0, - marginLeft: 0, - marginRight: 0, - marginTop: 0, + child: Slidable( + key: Key(index.toString()), + controller: _slidableController, + enabled: !isEditing, + actionPane: SlidableDrawerActionPane(), + actionExtentRatio: 0.25, + closeOnScroll: false, + secondaryActions: [ + /// 分享 + IconSlideAction( + caption: '分享', + color: Colors.deepOrange, + icon: Icons.share, + onTap: () => _onSlideShare(), + closeOnTap: true, + ), + + /// 删除 + IconSlideAction( + caption: '删除', + color: Colors.red, + closeOnTap: true, + icon: Icons.delete, + onTap: () => _onSlideDelete(styleModel?.confirmDialog ,index), + ), + ], + child: HomeGoodsItemSingle( + item, + HomeGoodsStyleModel()..listStyle = styleModel?.listStyle, + marginBottom: 8, + marginLeft: 0, + marginRight: 0, + marginTop: 0 + ), ), ) ], diff --git a/pubspec.yaml b/pubspec.yaml index 8a52ad3..5b7f2b8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,8 @@ dependencies: flutter_native_image: ^0.0.5 #字符检测 string_validator: 0.1.4 + # 列表滑动删除 + flutter_slidable: 0.5.7 # image_gallery_saver: ^1.6.0 permission_handler: