-
Notifications
You must be signed in to change notification settings - Fork 779
/
Copy pathheight_calculator.dart
171 lines (163 loc) · 6.12 KB
/
height_calculator.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
165
166
167
168
169
170
171
// 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';
/// Renders the linear gauge height calculator sample.
class HeightCalculator extends SampleView {
/// Creates the linear gauge height calculator sample.
const HeightCalculator(Key key) : super(key: key);
@override
_HeightCalculatorState createState() => _HeightCalculatorState();
}
class _HeightCalculatorState extends SampleViewState {
_HeightCalculatorState();
double _pointerValue = 130;
double minimumLevel = 0;
double maximumLevel = 200;
@override
Widget build(BuildContext context) {
return isWebOrDesktop
? Container(
alignment: Alignment.center,
child: Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width >= 1000 ? 550 : 440,
height: 500,
child: _buildHeightCalculator(context),
),
)
: _buildHeightCalculator(context);
}
/// Returns the height calculator.
Widget _buildHeightCalculator(BuildContext context) {
final Brightness brightness = Theme.of(context).brightness;
return Padding(
padding: const EdgeInsets.all(10),
child: Center(
child: Container(
height:
isCardView
? MediaQuery.of(context).size.height
: MediaQuery.of(context).size.height * 3 / 4,
padding: const EdgeInsets.all(5.0),
child: SfLinearGauge(
orientation: LinearGaugeOrientation.vertical,
maximum: maximumLevel,
tickPosition: LinearElementPosition.outside,
labelPosition: LinearLabelPosition.outside,
minorTicksPerInterval: 0,
interval: isCardView ? 50 : 25,
onGenerateLabels: () {
return isCardView
? <LinearAxisLabel>[
const LinearAxisLabel(text: '0 cm', value: 0),
const LinearAxisLabel(text: '50 cm', value: 50),
const LinearAxisLabel(text: '100 cm', value: 100),
const LinearAxisLabel(text: '150 cm', value: 150),
const LinearAxisLabel(text: '200 cm', value: 200),
]
: <LinearAxisLabel>[
const LinearAxisLabel(text: '0 cm', value: 0),
const LinearAxisLabel(text: '25 cm', value: 25),
const LinearAxisLabel(text: '50 cm', value: 50),
const LinearAxisLabel(text: '75 cm', value: 75),
const LinearAxisLabel(text: '100 cm', value: 100),
const LinearAxisLabel(text: '125 cm', value: 125),
const LinearAxisLabel(text: '150 cm', value: 150),
const LinearAxisLabel(text: '175 cm', value: 175),
const LinearAxisLabel(text: '200 cm', value: 200),
];
},
axisTrackStyle: const LinearAxisTrackStyle(),
markerPointers: <LinearMarkerPointer>[
LinearShapePointer(
value: _pointerValue,
enableAnimation: false,
onChanged: (dynamic value) {
setState(() {
_pointerValue = value as double;
});
},
shapeType: LinearShapePointerType.rectangle,
color: const Color(0xff0074E3),
height: 1.5,
width: isCardView ? 150 : 250,
),
LinearWidgetPointer(
value: _pointerValue,
enableAnimation: false,
onChanged: (dynamic value) {
setState(() {
_pointerValue = value as double;
});
},
child: SizedBox(
width: 24,
height: 16,
child: Image.asset('images/rectangle_pointer.png'),
),
),
LinearWidgetPointer(
value: _pointerValue,
enableAnimation: false,
onChanged: (dynamic value) {
setState(() {
_pointerValue = value as double;
});
},
offset: isCardView ? 150 : 230,
position: LinearElementPosition.outside,
child: Container(
width: 60,
height: 25,
decoration: BoxDecoration(
color: model.homeCardColor,
boxShadow: <BoxShadow>[
BoxShadow(
color:
brightness == Brightness.light
? Colors.grey
: Colors.black54,
offset: const Offset(0.0, 1.0), //(x,y)
blurRadius: 6.0,
),
],
borderRadius: BorderRadius.circular(4),
),
child: Center(
child: Text(
_pointerValue.toStringAsFixed(0) + ' cm',
style: const TextStyle(
fontWeight: FontWeight.normal,
fontSize: 14,
color: Color(0xff0074E3),
),
),
),
),
),
],
ranges: <LinearGaugeRange>[
LinearGaugeRange(
endValue: _pointerValue,
startWidth: 200,
midWidth: isCardView ? 200 : 300,
endWidth: 200,
color: Colors.transparent,
child: Image.asset(
brightness == Brightness.light
? 'images/bmi_light.png'
: 'images/bmi_dark.png',
fit: BoxFit.fitHeight,
),
),
],
),
),
),
);
}
}