Files
GitJournal/lib/widgets/swipe_detector.dart
Vishesh Handa b588cdc66b NoteBrowser: Allow browsing via swipes
This is the first prototype for swiping. It really needs a lot of work,
and it needs some kind of animation.
2018-05-25 00:46:17 +02:00

34 lines
760 B
Dart

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
class SwipeDetector extends StatelessWidget {
final VoidCallback onLeftSwipe;
final VoidCallback onRightSwipe;
final Widget child;
SwipeDetector({
@required this.onLeftSwipe,
@required this.onRightSwipe,
@required this.child,
});
@override
Widget build(BuildContext context) {
double primaryDelta;
return new GestureDetector(
child: child,
onHorizontalDragUpdate: (DragUpdateDetails details) {
primaryDelta = details.primaryDelta;
},
onHorizontalDragEnd: (DragEndDetails _) {
if (primaryDelta > 0) {
onRightSwipe();
} else {
onLeftSwipe();
}
},
);
}
}