-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathdrag_behavior.dart
164 lines (155 loc) · 5.01 KB
/
drag_behavior.dart
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/// Flutter package imports
import 'package:flutter/material.dart';
/// Gauge imports
import 'package:syncfusion_flutter_gauges/gauges.dart';
/// Local imports
import '../../../model/sample_view.dart';
import '../utils.dart';
/// Shows the linear gauge multiple pointer drag behavior.
class DragBehavior extends SampleView {
/// Creates linear gauge with different pointer drag behavior.
const DragBehavior(Key key) : super(key: key);
@override
_DragBehaviorState createState() => _DragBehaviorState();
}
/// State class of linear gauge widget pointer.
class _DragBehaviorState extends SampleViewState {
_DragBehaviorState();
double _firstLoosePointerValue = 40;
double _middleLoosePointerValue = 60;
double _firstLockPointerValue = 40;
double _middleLockPointerValue = 60;
final bool _isHorizontalOrientation = true;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Expanded(
child: Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
width: getScreenWidth(context, _isHorizontalOrientation),
child: _buildWidgetPointer(context),
),
],
),
),
),
),
],
);
}
/// Returns the linear gauge widget pointer.
Widget _buildWidgetPointer(BuildContext context) {
return Container(
padding: const EdgeInsets.fromLTRB(24.0, 0.0, 24.0, 32.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildHorizontalGauges(
'Free',
_buildIconWidgetPointer(context, LinearMarkerDragBehavior.free),
),
_buildHorizontalGauges(
'Constrained',
_buildIconWidgetPointer(
context,
LinearMarkerDragBehavior.constrained,
),
),
],
),
);
}
/// Returns the horizontal axis track.
Widget _buildHorizontalGauges(String axisTrackName, Widget linearGauge) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(axisTrackName),
linearGauge,
const SizedBox(height: 10),
],
);
}
/// Returns the icon widget pointer sample.
Widget _buildIconWidgetPointer(
BuildContext context,
LinearMarkerDragBehavior dragMode,
) {
return SizedBox(
height: 100,
child: SfLinearGauge(
animateAxis: true,
interval: 10,
axisTrackStyle: const LinearAxisTrackStyle(thickness: 3),
markerPointers: <LinearMarkerPointer>[
LinearWidgetPointer(
value:
dragMode == LinearMarkerDragBehavior.free
? _firstLoosePointerValue
: _firstLockPointerValue,
onChanged: (dynamic value) {
setState(() {
if (dragMode == LinearMarkerDragBehavior.free) {
_firstLoosePointerValue = value as double;
} else {
_firstLockPointerValue = value as double;
}
});
},
dragBehavior:
dragMode == LinearMarkerDragBehavior.free
? LinearMarkerDragBehavior.free
: LinearMarkerDragBehavior.constrained,
position: LinearElementPosition.outside,
child: RotatedBox(
quarterTurns: 3,
child: SizedBox(
width: 20,
height: 16,
child: Image.asset('images/rectangle_pointer.png'),
),
),
),
LinearWidgetPointer(
value:
dragMode == LinearMarkerDragBehavior.free
? _middleLoosePointerValue
: _middleLockPointerValue,
onChanged: (dynamic value) {
setState(() {
if (dragMode == LinearMarkerDragBehavior.free) {
_middleLoosePointerValue = value as double;
} else {
_middleLockPointerValue = value as double;
}
});
},
dragBehavior:
dragMode == LinearMarkerDragBehavior.free
? LinearMarkerDragBehavior.free
: LinearMarkerDragBehavior.constrained,
position: LinearElementPosition.outside,
child: RotatedBox(
quarterTurns: 3,
child: SizedBox(
width: 20,
height: 16,
child: Image.asset(
'images/rectangle_pointer.png',
color: Theme.of(context).colorScheme.onSurface,
),
),
),
),
],
),
);
}
}