102 lines
2.9 KiB
Dart
Executable File
102 lines
2.9 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/tools/left_slide/left_slide_logic.dart';
|
|
|
|
typedef BaseFunction<T> = void Function(T o);
|
|
|
|
/// 来源: https://blog.csdn.net/zhuowalun8427/article/details/121285947 。
|
|
class LeftSlideActions extends StatefulWidget {
|
|
const LeftSlideActions({
|
|
required this.tag,
|
|
required this.actionsWidth,
|
|
required this.actions,
|
|
required this.child,
|
|
Key? key,
|
|
this.decoration,
|
|
this.actionsWillShow,
|
|
this.exportHideActions,
|
|
}) : super(key: key);
|
|
final String tag;
|
|
final double actionsWidth;
|
|
final List<Widget> actions;
|
|
final Widget child;
|
|
final Decoration? decoration;
|
|
final VoidCallback? actionsWillShow;
|
|
final BaseFunction<VoidCallback>? exportHideActions;
|
|
|
|
@override
|
|
_LeftSlideActionsState createState() => _LeftSlideActionsState();
|
|
}
|
|
|
|
class _LeftSlideActionsState extends State<LeftSlideActions>
|
|
with TickerProviderStateMixin {
|
|
late AnimationController _controller;
|
|
late LeftSlideLogic logic;
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
lowerBound: -widget.actionsWidth,
|
|
upperBound: 0,
|
|
vsync: this,
|
|
duration: const Duration(milliseconds: 300),
|
|
)..addListener(() {
|
|
logic.translateX = _controller.value;
|
|
setState(() {});
|
|
});
|
|
if (widget.exportHideActions != null) {
|
|
widget.exportHideActions!(logic.hide);
|
|
}
|
|
logic = LeftSlideLogic(
|
|
controller: _controller,
|
|
actionsWidth: widget.actionsWidth,
|
|
actions: widget.actions,
|
|
decoration: widget.decoration,
|
|
actionsWillShow: widget.actionsWillShow,
|
|
exportHideActions: widget.exportHideActions,
|
|
);
|
|
Get.put(logic, tag: widget.tag);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetBuilder<LeftSlideLogic>(
|
|
tag: widget.tag,
|
|
builder: (LeftSlideLogic logic) {
|
|
return Container(
|
|
decoration: widget.decoration,
|
|
clipBehavior: Clip.hardEdge,
|
|
child: Stack(
|
|
children: <Widget>[
|
|
Positioned.fill(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: widget.actions,
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onHorizontalDragUpdate: logic.onHorizontalDragUpdate,
|
|
onHorizontalDragEnd: logic.onHorizontalDragEnd,
|
|
child: Transform.translate(
|
|
offset: Offset(logic.translateX, 0),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Expanded(flex: 1, child: widget.child),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
});
|
|
}
|
|
}
|