Unverified Commit 830bdfa3 authored by Chinmoy's avatar Chinmoy Committed by GitHub

added none property in a DismissDirection (#68987)

parent b8887f47
......@@ -237,6 +237,7 @@ class _LeaveBehindListItem extends StatelessWidget {
case DismissDirection.vertical:
case DismissDirection.up:
case DismissDirection.down:
case DismissDirection.none:
assert(false);
}
return false;
......
......@@ -50,7 +50,10 @@ enum DismissDirection {
up,
/// The [Dismissible] can be dismissed by dragging down only.
down
down,
/// The [Dismissible] cannot be dismissed by dragging.
none
}
/// A widget that can be dismissed by dragging in the indicated [direction].
......@@ -305,9 +308,9 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
|| widget.direction == DismissDirection.startToEnd;
}
DismissDirection? _extentToDirection(double extent) {
DismissDirection _extentToDirection(double extent) {
if (extent == 0.0)
return null;
return DismissDirection.none;
if (_directionIsXAxis) {
switch (Directionality.of(context)) {
case TextDirection.rtl:
......@@ -319,7 +322,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
return extent > 0 ? DismissDirection.down : DismissDirection.up;
}
DismissDirection? get _dismissDirection => _extentToDirection(_dragExtent);
DismissDirection get _dismissDirection => _extentToDirection(_dragExtent);
bool get _isActive {
return _dragUnderway || _moveController!.isAnimating;
......@@ -391,6 +394,10 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
break;
}
break;
case DismissDirection.none:
_dragExtent = 0;
break;
}
if (oldDragExtent.sign != _dragExtent.sign) {
setState(() {
......@@ -426,7 +433,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
}
final double vx = velocity.pixelsPerSecond.dx;
final double vy = velocity.pixelsPerSecond.dy;
DismissDirection? flingDirection;
DismissDirection flingDirection;
// Verify that the fling is in the generally right direction and fast enough.
if (_directionIsXAxis) {
if (vx.abs() - vy.abs() < _kMinFlingVelocityDelta || vx.abs() < _kMinFlingVelocity)
......@@ -495,8 +502,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
Future<bool?> _confirmStartResizeAnimation() async {
if (widget.confirmDismiss != null) {
final DismissDirection direction = _dismissDirection!;
assert(direction != null);
final DismissDirection direction = _dismissDirection;
return widget.confirmDismiss!(direction);
}
return true;
......@@ -509,8 +515,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
assert(_sizePriorToCollapse == null);
if (widget.resizeDuration == null) {
if (widget.onDismissed != null) {
final DismissDirection direction = _dismissDirection!;
assert(direction != null);
final DismissDirection direction = _dismissDirection;
widget.onDismissed!(direction);
}
} else {
......@@ -537,8 +542,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
void _handleResizeProgressChanged() {
if (_resizeController!.isCompleted) {
if (widget.onDismissed != null) {
final DismissDirection direction = _dismissDirection!;
assert(direction != null);
final DismissDirection direction = _dismissDirection;
widget.onDismissed!(direction);
}
} else {
......@@ -555,7 +559,7 @@ class _DismissibleState extends State<Dismissible> with TickerProviderStateMixin
Widget? background = widget.background;
if (widget.secondaryBackground != null) {
final DismissDirection? direction = _dismissDirection;
final DismissDirection direction = _dismissDirection;
if (direction == DismissDirection.endToStart || direction == DismissDirection.up)
background = widget.secondaryBackground;
}
......
......@@ -861,4 +861,17 @@ void main() {
await tester.tapAt(const Offset(10.0, 10.0));
expect(didReceivePointerDown, isTrue);
});
testWidgets('DismissDirection.none does not trigger dismiss', (WidgetTester tester) async {
dismissDirection = DismissDirection.none;
await tester.pumpWidget(buildTest());
expect(dismissedItems, isEmpty);
await dismissItem(tester, 0, gestureDirection: AxisDirection.left);
await dismissItem(tester, 0, gestureDirection: AxisDirection.right);
await dismissItem(tester, 0, gestureDirection: AxisDirection.up);
await dismissItem(tester, 0, gestureDirection: AxisDirection.down);
expect(find.text('0'), findsOneWidget);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment