63 lines
1.4 KiB
Dart
63 lines
1.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/tools/left_slide/left_slide_actions.dart';
|
|
|
|
class LeftSlideLogic extends GetxController {
|
|
LeftSlideLogic({
|
|
required this.controller,
|
|
required this.actionsWidth,
|
|
required this.actions,
|
|
required this.decoration,
|
|
required this.actionsWillShow,
|
|
required this.exportHideActions,
|
|
});
|
|
|
|
late AnimationController controller;
|
|
final double actionsWidth;
|
|
final List<Widget> actions;
|
|
final Decoration? decoration;
|
|
final VoidCallback? actionsWillShow;
|
|
final BaseFunction<VoidCallback>? exportHideActions;
|
|
double translateX = 0;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
}
|
|
|
|
void onHorizontalDragUpdate(DragUpdateDetails details) {
|
|
translateX = (translateX + details.delta.dx).clamp(-actionsWidth, 0.0);
|
|
update();
|
|
}
|
|
|
|
void onHorizontalDragEnd(DragEndDetails details) {
|
|
controller.value = translateX;
|
|
if (details.velocity.pixelsPerSecond.dx > 200) {
|
|
hide();
|
|
} else if (details.velocity.pixelsPerSecond.dx < -200) {
|
|
show();
|
|
} else {
|
|
if (translateX.abs() > actionsWidth / 2) {
|
|
show();
|
|
} else {
|
|
hide();
|
|
}
|
|
}
|
|
}
|
|
|
|
void show() {
|
|
if (actionsWillShow != null) {
|
|
actionsWillShow!();
|
|
}
|
|
if (translateX != -actionsWidth) {
|
|
controller.animateTo(-actionsWidth);
|
|
}
|
|
}
|
|
|
|
void hide() {
|
|
if (translateX != 0) {
|
|
controller.animateTo(0);
|
|
}
|
|
}
|
|
}
|