mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-20 06:39:22 +08:00

This is the first prototype for swiping. It really needs a lot of work, and it needs some kind of animation.
34 lines
760 B
Dart
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();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|