luckysmg / flutter_swipe_action_cell Goto Github PK
View Code? Open in Web Editor NEWA flutter UI package provides a cell widget that has leading and trailing swipe action menu.
License: Apache License 2.0
A flutter UI package provides a cell widget that has leading and trailing swipe action menu.
License: Apache License 2.0
你好,如何获取侧滑状态,比如侧滑开始,侧滑进行中,侧滑结束?
更换到 2.2.1 打包修复 Flutter 2.10.5版本
Running Gradle task 'assembleProfile'...
../../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_swipe_action_cell-2.2.2/lib/core/cell.dart:1055:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_swipe_action_cell-2.2.2/lib/core/cell.dart:1063:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_swipe_action_cell-2.2.2/lib/core/swipe_pull_align_button.dart:59:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
../../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_swipe_action_cell-2.2.2/lib/core/swipe_pull_button.dart:68:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
之前有很多同学反映按钮内部内容不居中,很难受,目前最新的版本2.0.3
已经支持按钮内部的内容实现自动居中
外层tabview,tabview里面两个页面,一个listview,一个其他。listview 的item为SwipeActionCell,Android下左右滑动会有冲突,iOS不会
版本信息如下:
flutter: 2.0.4
dart: 2.12.2
flutter_swipe_action_cell: ^2.2.0
现象:
在gridview.count中使用swipeActionCell,侧滑删除后,红色覆盖整个cell,但是不会发生形变(移除效果动画)。
RT
问题描述:
在列表视图滑动到最后几行时,就会报出如下红字:
"Cannot get size from a render object that has been marked dirty for layout"
已经被该问题困扰了几天.
issue貌似来自:
package:flutter_swipe_action_cell/core/cell.dart:929:50
@OverRide
void didUpdateWidget(_ContentWidget oldWidget) {
super.didUpdateWidget(oldWidget);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (mounted) widget.onLayoutUpdate(context.size);
});
}
完整的报错信息:
════════ Exception caught by scheduler library ═══════════════════════════
The following assertion was thrown during a scheduler callback:
Cannot get size from a render object that has been marked dirty for layout.
The size of this render object is ambiguous because this render object has been modified since it was last laid out, which typically means that the size getter was called too early in the pipeline (e.g., during the build phase) before the framework has determined the size and position of the render objects during layout.
The size getter was called for the following element: _ContentWidget
state: __ContentWidgetState#a7aaf
The render object from which the size was to be obtained was: RenderTransform#45058 NEEDS-LAYOUT NEEDS-PAINT
... parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=346.0, 0.0<=h<=Infinity)
... size: Size(346.0, 72.0)
... transform matrix: [0] 1.0,0.0,0.0,0.0
[1] 0.0,1.0,0.0,0.0
[2] 0.0,0.0,1.0,0.0
[3] 0.0,0.0,0.0,1.0
... origin: null
... alignment: null
... textDirection: ltr
... transformHitTests: false
Consider using debugPrintMarkNeedsLayoutStacks to determine why the render object in question is dirty, if you did not expect this.
When the exception was thrown, this was the stack:
#0 Element.size. (package:flutter/src/widgets/framework.dart:3875:9)
#1 Element.size (package:flutter/src/widgets/framework.dart:3893:6)
#2 __ContentWidgetState.didUpdateWidget. (package:flutter_swipe_action_cell/core/cell.dart:929:50)
#3 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
#4 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1063:9)
...
pubspec.yaml使用的版本
flutter_swipe_action_cell: ^1.2.3
我的源码片段
是在ListView的itemBuilder中使用的:
Widget renderItemType([BuildContext context,List list,int idx]){
return SwipeActionCell(
key: ObjectKey(list[idx]),
child: ListItem(key:ValueKey(list[idx].code),leftTime:list[idx].lastTime,bigTitle:list[idx].name,subTitle:list[idx].code),
trailingActions: [
SwipeAction(
title: '删除',
style:TS.textWhite14,
color: Colors.red,
icon: Icon(Icons.delete,color: Colors.white,),
onTap: (CompletionHandler handler) async {
await handler(true);
list.removeAt(idx);
setState(() {});
},
),
],
);
}
我的开发环境:
flutter doctor -v
[√] Flutter (Channel unknown, 1.22.3, on Microsoft Windows [Version 6.1.7601], locale zh-CN)
• Flutter version 1.22.3 at D:\android\flutter
• Framework revision 8874f21e79 (3 weeks ago), 2020-10-29 14:14:35 -0700
• Engine revision a1440ca392
• Dart version 2.10.3
• Pub download mirror https://pub.flutter-io.cn
• Flutter download mirror https://storage.flutter-io.cn
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at D:\android\Sdk
• Platform android-29, build-tools 29.0.3
• ANDROID_HOME = D:\android\Sdk
• Java binary at: D:\android\Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Android Studio (version 4.0)
• Android Studio at D:\android\Studio
• Flutter plugin installed
• Dart plugin version 193.7547
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
I would like to open the SwipeAction programmatically and without animation, any suggestion on it?
show log below:
: Error: Member not found: 'Scrollable.maybeOf'.
scrollPosition = Scrollable.maybeOf(context)?.position;
^^^^^^^
code:
lib/core/cell.dart
Line 434: scrollPosition = Scrollable.maybeOf(context)?.position;
以最简单的删除demo为例,当删除按钮滑动出来了,我又不想删除了,能否点击空白处让删除自己滑回去
I am have implemented the first example of this package successfully and it works perfectly. Now, I want to implement the second example - Perform first action when full swipe, but it does not work as described.
Well, the performsFirstActionWithFullSwipe
parameter is no longer available and I could not find anything that would help me to delete an item from the list when the user makes the full swipe.
Hello, thanks for your helpful work
is there a way to get the number of elements selected in edit mode?
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building Container(bg: BoxDecoration(color: Color(0xff050505)), margin: EdgeInsets(1.0, 0.0, 1.0, 0.0)):
The getter 'position' was called on null.
Receiver: null
Tried calling: position
The relevant error-causing widget was
Container
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 _SwipeActionCellState._addScrollListener
package:flutter_swipe_action_cell/core/swipe_action_cell.dart:207
#2 _SwipeActionCellState.didChangeDependencies
package:flutter_swipe_action_cell/core/swipe_action_cell.dart:191
#3 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4716
#4 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4531
...
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 5028 pos 14: '_dependents.isEmpty': is not true.
The relevant error-causing widget was
MediaQuery
lib/main.dart:98
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by scheduler library ═════════════════════════════════
Cannot get size from a render object that has not been through layout.
════════════════════════════════════════════════════════════════════════════════
如标题所示,你可以试试
Hey,
It's me again :)
I sometime encounter a weird behaviour with your package.
It is working as expected most of the times, but one time out of hundred when trying to open a cell it freezes my phone and I have to hard reset.
It is not happening anywhere in my app, except when trying to open a cell, that is why I think it is something to do with your package.
Is there anything that may cause a deadlock or a loop that never ends?
I don't have any logs to give because it is really random.
Please help,
Thank you!
Hey,
I have found 2 issues.
Thanks!
flutter_swipe_action_cell/lib/core/cell.dart
Line 651 in 8bcfedc
Hey really nice package!
I have a little problem,
I want to show actions with a condition.
My application can be RTL and LTR, I need to set the leading actions if the direction of the app is ltr and trailing actions need to be empty. If the direction of the app is rtl I need to set the trailing actions and the leading actions need to be empty.
However, errors show up if the list of the actions is empty.
I looked at the code, and saw you initialize the actions with defaultActions
list.
This is fine, but if I over swipe the item, there is a slight red background which is shown (an empty SwipeAction
I suppose).
Here is a gif to show the issue:
I think you should allow null or an empty actions list.
Or fix the red background of the empty SwipeAction
in the defaultActions
list.
Thanks!
Widget _item(BuildContext ctx, int index) {
return SwipeActionCell(
controller: controller,
index: index,
key: ValueKey(list[index]),
///animation default value below...
normalAnimationDuration: 500,
deleteAnimationDuration: 400,
performsFirstActionWithFullSwipe: true,
trailingActions: [
SwipeAction(
title: "取消删除",
// nestedAction: SwipeNestedAction(title: "confirm"),
onTap: (handler) async {
await handler(true);
list.removeAt(index);
setState(() {});
}),
// SwipeAction(title: "action2", color: Colors.grey, onTap: (handler) {}),
],
action数组为一个的时候 取消删除 显示不完整
我尝试过修改您的代码 但由于是初学者实现的并不完美
Hey!
Thank you for the package.
It seems there is a bug with the animations — when I touch the screen during the delete animation the cell loses its red color and some visual artifacts appear after it :-)
Please take a look.
Demo
Repro
import 'package:flutter/cupertino.dart';
import 'package:flutter_swipe_action_cell/flutter_swipe_action_cell.dart';
class X extends StatefulWidget {
@override
State<X> createState() => _XState();
}
class _XState extends State<X> {
var items = List<String>.empty();
@override
void initState() {
super.initState();
items = List.generate(10, (index) => 'Item $index');
}
@override
Widget build(BuildContext context) {
return CupertinoApp(
home: CupertinoPageScaffold(
child: SafeArea(
child: CustomScrollView(
slivers: [
SliverList(
delegate: SliverChildBuilderDelegate(
childCount: items.length,
(_, index) {
return SwipeActionCell(
deleteAnimationDuration: 10000,
key: ValueKey(items[index]),
trailingActions: <SwipeAction>[
SwipeAction(
title: "delete",
onTap: (CompletionHandler handler) async {
await handler(true);
items.removeAt(index);
setState(() {});
},
color: CupertinoColors.destructiveRed,
),
],
child: Container(
height: 30,
child: Text(items[index]),
color: CupertinoColors.white,
),
);
},
),
),
],
),
),
),
);
}
}
void main() {
runApp(X());
}
I use the latest 3.1.0 version
看了源码,只有一个开始滑动的回调 CellFingerOpenEvent
,还有编辑模式的回调,找不到侧滑展开的回调和侧滑收回的回调,有什么好的办法监听到这两个事件吗
// 监听侧滑 这个回调方法展开和收回都会执行,而且无法判断是展开还是收回
SwipeActionStore.getInstance().bus.on<CellFingerOpenEvent>().listen((CellFingerOpenEvent event) {
ValueKey<String> valueKey = event.key as ValueKey<String>;
print('--->>> open: ${valueKey.value} ${_swipeActionController.selectedSet.length}');
});
version: flutter_swipe_action_cell: ^2.1.1
flutter version: 2.5.2 channel stable
最后一条的数据已经没有了 但是还是会显示一条item 不仅是删除最后一条 把列表item全删了 只要导致列表item为0了 那些被删除的item的ui还在显示着 setState也没用
I want adjust size delete button.How do that?
Try calling using ?. instead.
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
^^^^^^^^^^^^^^^^^^^^
感谢插件作者,我想实现如视频里这样的回弹效果,是否可以自定义动画?
看了一下代码, 我觉得首先需要修改普通的动画的曲线为 easeOutBack
curvedAnim = CurvedAnimation(parent: controller, curve: Curves.easeOutBack);
其次,我认为需要再增加一个 animation 作为收回的动画(不需要 easeOutBack)
不知道这个思路是否正确?
谢谢
�JingRui 同学你好,在网上看到了你的一些 iOS 和 Flutter 开发作品非常喜欢,我目前在微信就职,希望可以与你取得联系做进一步的交流。
hello,先感谢老哥贡献组件。看到参数中有 backgroundRadius 参数,是实现左上和左下圆角的,貌似也是默认行为。
请问如何实现右上和右下圆角?
Hello, There is no controller available to open-cell at any index with swipeController however there is an option to close-all-cell, how can I close the cell without opening it !!!
There is no maybeOf method in Scrollable.
line 434 in cell.dart:
scrollPosition = Scrollable.maybeOf(context)?.position;
should be :
scrollPosition = Scrollable.of(context)?.position;
since flutter stable 2.0.0 is there with stable null safety, it would be nice to have this package migrated as well
I get this error sometimes when tapping on an action with nested action.
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: LateInitializationError: Field 'offsetFillActionContentCurve' has not been initialized.
I have to implement a some custom widget like AlertDialog to show user that is she/he sure to cancel the order or not.
But the problem is the width and height of the dialog is bounded with SwipeAction -> widthSpace, width and height is bounded by parent height. So can't showDialog and will cause overflow.
首先感谢lucksmg的出色作品.
其次想请教个问题:
由于侧滑是Ios风格的操作,安卓上对应的是长按. 如果想在长按动作上也调出flutter_swipe_action_cell的侧滑效果,
需要怎么做?
great package so far, thank you !!!
I had some use cases where it perfectly suited my needs, but now I have one use case (and I think there will be some more) where I would like to have a horizontal scrollable widget (in my case it is just a ListView with scrollDirection: Axis.horizontal) and the swipe actions simultaneously.
When arriving to the end (or beginning) of my scrollable widget I would like to show your swipe actions.
Is this (or will this ever) be possible with your package?
When i scroll ListView.builder than each new appears item triggers rebuild all of SvipeActionCell widgets.(9-15 pcs per time). is this behavior right and expected?
When i remove SwipeActionCell widget, yhen builder builds only new IgnorePointer. What is my bad?
I tried to pass index as ValueKey, it doesn't help.
Hey,
I have encountered a bug.
When the child of the SwipeActionCell
is changing its height, the swipe actions height is not updated to match the child.
Here is a video:
import 'package:flutter/material.dart';
import 'package:flutter_swipe_action_cell/flutter_swipe_action_cell.dart';
class Bug extends StatefulWidget {
const Bug({super.key});
@override
State<Bug> createState() => _BugState();
}
class _BugState extends State<Bug> {
bool isAdded = false;
@override
Widget build(BuildContext context) {
return Column(
children: [
SwipeActionCell(
key: const Key('bug'),
leadingActions: [
SwipeAction(
onTap: (_) {},
icon: const Icon(Icons.bug_report),
),
],
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(10),
color: Colors.blue,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('bug'),
if (isAdded) const Text('added'),
],
),
),
),
ElevatedButton(
onPressed: () {
setState(() {
isAdded = !isAdded;
});
},
child: const Text('Toggle'),
),
],
);
}
}
Thanks in advanced :)
Hello,
How to check if a cell is swipe and changed in real time.
THank you
you can try lastest version of this package.
Just write in your issue directly.😀(Not write in this issue)
When the exception was thrown, this was the stack:
#0 List.first (dart:core-patch/growable_array.dart:332:5)
#1 SwipeActionCellState._closeNestedAction (package:flutter_swipe_action_cell/core/cell.dart:661:33)
#2 SwipeActionCellState._scrollListener (package:flutter_swipe_action_cell/core/cell.dart:415:7)
#3 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:308:24)
#4 ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:412:5)
#5 ScrollPosition.beginActivity (package:flutter/src/widgets/scroll_position.dart:884:25)
#6 ScrollPositionWithSingleContext.beginActivity (package:flutter/src/widgets/scroll_position_with_single_context.dart:114:11)
#7 ScrollPositionWithSingleContext.drag (package:flutter/src/widgets/scroll_position_with_single_context.dart:264:5)
canEdit ? [
SwipeAction(
title: '编辑',
onTap: (CompletionHandler handler) async {
editAction?.call();
},
color: Colors.amber),
] : []
滚动的时候报错
希望 编辑模式下可以和iOS原生一样支持拖拽排序
你好 只要编辑功能,怎么禁掉左滑,和basepage的tabpage左滑冲突了
RT
你好,这个库的侧滑效果很不错,👍。
遇到了一个问题,如下:
刚开始时leadingActions为空的,然后有一个开关触发,设置了leadingActions,结果无法滑出来;
如果刚开始leadingActions不为空,接着设置为空,然后再设置leadingActions,就可以滑出来。
下面的代码,是在example项目基础上增加了一个isHaveLeading,通过这个参数,来控制leadingActions的显示。
bool isHaveLeading = false;
Widget _item(BuildContext ctx, int index) {
List<SwipeAction>? leadingActions;
if (isHaveLeading) {
leadingActions = [
SwipeAction(
title: "delete",
onTap: (handler) async {
await handler(true);
list.removeAt(index);
setState(() {});
}),
SwipeAction(
title: "action3", color: Colors.orange, onTap: (handler) {}),
];
}
return SwipeActionCell(
controller: controller,
index: index,
// Required!
key: ValueKey(list[index]),
// Animation default value below
// normalAnimationDuration: 400,
// deleteAnimationDuration: 400,
selectedForegroundColor: Colors.black.withAlpha(30),
trailingActions: [
SwipeAction(
title: "delete",
performsFirstActionWithFullSwipe: true,
nestedAction: SwipeNestedAction(title: "confirm"),
onTap: (handler) async {
await handler(true);
list.removeAt(index);
setState(() {});
}),
SwipeAction(title: "action2", color: Colors.grey, onTap: (handler) {}),
],
leadingActions: leadingActions,
child: GestureDetector(
onTap: () {
Navigator.push(
context, CupertinoPageRoute(builder: (ctx) => const HomePage()));
},
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Text("This is index of ${list[index]}",
style: const TextStyle(fontSize: 30)),
),
),
);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.