drag_info.dart
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import 'package:flutter/widgets.dart';
import '../config/manager.dart';
import '../page_view/page_info.dart';
class DragInfo {
DragInfo._(this.pageInfo);
factory DragInfo.from(
{required Offset begin,
required Offset end,
required Element pageElement,
required PageInfo pageInfo,
required int duration}) {
DragInfo dragInfo = DragInfo._(pageInfo);
dragInfo._beginOffset = begin;
dragInfo._endOffset = end;
dragInfo._duration = duration;
dragInfo._ignore = pageInfo.ignore;
double dx = dragInfo.endOffset.dx - dragInfo.beginOffset.dx;
double dy = dragInfo.endOffset.dy - dragInfo.beginOffset.dy;
var direction = 'down';
if (dx.abs() > dy.abs()) {
if (dx > 0) {
direction = 'right';
} else {
direction = 'left';
}
} else if (dy.abs() > dx.abs()) {
if (dy > 0) {
direction = 'down';
} else {
direction = 'up';
}
} else {
direction = 'none';
}
dragInfo._direction = direction;
return dragInfo;
}
Offset _beginOffset = Offset.zero;
Offset get beginOffset => _beginOffset;
Offset _endOffset = Offset.zero;
Offset get endOffset => _endOffset;
bool _ignore = false;
bool get ignore => _ignore;
String _direction = 'none';
String get direction => _direction;
int _duration = 0;
int get duration => _duration;
final PageInfo pageInfo;
@override
String toString() {
return [
'beginOffset: $beginOffset',
'endOffset: $endOffset',
'pageInfo: $pageInfo',
].join(', ');
}
}