2021-04-06 12:00:00 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:simple_gesture_detector/simple_gesture_detector.dart';
|
|
|
|
|
|
|
|
import '../../core/enums/swipe_event.dart';
|
|
|
|
import '../../core/services/swipe_service.dart';
|
|
|
|
import '../../locator.dart';
|
|
|
|
|
|
|
|
class SwipeNavigation extends StatefulWidget {
|
|
|
|
/// Widget to be augmented with gesture detection.
|
2021-11-29 23:44:22 +00:00
|
|
|
final Widget? child;
|
2021-04-06 12:00:00 +00:00
|
|
|
|
|
|
|
/// Creates a [SwipeNavigation] widget.
|
|
|
|
const SwipeNavigation({
|
2021-11-29 23:44:22 +00:00
|
|
|
Key? key,
|
2021-04-06 12:00:00 +00:00
|
|
|
this.child,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_SwipeNavigationState createState() => _SwipeNavigationState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SwipeNavigationState extends State<SwipeNavigation> {
|
|
|
|
final SwipeService _swipeService = locator<SwipeService>();
|
|
|
|
|
|
|
|
void _onHorizontalSwipe(SwipeDirection direction) {
|
|
|
|
if (direction == SwipeDirection.left) {
|
|
|
|
_swipeService.addEvent(SwipeEvent.Left);
|
|
|
|
} else {
|
|
|
|
_swipeService.addEvent(SwipeEvent.Right);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-06-22 22:44:08 +00:00
|
|
|
return SimpleGestureDetector(onHorizontalSwipe: _onHorizontalSwipe, child: widget.child!);
|
2021-04-06 12:00:00 +00:00
|
|
|
}
|
|
|
|
}
|