forked from inex/swipe_to_action
null-safety migration
This commit is contained in:
parent
349ec81edb
commit
6d9396bf55
|
@ -6,7 +6,7 @@ buildscript {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
||||||
|
|
|
@ -7,42 +7,42 @@ packages:
|
||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.5.0-nullsafety.1"
|
version: "2.5.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: boolean_selector
|
name: boolean_selector
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.1"
|
version: "2.1.0"
|
||||||
characters:
|
characters:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: characters
|
name: characters
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0-nullsafety.3"
|
version: "1.1.0"
|
||||||
charcode:
|
charcode:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: charcode
|
name: charcode
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0-nullsafety.1"
|
version: "1.2.0"
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: clock
|
name: clock
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0-nullsafety.1"
|
version: "1.1.0"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: collection
|
name: collection
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.15.0-nullsafety.3"
|
version: "1.15.0"
|
||||||
cupertino_icons:
|
cupertino_icons:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -56,7 +56,7 @@ packages:
|
||||||
name: fake_async
|
name: fake_async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0-nullsafety.1"
|
version: "1.2.0"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -72,27 +72,34 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
js:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: js
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.3"
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: matcher
|
name: matcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.10-nullsafety.1"
|
version: "0.12.10"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: meta
|
name: meta
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0-nullsafety.3"
|
version: "1.3.0"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0-nullsafety.1"
|
version: "1.8.0"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -104,28 +111,28 @@ packages:
|
||||||
name: source_span
|
name: source_span
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0-nullsafety.2"
|
version: "1.8.0"
|
||||||
stack_trace:
|
stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stack_trace
|
name: stack_trace
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.10.0-nullsafety.1"
|
version: "1.10.0"
|
||||||
stream_channel:
|
stream_channel:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stream_channel
|
name: stream_channel
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.1"
|
version: "2.1.0"
|
||||||
string_scanner:
|
string_scanner:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: string_scanner
|
name: string_scanner
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0-nullsafety.1"
|
version: "1.1.0"
|
||||||
swipe_to_action:
|
swipe_to_action:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -139,28 +146,28 @@ packages:
|
||||||
name: term_glyph
|
name: term_glyph
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0-nullsafety.1"
|
version: "1.2.0"
|
||||||
test_api:
|
test_api:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.19-nullsafety.2"
|
version: "0.2.19"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: typed_data
|
name: typed_data
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0-nullsafety.3"
|
version: "1.3.0"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vector_math
|
name: vector_math
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.3"
|
version: "2.1.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.10.0-110 <=2.11.0-161.0.dev"
|
dart: ">=2.12.0 <3.0.0"
|
||||||
flutter: ">=1.20.0 <2.0.0"
|
flutter: ">=2.0.0"
|
||||||
|
|
|
@ -6,7 +6,7 @@ description: Demonstrates how to use the swipe_to_action plugin.
|
||||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.7.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|
|
@ -5,23 +5,4 @@
|
||||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
// gestures. You can also use WidgetTester to find child widgets in the widget
|
||||||
// tree, read text, and verify that the values of widget properties are correct.
|
// tree, read text, and verify that the values of widget properties are correct.
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
void main() {}
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
import 'package:swipe_to_action_example/main.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
testWidgets('Verify Platform version', (WidgetTester tester) async {
|
|
||||||
// Build our app and trigger a frame.
|
|
||||||
await tester.pumpWidget(MyApp());
|
|
||||||
|
|
||||||
// Verify that platform version is retrieved.
|
|
||||||
expect(
|
|
||||||
find.byWidgetPredicate(
|
|
||||||
(Widget widget) => widget is Text &&
|
|
||||||
widget.data.startsWith('Running on:'),
|
|
||||||
),
|
|
||||||
findsOneWidget,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
@ -31,6 +31,9 @@ enum SwipeDirection {
|
||||||
/// The [Swipeable] can be swiped by dragging in the reading direction
|
/// The [Swipeable] can be swiped by dragging in the reading direction
|
||||||
/// (e.g., from left to right in left-to-right languages).
|
/// (e.g., from left to right in left-to-right languages).
|
||||||
startToEnd,
|
startToEnd,
|
||||||
|
|
||||||
|
/// Called instead of null.
|
||||||
|
none,
|
||||||
}
|
}
|
||||||
|
|
||||||
class Swipeable extends StatefulWidget {
|
class Swipeable extends StatefulWidget {
|
||||||
|
@ -43,12 +46,12 @@ class Swipeable extends StatefulWidget {
|
||||||
/// state of the dismissed item. Using keys causes the widgets to sync
|
/// state of the dismissed item. Using keys causes the widgets to sync
|
||||||
/// according to their keys and avoids this pitfall.
|
/// according to their keys and avoids this pitfall.
|
||||||
const Swipeable({
|
const Swipeable({
|
||||||
@required Key key,
|
required Key key,
|
||||||
@required this.child,
|
required this.child,
|
||||||
|
required this.onSwipe,
|
||||||
this.background,
|
this.background,
|
||||||
this.secondaryBackground,
|
this.secondaryBackground,
|
||||||
this.confirmSwipe,
|
this.confirmSwipe,
|
||||||
this.onSwipe,
|
|
||||||
this.direction = SwipeDirection.horizontal,
|
this.direction = SwipeDirection.horizontal,
|
||||||
this.dismissThresholds = const <SwipeDirection, double>{},
|
this.dismissThresholds = const <SwipeDirection, double>{},
|
||||||
this.maxOffset = 0.4,
|
this.maxOffset = 0.4,
|
||||||
|
@ -60,9 +63,7 @@ class Swipeable extends StatefulWidget {
|
||||||
PointerDeviceKind.stylus,
|
PointerDeviceKind.stylus,
|
||||||
PointerDeviceKind.touch
|
PointerDeviceKind.touch
|
||||||
},
|
},
|
||||||
}) : assert(key != null),
|
}) : assert(secondaryBackground == null || background != null),
|
||||||
assert(secondaryBackground == null || background != null),
|
|
||||||
assert(dragStartBehavior != null),
|
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
/// The widget below this widget in the tree.
|
/// The widget below this widget in the tree.
|
||||||
|
@ -73,12 +74,12 @@ class Swipeable extends StatefulWidget {
|
||||||
/// A widget that is stacked behind the child. If secondaryBackground is also
|
/// A widget that is stacked behind the child. If secondaryBackground is also
|
||||||
/// specified then this widget only appears when the child has been dragged
|
/// specified then this widget only appears when the child has been dragged
|
||||||
/// to the right.
|
/// to the right.
|
||||||
final Widget background;
|
final Widget? background;
|
||||||
|
|
||||||
/// A widget that is stacked behind the child and is exposed when the child
|
/// A widget that is stacked behind the child and is exposed when the child
|
||||||
/// has been dragged to the left. It may only be specified when background
|
/// has been dragged to the left. It may only be specified when background
|
||||||
/// has also been specified.
|
/// has also been specified.
|
||||||
final Widget secondaryBackground;
|
final Widget? secondaryBackground;
|
||||||
|
|
||||||
/// Gives the app an opportunity to confirm or veto a pending dismissal.
|
/// Gives the app an opportunity to confirm or veto a pending dismissal.
|
||||||
///
|
///
|
||||||
|
@ -87,7 +88,7 @@ class Swipeable extends StatefulWidget {
|
||||||
///
|
///
|
||||||
/// If the returned Future<bool> completes to false or null the [onSwipe]
|
/// If the returned Future<bool> completes to false or null the [onSwipe]
|
||||||
/// callback will not run.
|
/// callback will not run.
|
||||||
final ConfirmSwipeCallback confirmSwipe;
|
final ConfirmSwipeCallback? confirmSwipe;
|
||||||
|
|
||||||
/// Called when the widget has been dismissed, after finishing resizing.
|
/// Called when the widget has been dismissed, after finishing resizing.
|
||||||
final SwipeDirectionCallback onSwipe;
|
final SwipeDirectionCallback onSwipe;
|
||||||
|
@ -159,9 +160,8 @@ class Swipeable extends StatefulWidget {
|
||||||
|
|
||||||
class _SwipeableClipper extends CustomClipper<Rect> {
|
class _SwipeableClipper extends CustomClipper<Rect> {
|
||||||
_SwipeableClipper({
|
_SwipeableClipper({
|
||||||
@required this.moveAnimation,
|
required this.moveAnimation,
|
||||||
}) : assert(moveAnimation != null),
|
}) : super(reclip: moveAnimation);
|
||||||
super(reclip: moveAnimation);
|
|
||||||
|
|
||||||
final Animation<Offset> moveAnimation;
|
final Animation<Offset> moveAnimation;
|
||||||
|
|
||||||
|
@ -185,28 +185,27 @@ class _SwipeableClipper extends CustomClipper<Rect> {
|
||||||
|
|
||||||
enum _FlingGestureKind { none, forward, reverse }
|
enum _FlingGestureKind { none, forward, reverse }
|
||||||
|
|
||||||
class _SwipeableState extends State<Swipeable>
|
class _SwipeableState extends State<Swipeable> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||||
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
_moveController = AnimationController(duration: widget.movementDuration, vsync: this)
|
||||||
_moveController =
|
|
||||||
AnimationController(duration: widget.movementDuration, vsync: this)
|
|
||||||
..addStatusListener(_handleDismissStatusChanged);
|
..addStatusListener(_handleDismissStatusChanged);
|
||||||
_updateMoveAnimation();
|
_updateMoveAnimation();
|
||||||
|
|
||||||
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationController _moveController;
|
late AnimationController _moveController;
|
||||||
Animation<Offset> _moveAnimation;
|
late Animation<Offset> _moveAnimation;
|
||||||
|
|
||||||
double _dragExtent = 0.0;
|
double _dragExtent = 0.0;
|
||||||
bool _dragUnderway = false;
|
bool _dragUnderway = false;
|
||||||
Size _sizePriorToCollapse;
|
Size? _sizePriorToCollapse;
|
||||||
|
|
||||||
bool _isTouch = true;
|
bool _isTouch = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => _moveController?.isAnimating == true;
|
bool get wantKeepAlive => _moveController.isAnimating == true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
@ -216,20 +215,14 @@ class _SwipeableState extends State<Swipeable>
|
||||||
|
|
||||||
SwipeDirection _extentToDirection(double extent) {
|
SwipeDirection _extentToDirection(double extent) {
|
||||||
if (extent == 0.0) {
|
if (extent == 0.0) {
|
||||||
return null;
|
return SwipeDirection.none;
|
||||||
}
|
}
|
||||||
switch (Directionality.of(context)) {
|
switch (Directionality.of(context)) {
|
||||||
case TextDirection.rtl:
|
case TextDirection.rtl:
|
||||||
return extent < 0
|
return extent < 0 ? SwipeDirection.startToEnd : SwipeDirection.endToStart;
|
||||||
? SwipeDirection.startToEnd
|
|
||||||
: SwipeDirection.endToStart;
|
|
||||||
case TextDirection.ltr:
|
case TextDirection.ltr:
|
||||||
return extent > 0
|
return extent > 0 ? SwipeDirection.startToEnd : SwipeDirection.endToStart;
|
||||||
? SwipeDirection.startToEnd
|
|
||||||
: SwipeDirection.endToStart;
|
|
||||||
}
|
}
|
||||||
assert(false);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SwipeDirection get _swipeDirection => _extentToDirection(_dragExtent);
|
SwipeDirection get _swipeDirection => _extentToDirection(_dragExtent);
|
||||||
|
@ -240,7 +233,7 @@ class _SwipeableState extends State<Swipeable>
|
||||||
|
|
||||||
double get _overallDragAxisExtent {
|
double get _overallDragAxisExtent {
|
||||||
final size = context.size;
|
final size = context.size;
|
||||||
return size.width;
|
return size?.width ?? 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handlePointerDown(PointerDownEvent event) {
|
void _handlePointerDown(PointerDownEvent event) {
|
||||||
|
@ -252,8 +245,7 @@ class _SwipeableState extends State<Swipeable>
|
||||||
void _handleDragStart(DragStartDetails details) {
|
void _handleDragStart(DragStartDetails details) {
|
||||||
_dragUnderway = true;
|
_dragUnderway = true;
|
||||||
if (_moveController.isAnimating) {
|
if (_moveController.isAnimating) {
|
||||||
_dragExtent =
|
_dragExtent = _moveController.value * _overallDragAxisExtent * _dragExtent.sign;
|
||||||
_moveController.value * _overallDragAxisExtent * _dragExtent.sign;
|
|
||||||
_moveController.stop();
|
_moveController.stop();
|
||||||
} else {
|
} else {
|
||||||
_dragExtent = 0.0;
|
_dragExtent = 0.0;
|
||||||
|
@ -269,9 +261,12 @@ class _SwipeableState extends State<Swipeable>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final delta = details.primaryDelta;
|
final delta = details.primaryDelta ?? 0.0;
|
||||||
final oldDragExtent = _dragExtent;
|
final oldDragExtent = _dragExtent;
|
||||||
switch (widget.direction) {
|
switch (widget.direction) {
|
||||||
|
case SwipeDirection.none:
|
||||||
|
return;
|
||||||
|
|
||||||
case SwipeDirection.horizontal:
|
case SwipeDirection.horizontal:
|
||||||
_dragExtent += delta;
|
_dragExtent += delta;
|
||||||
break;
|
break;
|
||||||
|
@ -327,7 +322,6 @@ class _SwipeableState extends State<Swipeable>
|
||||||
}
|
}
|
||||||
|
|
||||||
_FlingGestureKind _describeFlingGesture(Velocity velocity) {
|
_FlingGestureKind _describeFlingGesture(Velocity velocity) {
|
||||||
assert(widget.direction != null);
|
|
||||||
if (_dragExtent == 0.0) {
|
if (_dragExtent == 0.0) {
|
||||||
// If it was a fling, then it was a fling that was let loose at the exact
|
// If it was a fling, then it was a fling that was let loose at the exact
|
||||||
// middle of the range (i.e. when there's no displacement). In that case,
|
// middle of the range (i.e. when there's no displacement). In that case,
|
||||||
|
@ -340,14 +334,12 @@ class _SwipeableState extends State<Swipeable>
|
||||||
final vy = velocity.pixelsPerSecond.dy;
|
final vy = velocity.pixelsPerSecond.dy;
|
||||||
SwipeDirection flingDirection;
|
SwipeDirection flingDirection;
|
||||||
// Verify that the fling is in the generally right direction and fast enough.
|
// Verify that the fling is in the generally right direction and fast enough.
|
||||||
if (vx.abs() - vy.abs() < _kMinFlingVelocityDelta ||
|
if (vx.abs() - vy.abs() < _kMinFlingVelocityDelta || vx.abs() < _kMinFlingVelocity) {
|
||||||
vx.abs() < _kMinFlingVelocity) {
|
|
||||||
return _FlingGestureKind.none;
|
return _FlingGestureKind.none;
|
||||||
}
|
}
|
||||||
assert(vx != 0.0);
|
assert(vx != 0.0);
|
||||||
flingDirection = _extentToDirection(vx);
|
flingDirection = _extentToDirection(vx);
|
||||||
|
|
||||||
assert(_swipeDirection != null);
|
|
||||||
if (flingDirection == _swipeDirection) {
|
if (flingDirection == _swipeDirection) {
|
||||||
return _FlingGestureKind.forward;
|
return _FlingGestureKind.forward;
|
||||||
}
|
}
|
||||||
|
@ -359,8 +351,7 @@ class _SwipeableState extends State<Swipeable>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_dragUnderway = false;
|
_dragUnderway = false;
|
||||||
if (_moveController.isCompleted &&
|
if (_moveController.isCompleted && await _confirmStartSwipeAnimation() == true) {
|
||||||
await _confirmStartSwipeAnimation() == true) {
|
|
||||||
_startSwipeAnimation();
|
_startSwipeAnimation();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -369,28 +360,23 @@ class _SwipeableState extends State<Swipeable>
|
||||||
case _FlingGestureKind.forward:
|
case _FlingGestureKind.forward:
|
||||||
assert(_dragExtent != 0.0);
|
assert(_dragExtent != 0.0);
|
||||||
assert(!_moveController.isDismissed);
|
assert(!_moveController.isDismissed);
|
||||||
if ((widget.dismissThresholds[_swipeDirection] ?? _kDismissThreshold) >=
|
if ((widget.dismissThresholds[_swipeDirection] ?? _kDismissThreshold) >= 1.0) {
|
||||||
1.0) {
|
|
||||||
await _moveController.reverse();
|
await _moveController.reverse();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_dragExtent = flingVelocity.sign;
|
_dragExtent = flingVelocity.sign;
|
||||||
await _moveController.fling(
|
await _moveController.fling(velocity: flingVelocity.abs() * _kFlingVelocityScale);
|
||||||
velocity: flingVelocity.abs() * _kFlingVelocityScale);
|
|
||||||
break;
|
break;
|
||||||
case _FlingGestureKind.reverse:
|
case _FlingGestureKind.reverse:
|
||||||
assert(_dragExtent != 0.0);
|
assert(_dragExtent != 0.0);
|
||||||
assert(!_moveController.isDismissed);
|
assert(!_moveController.isDismissed);
|
||||||
_dragExtent = flingVelocity.sign;
|
_dragExtent = flingVelocity.sign;
|
||||||
await _moveController.fling(
|
await _moveController.fling(velocity: -flingVelocity.abs() * _kFlingVelocityScale);
|
||||||
velocity: -flingVelocity.abs() * _kFlingVelocityScale);
|
|
||||||
break;
|
break;
|
||||||
case _FlingGestureKind.none:
|
case _FlingGestureKind.none:
|
||||||
if (!_moveController.isDismissed) {
|
if (!_moveController.isDismissed) {
|
||||||
// we already know it's not completed, we check that above
|
// we already know it's not completed, we check that above
|
||||||
if (_moveController.value >
|
if (_moveController.value > (widget.dismissThresholds[_swipeDirection] ?? _kDismissThreshold)) {
|
||||||
(widget.dismissThresholds[_swipeDirection] ??
|
|
||||||
_kDismissThreshold)) {
|
|
||||||
await _moveController.forward();
|
await _moveController.forward();
|
||||||
} else {
|
} else {
|
||||||
await _moveController.reverse();
|
await _moveController.reverse();
|
||||||
|
@ -414,21 +400,18 @@ class _SwipeableState extends State<Swipeable>
|
||||||
Future<bool> _confirmStartSwipeAnimation() async {
|
Future<bool> _confirmStartSwipeAnimation() async {
|
||||||
if (widget.confirmSwipe != null) {
|
if (widget.confirmSwipe != null) {
|
||||||
final direction = _swipeDirection;
|
final direction = _swipeDirection;
|
||||||
assert(direction != null);
|
return widget.confirmSwipe!(direction);
|
||||||
return widget.confirmSwipe(direction);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _startSwipeAnimation() {
|
void _startSwipeAnimation() {
|
||||||
assert(_moveController != null);
|
|
||||||
assert(_moveController.isCompleted);
|
assert(_moveController.isCompleted);
|
||||||
assert(_sizePriorToCollapse == null);
|
assert(_sizePriorToCollapse == null);
|
||||||
if (widget.onSwipe != null) {
|
|
||||||
final direction = _swipeDirection;
|
final direction = _swipeDirection;
|
||||||
assert(direction != null);
|
|
||||||
widget.onSwipe(direction);
|
widget.onSwipe(direction);
|
||||||
}
|
|
||||||
_moveController.reverse();
|
_moveController.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
47
pubspec.lock
47
pubspec.lock
|
@ -7,49 +7,49 @@ packages:
|
||||||
name: async
|
name: async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.5.0-nullsafety.1"
|
version: "2.5.0"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: boolean_selector
|
name: boolean_selector
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.1"
|
version: "2.1.0"
|
||||||
characters:
|
characters:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: characters
|
name: characters
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0-nullsafety.3"
|
version: "1.1.0"
|
||||||
charcode:
|
charcode:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: charcode
|
name: charcode
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0-nullsafety.1"
|
version: "1.2.0"
|
||||||
clock:
|
clock:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: clock
|
name: clock
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0-nullsafety.1"
|
version: "1.1.0"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: collection
|
name: collection
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.15.0-nullsafety.3"
|
version: "1.15.0"
|
||||||
fake_async:
|
fake_async:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: fake_async
|
name: fake_async
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0-nullsafety.1"
|
version: "1.2.0"
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -65,27 +65,34 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
js:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: js
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.6.3"
|
||||||
matcher:
|
matcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: matcher
|
name: matcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.10-nullsafety.1"
|
version: "0.12.10"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: meta
|
name: meta
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0-nullsafety.3"
|
version: "1.3.0"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0-nullsafety.1"
|
version: "1.8.0"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
@ -97,56 +104,56 @@ packages:
|
||||||
name: source_span
|
name: source_span
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.0-nullsafety.2"
|
version: "1.8.0"
|
||||||
stack_trace:
|
stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stack_trace
|
name: stack_trace
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.10.0-nullsafety.1"
|
version: "1.10.0"
|
||||||
stream_channel:
|
stream_channel:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stream_channel
|
name: stream_channel
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.1"
|
version: "2.1.0"
|
||||||
string_scanner:
|
string_scanner:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: string_scanner
|
name: string_scanner
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0-nullsafety.1"
|
version: "1.1.0"
|
||||||
term_glyph:
|
term_glyph:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: term_glyph
|
name: term_glyph
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0-nullsafety.1"
|
version: "1.2.0"
|
||||||
test_api:
|
test_api:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.19-nullsafety.2"
|
version: "0.2.19"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: typed_data
|
name: typed_data
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0-nullsafety.3"
|
version: "1.3.0"
|
||||||
vector_math:
|
vector_math:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vector_math
|
name: vector_math
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.0-nullsafety.3"
|
version: "2.1.0"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.10.0-110 <=2.11.0-161.0.dev"
|
dart: ">=2.12.0 <3.0.0"
|
||||||
flutter: ">=1.20.0 <2.0.0"
|
flutter: ">=2.0.0"
|
||||||
|
|
|
@ -4,8 +4,8 @@ version: 0.1.0
|
||||||
homepage: https://inex.dev/inex/swipe_to_action
|
homepage: https://inex.dev/inex/swipe_to_action
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.7.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
flutter: ">=1.20.0 <2.0.0"
|
flutter: ">=2.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
|
|
Loading…
Reference in a new issue