@@ -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; | |||
@@ -23,7 +23,7 @@ class FavoritesDialogWidget extends StatelessWidget { | |||
child: Column( | |||
children: <Widget>[ | |||
/// 标题 | |||
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: <Widget>[ | |||
@@ -60,10 +60,16 @@ class FavoritesGoodsListBloc extends Bloc<FavoritesGoodsListEvent, FavoritesGood | |||
yield* _mapSelectAllEventToState(event); | |||
} | |||
/// 取消选中所有商品 | |||
if(event is FavoritesGoodsListGoodsCancelAllEvent){ | |||
yield* _mapCancelAllEventToState(event); | |||
} | |||
/// 右滑删除单个商品 | |||
if(event is FavoritesGoodsListSlideDeleteEvent){ | |||
yield* _mapSlideDeleteEventToState(event); | |||
} | |||
// /// 切换样式 | |||
// if (event is FavoritesGoodsListChangeStyleEvent) { | |||
// yield* _mapChangeStyleEventToState(event); | |||
@@ -159,6 +165,15 @@ class FavoritesGoodsListBloc extends Bloc<FavoritesGoodsListEvent, FavoritesGood | |||
} | |||
} | |||
/// 右滑动删除商品 | |||
Stream<FavoritesGoodsListState> _mapSlideDeleteEventToState(FavoritesGoodsListSlideDeleteEvent event) async*{ | |||
var result = await repository.slideDeleteData(event.index); | |||
if (!EmptyUtil.isEmpty(result)) { | |||
yield FavoritesGoodsListLoadedState(dataModel: result); | |||
} else { | |||
yield FavoritesGoodsListErrorState(); | |||
} | |||
} | |||
// /// 切换样式 | |||
@@ -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 {} | |||
@@ -22,17 +22,33 @@ class FavoritesGoodsListRepository { | |||
return _selectIndex.length; | |||
} | |||
/// 选中所有 | |||
Future<FavoritesGoodsListDataModel> selectAllData() async { | |||
/// 右滑动删除当个商品 | |||
Future<FavoritesGoodsListDataModel> 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<FavoritesGoodsListDataModel> 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; | |||
} | |||
/// 单个选中状态 | |||
@@ -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<FavoritesGoodsListBloc>(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<FavoritesGoodsListBloc>(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<FavoritesGoodsListBloc>(context).add(FavoritesGoodsListSignGoodsSelectEvent(index)); | |||
@@ -92,6 +109,7 @@ class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsList | |||
@override | |||
void initState() { | |||
_refreshController = RefreshController(); | |||
_slidableController = SlidableController(); | |||
BlocProvider.of<FavoritesGoodsListBloc>(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: <Widget>[ | |||
/// 分享 | |||
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 | |||
), | |||
), | |||
) | |||
], | |||
@@ -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: | |||