-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.dart
484 lines (450 loc) · 16.9 KB
/
main.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter_sparkline/flutter_sparkline.dart';
import 'dart:async';
import 'package:health/health.dart';
import 'package:flare_splash_screen/flare_splash_screen.dart';
import 'package:horizontal_calendar_widget/date_helper.dart';
import 'package:horizontal_calendar_widget/horizontal_calendar.dart';
import 'package:introduction_screen/introduction_screen.dart';
///completed all , need to add intro screens
void main() => runApp(Splash());
class Splash extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Heart Beat',
home: SplashScreen(
'assets/Hearth.flr',
OnBoardingPage(),
startAnimation: 'favorite',
backgroundColor: Color(0xff181818),
),
);
}
}
class OnBoardingPage extends StatefulWidget {
@override
_OnBoardingPageState createState() => _OnBoardingPageState();
}
class _OnBoardingPageState extends State<OnBoardingPage> {
final introKey = GlobalKey<IntroductionScreenState>();
void _onIntroEnd(context) {
Navigator.of(context).push(
MaterialPageRoute(builder: (_) => MyApp()),
);
}
Widget _buildImage(String assetName) {
return Align(
child: Image.asset('assets/$assetName', width: 350.0),
alignment: Alignment.bottomCenter,
);
}
@override
Widget build(BuildContext context) {
const bodyStyle = TextStyle(fontSize: 19.0);
const pageDecoration = const PageDecoration(
titleTextStyle: TextStyle(fontSize: 28.0, fontWeight: FontWeight.w700),
bodyTextStyle: bodyStyle,
descriptionPadding: EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 16.0),
pageColor: Colors.white,
imagePadding: EdgeInsets.zero,
);
return IntroductionScreen(
key: introKey,
pages: [
PageViewModel(
title: "Pick a Date",
body:
"Choose a date on which you want your heart beats on.",
image: _buildImage('img3.gif'),
decoration: pageDecoration,
),
PageViewModel(
title: "Connect your smart bands",
body:
" Connect your smart bands with google fit for android or apple fit for ios.",
image: _buildImage('img1.png'),
decoration: pageDecoration,
),
PageViewModel(
title: "Track your heartbeats",
body: "Monitor every minute of your Heart Beats",
image: _buildImage('img2.jpg'),
decoration: pageDecoration,
),
],
onDone: () => _onIntroEnd(context),
//onSkip: () => _onIntroEnd(context), // You can override onSkip callback
showSkipButton: true,
skipFlex: 0,
nextFlex: 0,
skip: const Text('Skip'),
next: const Icon(Icons.arrow_forward),
done: const Text('Done', style: TextStyle(fontWeight: FontWeight.w600)),
dotsDecorator: const DotsDecorator(
size: Size(10.0, 10.0),
color: Color(0xFFBDBDBD),
activeSize: Size(22.0, 10.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25.0)),
),
),
);
}
}
class MyApp extends StatefulWidget{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return MyAppState();
}
}
// constants for horizontal Calendar
const labelMonth = 'Month';
const labelDate = 'Date';
const labelWeekDay = 'Week Day';
class MyAppState extends State<MyApp>{
DateTime firstDate = toDateMonthYear(DateTime.now().subtract(Duration(days: 30)));//starting date for HC
DateTime lastDate = toDateMonthYear(DateTime.now().add(Duration(days: 1)));//ending date for HC
//HC formats
String dateFormat = 'dd';
String monthFormat = 'MMM';
String weekDayFormat = 'EEE';
List<String> order = [labelMonth, labelDate, labelWeekDay];
bool forceRender = false;
GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();
double hr;
var hb = 0 ;
var _maxHeartRate=0, _minHeartRate = 0, _avgHeartRate=0;
var hrlists;
List hrlist = new List();
List<double> _heartBeatList = [72.0];
var count = 0;
var total = 0;
var _healthDataList = List<HealthDataPoint>();
bool _isAuthorized = false;
bool _showAnalysis = false;
Color defaultDecorationColor = Colors.transparent;
BoxShape defaultDecorationShape = BoxShape.rectangle;
bool isCircularRadiusDefault = true;
Color selectedDecorationColor = Colors.red;
BoxShape selectedDecorationShape = BoxShape.rectangle;
bool isCircularRadiusSelected = true;
Color disabledDecorationColor = Colors.grey;
BoxShape disabledDecorationShape = BoxShape.rectangle;
bool isCircularRadiusDisabled = true;
int maxSelectedDateCount = 1;
@override
void initState() {
super.initState();
}
///Method for labelling months,dates and weekdays in HC
LabelType toLabelType(String label) {
LabelType type;
switch (label) {
case labelMonth:
type = LabelType.month;
break;
case labelDate:
type = LabelType.date;
break;
case labelWeekDay:
type = LabelType.weekday;
break;
}
return type;
}
Future<void> onDateForHeart(date) async{
_maxHeartRate=0;
_minHeartRate = 240;
_avgHeartRate=0;
print("Start Date: $date");
DateTime selectedDate = date;
total=0;
count=0;
DateTime endDate = date.add(Duration(hours: 23));
print("End Date: $endDate");
_healthDataList.clear();
hrlist.clear();
_heartBeatList.clear();
Future.delayed(Duration(seconds: 0), () async {
_isAuthorized = await Health.requestAuthorization();
if (_isAuthorized) {
print('Authorized');
/// Calls to 'Health.getHealthDataFromType'
/// must be wrapped in a try catch block.b
try {
List<HealthDataPoint> healthData;
healthData =
await Health.getHealthDataFromType(selectedDate, endDate,HealthDataType.HEART_RATE);
_healthDataList.addAll(healthData);
} catch (exception) {
print(exception.toString());
}
for (var x in _healthDataList) {
hrlist.add(x.value.toDouble());
_heartBeatList.add(x.value.toDouble());
count=count+1;
total = total + x.value.toInt();
hb = x.value.toInt();
if(_minHeartRate >= hb){
_minHeartRate = hb;
}
if(_maxHeartRate <= hb){
_maxHeartRate = hb;
}
}
print("Min Heart Rate: $_minHeartRate");
print("Max Heart Rate: $_maxHeartRate");
print("$total / $count");
print("Heart Rates: $hrlist");
hrlists = new List<double>.from(hrlist);
hr = (total/count);
_avgHeartRate = hr.toInt();
print("Average Heart Rate : $hr");
/// Print the results
for (var x in _healthDataList) {
print("Data point: $x");
}
/// Update the UI to display the results
setState(() {});
} else {
print('Not authorized');
}
});
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
backgroundColor: Colors.black,
title: const Text('Heart Rate'),
),
body: SafeArea(
child: ListView(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(horizontal: 5.0, vertical: 15.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: Colors.white,
boxShadow: [BoxShadow(
color: Color(0x802196F3),
offset: Offset(0.0,1.0),
blurRadius: 6.0,
)]
),
child: HorizontalCalendar(
key: forceRender ? UniqueKey() : Key('Calendar'),
height: 92,
padding: EdgeInsets.all(22),
firstDate: firstDate,
lastDate: lastDate,
dateFormat: dateFormat,
weekDayFormat: weekDayFormat,
monthFormat: monthFormat,
defaultDecoration: BoxDecoration(
color: defaultDecorationColor,
shape: defaultDecorationShape,
borderRadius: defaultDecorationShape == BoxShape.rectangle &&
isCircularRadiusDefault
? BorderRadius.circular(8)
: null,
),
selectedDecoration: BoxDecoration(
color: selectedDecorationColor,
shape: selectedDecorationShape,
borderRadius: selectedDecorationShape == BoxShape.rectangle &&
isCircularRadiusSelected
? BorderRadius.circular(8)
: null,
),
disabledDecoration: BoxDecoration(
color: disabledDecorationColor,
shape: disabledDecorationShape,
borderRadius: disabledDecorationShape == BoxShape.rectangle &&
isCircularRadiusDisabled
? BorderRadius.circular(8)
: null,
),
labelOrder: order.map(toLabelType).toList(),
maxSelectedDateCount: maxSelectedDateCount,
//date selection
onDateSelected: (date) async {
onDateForHeart(date);
},
),
),
_healthDataList.isEmpty
? Text('\n')
: Container(
margin: EdgeInsets.symmetric(horizontal: 5.0, vertical: 5.0),
padding: EdgeInsets.symmetric(vertical: 15.0, horizontal: 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: Colors.white,
boxShadow: [BoxShadow(
color: Color(0x802196F3),
offset: Offset(0.0,1.0),
blurRadius: 6.0,
)]
),
height: 300,
child: ListView.builder(
itemCount: _healthDataList.length,
itemBuilder: (_, index) => Container(
margin: EdgeInsets.symmetric(vertical: 2.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: Colors.black,
boxShadow: [BoxShadow(
color: Color(0x802196F3),
offset: Offset(0.0,1.0),
blurRadius: 6.0,
)]
),
child: ListTile(
title: Text(
"${_healthDataList[index].dataType.toString()}: ${_healthDataList[index].value.toString()}",
style: TextStyle(color: Colors.white),),
trailing: Icon(Icons.favorite,color: Colors.red,),
subtitle: Text(
'${DateTime.fromMillisecondsSinceEpoch(_healthDataList[index].dateFrom)} - ${DateTime.fromMillisecondsSinceEpoch(_healthDataList[index].dateTo)}',
style: TextStyle(color: Colors.white),),
),
)
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Container(
height: 220,
width: 50,
margin: EdgeInsets.symmetric(horizontal: 5.0, vertical: 5.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: Colors.white,
boxShadow: [BoxShadow(
color: Color(0x802196F3),
offset: Offset(0.0,1.0),
blurRadius: 6.0,
)]
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: new Sparkline(
data: _heartBeatList,
lineColor: Color(0xffff6101),
pointsMode: PointsMode.all,
pointSize: 0.0,
),
)
),
),
_showAnalysis? Text('\n')
: Container(
height: 70.0,
margin: EdgeInsets.symmetric(horizontal: 5.0, vertical: 15.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24.0),
color: Colors.white,
boxShadow: [BoxShadow(
color: Color(0x802196F3),
offset: Offset(0.0,1.0),
blurRadius: 6.0,
)]
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text("$_maxHeartRate",
style: TextStyle(fontSize: 24,
color: Colors.red,
fontWeight: FontWeight.bold
),
)
),
Text("Max Heart Rate"),
],
),
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text("$_avgHeartRate",
style: TextStyle(
fontSize: 24,
color: Colors.blueAccent,
fontWeight: FontWeight.bold
),
)
),
Text("Average Heart Rate"),
],
),
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Center(
child: Text("$_minHeartRate",
style: TextStyle(
fontSize: 24,
color: Colors.greenAccent,
fontWeight: FontWeight.bold
),
)
),
Text("Min Heart Rate"),
],
),
),
],
),
),
Center(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 1.0),
child: RaisedButton(
onPressed: (){
// _showAnalysis = true;
print("ANALYZE BUTTON CLICKED");
},
// onPressed: ()=> _showAnalysis = true,
disabledColor: Colors.black,
disabledTextColor: Colors.white,
color: Colors.black,
textColor: Colors.white,
child: Text("Analyze"),
elevation: 5.0,
disabledElevation: 5.0,
hoverColor: Color(0x802196F3),
),
),
),
],
),
),
),
);
}
}