Browse Source

1、收藏夹新增滑动删除

tags/0.0.2^2
PH2 4 years ago
parent
commit
df31200376
7 changed files with 101 additions and 16 deletions
  1. +1
    -0
      lib/pages/favorites_page/favorites_page.dart
  2. +1
    -1
      lib/widgets/favorites/dialog/favorites_dialog_widget.dart
  3. +15
    -0
      lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart
  4. +6
    -0
      lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart
  5. +24
    -8
      lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart
  6. +52
    -7
      lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart
  7. +2
    -0
      pubspec.yaml

+ 1
- 0
lib/pages/favorites_page/favorites_page.dart View File

@@ -171,6 +171,7 @@ class _FavoritesPageContainerState extends State<_FavoritesPageContainer> with T
if (length > 0) { if (length > 0) {
int index = -1; int index = -1;
return TabBarView( return TabBarView(
physics: NeverScrollableScrollPhysics(),
controller: _tabController, controller: _tabController,
children: model.tabList.map((e) { children: model.tabList.map((e) {
++index; ++index;


+ 1
- 1
lib/widgets/favorites/dialog/favorites_dialog_widget.dart View File

@@ -23,7 +23,7 @@ class FavoritesDialogWidget extends StatelessWidget {
child: Column( child: Column(
children: <Widget>[ 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), const SizedBox(height: 44),
Row( Row(
children: <Widget>[ children: <Widget>[


+ 15
- 0
lib/widgets/favorites/goods_list/bloc/favorites_goods_list_bloc.dart View File

@@ -60,10 +60,16 @@ class FavoritesGoodsListBloc extends Bloc<FavoritesGoodsListEvent, FavoritesGood
yield* _mapSelectAllEventToState(event); yield* _mapSelectAllEventToState(event);
} }


/// 取消选中所有商品
if(event is FavoritesGoodsListGoodsCancelAllEvent){ if(event is FavoritesGoodsListGoodsCancelAllEvent){
yield* _mapCancelAllEventToState(event); yield* _mapCancelAllEventToState(event);
} }


/// 右滑删除单个商品
if(event is FavoritesGoodsListSlideDeleteEvent){
yield* _mapSlideDeleteEventToState(event);
}

// /// 切换样式 // /// 切换样式
// if (event is FavoritesGoodsListChangeStyleEvent) { // if (event is FavoritesGoodsListChangeStyleEvent) {
// yield* _mapChangeStyleEventToState(event); // 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();
}
}




// /// 切换样式 // /// 切换样式


+ 6
- 0
lib/widgets/favorites/goods_list/bloc/favorites_goods_list_event.dart View File

@@ -19,6 +19,12 @@ class FavoritesGoodsListSearchEvent extends FavoritesGoodsListEvent {
FavoritesGoodsListSearchEvent(this.keyword); FavoritesGoodsListSearchEvent(this.keyword);
} }


/// 右滑动删除
class FavoritesGoodsListSlideDeleteEvent extends FavoritesGoodsListEvent{
final int index;
FavoritesGoodsListSlideDeleteEvent(this.index);
}

/// 删除 /// 删除
class FavoritesGoodsListDeleteEvent extends FavoritesGoodsListEvent {} class FavoritesGoodsListDeleteEvent extends FavoritesGoodsListEvent {}




+ 24
- 8
lib/widgets/favorites/goods_list/bloc/favorites_goods_list_repository.dart View File

@@ -22,17 +22,33 @@ class FavoritesGoodsListRepository {
return _selectIndex.length; return _selectIndex.length;
} }


/// 选中所有
Future<FavoritesGoodsListDataModel> selectAllData() async {
/// 右滑动删除当个商品
Future<FavoritesGoodsListDataModel> slideDeleteData(int index) async{
_selectIndex.clear(); _selectIndex.clear();
int index = 0;
_oldData.lists.forEach((element) { _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;
} }


/// 单个选中状态 /// 单个选中状态


+ 52
- 7
lib/widgets/favorites/goods_list/favorites_goods_list_widget.dart View File

@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:pull_to_refresh/pull_to_refresh.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/dialog/tip_dialog/tip_dialog.dart';
import 'package:zhiying_base_widget/pages/favorites_page/model/favorites_style_model.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 { class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsListWidgetContainer> with AutomaticKeepAliveClientMixin {
RefreshController _refreshController; RefreshController _refreshController;
SlidableController _slidableController;


// 是否编辑中 // 是否编辑中
bool isEditing = false; bool isEditing = false;
@@ -61,6 +63,21 @@ class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsList
BlocProvider.of<FavoritesGoodsListBloc>(context).add(FavoritesGoodsListOnLoadEvent()); 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){ void _onClickGoods(int index){
BlocProvider.of<FavoritesGoodsListBloc>(context).add(FavoritesGoodsListSignGoodsSelectEvent(index)); BlocProvider.of<FavoritesGoodsListBloc>(context).add(FavoritesGoodsListSignGoodsSelectEvent(index));
@@ -92,6 +109,7 @@ class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsList
@override @override
void initState() { void initState() {
_refreshController = RefreshController(); _refreshController = RefreshController();
_slidableController = SlidableController();
BlocProvider.of<FavoritesGoodsListBloc>(context).add(FavoritesGoodsListInitEvent()); BlocProvider.of<FavoritesGoodsListBloc>(context).add(FavoritesGoodsListInitEvent());
super.initState(); super.initState();
} }
@@ -214,13 +232,40 @@ class __FavoritesGoodsListWidgetContainerState extends State<_FavoritesGoodsList
), ),
), ),
Expanded( 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
),
), ),
) )
], ],


+ 2
- 0
pubspec.yaml View File

@@ -31,6 +31,8 @@ dependencies:
flutter_native_image: ^0.0.5 flutter_native_image: ^0.0.5
#字符检测 #字符检测
string_validator: 0.1.4 string_validator: 0.1.4
# 列表滑动删除
flutter_slidable: 0.5.7
# image_gallery_saver: ^1.6.0 # image_gallery_saver: ^1.6.0


permission_handler: permission_handler:


Loading…
Cancel
Save