Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-256
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-256
2022-256
Commits
72e11618
Commit
72e11618
authored
Sep 28, 2022
by
Nilupul Jayasekara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement time frame to record screen
parent
e98ff601
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
276 additions
and
192 deletions
+276
-192
diabeta_app/lib/screens/dashboard_screen.dart
diabeta_app/lib/screens/dashboard_screen.dart
+12
-1
diabeta_app/lib/screens/diabetes/screens/logbook_screen.dart
diabeta_app/lib/screens/diabetes/screens/logbook_screen.dart
+2
-2
diabeta_app/lib/screens/reports/report_screen.dart
diabeta_app/lib/screens/reports/report_screen.dart
+257
-184
diabeta_app/lib/services/glucose_log_service.dart
diabeta_app/lib/services/glucose_log_service.dart
+5
-5
No files found.
diabeta_app/lib/screens/dashboard_screen.dart
View file @
72e11618
...
...
@@ -127,7 +127,7 @@ class _DashboardScreenState extends State<DashboardScreen> {
builder:
(
context
,
AsyncSnapshot
snapshot
)
{
if
(
snapshot
.
hasData
)
{
int
length
=
snapshot
.
data
!.
length
;
return
ListView
(
return
length
>
0
?
ListView
(
shrinkWrap:
true
,
physics:
const
NeverScrollableScrollPhysics
(),
children:
List
.
generate
(
...
...
@@ -152,6 +152,17 @@ class _DashboardScreenState extends State<DashboardScreen> {
);
},
),
):
Padding
(
padding:
const
EdgeInsets
.
only
(
top:
50.0
),
child:
Column
(
children:
[
Container
(
child:
Center
(
child:
Text
(
" No records, yet."
)),),
SizedBox
(
height:
8
,
),
Container
(
child:
Center
(
child:
Text
(
" Add your first record."
)),),
],
),
);
}
else
{
return
const
Center
(
...
...
diabeta_app/lib/screens/diabetes/screens/logbook_screen.dart
View file @
72e11618
...
...
@@ -23,7 +23,7 @@ class _LogbookScreenState extends State<LogbookScreen> {
builder:
(
context
,
AsyncSnapshot
snapshot
)
{
if
(
snapshot
.
hasData
)
{
int
length
=
snapshot
.
data
!.
length
;
return
ListView
(
return
length
>
0
?
ListView
(
shrinkWrap:
true
,
children:
List
.
generate
(
length
,
(
index
)
{
return
Center
(
...
...
@@ -44,7 +44,7 @@ class _LogbookScreenState extends State<LogbookScreen> {
),
);
}),
);
)
:
Container
(
child:
Center
(
child:
Text
(
"No data to display."
),),)
;
}
else
{
return
const
Center
(
child:
CircularProgressIndicator
(),
...
...
diabeta_app/lib/screens/reports/report_screen.dart
View file @
72e11618
...
...
@@ -33,17 +33,26 @@ class _ReportScreenState extends State<ReportScreen> {
List
<
SplineAreaWeightData
>
_chartGlucoseData
=
<
SplineAreaWeightData
>[];
List
<
SplineAreaWeightData
>
_chartCarbData
=
<
SplineAreaWeightData
>[];
final
_currentUser
=
FirebaseAuth
.
instance
.
currentUser
;
int
_gselectedIndex
=
0
;
int
_cselectedIndex
=
0
;
int
_gselectedIndex
=
0
;
int
_cselectedIndex
=
0
;
void
getChartGlucoseData
()
async
{
void
getChartGlucoseData
ByTimeFrame
()
async
{
List
<
SplineAreaWeightData
>
_data
=
<
SplineAreaWeightData
>[];
List
data
=
await
GlucoseLogService
.
getAllRecords
(
_currentUser
!.
uid
,
false
);
String
period
=
"This week"
;
if
(
_gselectedIndex
==
1
)
{
period
=
"This month"
;
}
else
if
(
_gselectedIndex
==
2
)
{
period
=
"This year"
;
}
List
data
=
await
GlucoseLogService
.
getRecordsByTimeFrame
(
_currentUser
!.
uid
,
period
,
isDecending:
false
);
data
.
forEach
((
element
)
{
if
(
element
.
glucoseLevel
!=
null
)
{
if
(
element
.
glucoseLevel
!=
null
)
{
_data
.
add
(
SplineAreaWeightData
(
DateFormat
(
'MMM d'
).
format
(
element
.
dateTime
).
toString
(),
element
.
glucoseLevel
));
DateFormat
(
'MMM d'
).
format
(
element
.
dateTime
).
toString
(),
element
.
glucoseLevel
));
}
});
setState
(()
{
...
...
@@ -51,15 +60,21 @@ class _ReportScreenState extends State<ReportScreen> {
});
}
void
getChartCarbsData
()
async
{
void
getChartCarbsData
ByTimeFrame
()
async
{
List
<
SplineAreaWeightData
>
_data
=
<
SplineAreaWeightData
>[];
List
data
=
await
GlucoseLogService
.
getAllRecords
(
_currentUser
!.
uid
,
false
)
;
String
period
=
"This week"
;
if
(
_cselectedIndex
==
1
)
{
period
=
"This month"
;
}
else
if
(
_cselectedIndex
==
2
)
{
period
=
"This year"
;
}
List
data
=
await
GlucoseLogService
.
getRecordsByTimeFrame
(
_currentUser
!.
uid
,
period
,
isDecending:
false
);
data
.
forEach
((
element
)
{
if
(
element
.
carbs
!=
null
)
{
if
(
element
.
carbs
!=
null
)
{
_data
.
add
(
SplineAreaWeightData
(
DateFormat
(
'MMM d'
).
format
(
element
.
dateTime
).
toString
(),
element
.
carbs
));
DateFormat
(
'MMM d'
).
format
(
element
.
dateTime
).
toString
(),
element
.
carbs
));
}
});
...
...
@@ -67,12 +82,13 @@ class _ReportScreenState extends State<ReportScreen> {
_chartCarbData
=
_data
;
});
}
@override
void
initState
()
{
getChartGlucoseData
();
getChartCarbsData
();
getChartGlucoseData
ByTimeFrame
();
getChartCarbsData
ByTimeFrame
();
}
@override
Widget
build
(
BuildContext
context
)
{
var
width
=
MediaQuery
.
of
(
context
).
size
.
width
;
...
...
@@ -88,125 +104,172 @@ class _ReportScreenState extends State<ReportScreen> {
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
8
),
child:
Row
(
children:
[
InkWell
(
onTap:
(()
{
setState
(()
{
_gselectedIndex
=
0
;
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)/
3
,
decoration:
BoxDecoration
(
color:
_gselectedIndex
!=
0
?
kPrimaryColor
:
Colors
.
teal
[
300
]
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"WEEK"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),),
children:
[
InkWell
(
onTap:
(()
{
setState
(()
{
_gselectedIndex
=
0
;
getChartGlucoseDataByTimeFrame
();
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)
/
3
,
decoration:
BoxDecoration
(
color:
_gselectedIndex
!=
0
?
kPrimaryColor
:
Colors
.
teal
[
300
]),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"WEEK"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),
),
),
),
),
),
InkWell
(
onTap:
(()
{
setState
(()
{
_gselectedIndex
=
1
;
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)/
3
,
decoration:
BoxDecoration
(
color:
_gselectedIndex
!=
1
?
kPrimaryColor
:
Colors
.
teal
[
300
]
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"MONTH"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),),
InkWell
(
onTap:
(()
{
setState
(()
{
_gselectedIndex
=
1
;
getChartGlucoseDataByTimeFrame
();
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)
/
3
,
decoration:
BoxDecoration
(
color:
_gselectedIndex
!=
1
?
kPrimaryColor
:
Colors
.
teal
[
300
]),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"MONTH"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),
),
),
),
),
),
InkWell
(
onTap:
(()
{
setState
(()
{
_gselectedIndex
=
2
;
print
(
_gselectedIndex
);
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)/
3
,
decoration:
BoxDecoration
(
color:
_gselectedIndex
!=
2
?
kPrimaryColor
:
Colors
.
teal
[
300
]
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"YEAR"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),),
InkWell
(
onTap:
(()
{
setState
(()
{
_gselectedIndex
=
2
;
getChartGlucoseDataByTimeFrame
();
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)
/
3
,
decoration:
BoxDecoration
(
color:
_gselectedIndex
!=
2
?
kPrimaryColor
:
Colors
.
teal
[
300
]),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"YEAR"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),
),
),
),
),
)
],
),
)
],
),
),
ChartCard
(
width
,
"Glucose"
,
"mg/dL"
,
_chartGlucoseData
),
ChartCard
(
width
,
"Glucose"
,
"mg/dL"
,
_chartGlucoseData
),
SizedBox
(
height:
30
,
),
Padding
(
Padding
(
padding:
const
EdgeInsets
.
symmetric
(
horizontal:
8
),
child:
Row
(
children:
[
InkWell
(
onTap:
(()
{
setState
(()
{
_cselectedIndex
=
0
;
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)/
3
,
decoration:
BoxDecoration
(
color:
_cselectedIndex
!=
0
?
kPrimaryColor
:
Colors
.
teal
[
300
]
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"WEEK"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),),
children:
[
InkWell
(
onTap:
(()
{
setState
(()
{
_cselectedIndex
=
0
;
getChartCarbsDataByTimeFrame
();
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)
/
3
,
decoration:
BoxDecoration
(
color:
_cselectedIndex
!=
0
?
kPrimaryColor
:
Colors
.
teal
[
300
]),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"WEEK"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),
),
),
),
),
),
InkWell
(
onTap:
(()
{
setState
(()
{
_cselectedIndex
=
1
;
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)/
3
,
decoration:
BoxDecoration
(
color:
_cselectedIndex
!=
1
?
kPrimaryColor
:
Colors
.
teal
[
300
]
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"MONTH"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),),
InkWell
(
onTap:
(()
{
setState
(()
{
_cselectedIndex
=
1
;
getChartCarbsDataByTimeFrame
();
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)
/
3
,
decoration:
BoxDecoration
(
color:
_cselectedIndex
!=
1
?
kPrimaryColor
:
Colors
.
teal
[
300
]),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"MONTH"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),
),
),
),
),
),
InkWell
(
onTap:
(()
{
setState
(()
{
_cselectedIndex
=
2
;
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)/
3
,
decoration:
BoxDecoration
(
color:
_cselectedIndex
!=
2
?
kPrimaryColor
:
Colors
.
teal
[
300
]
),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"YEAR"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),),
InkWell
(
onTap:
(()
{
setState
(()
{
_cselectedIndex
=
2
;
getChartCarbsDataByTimeFrame
();
});
}),
child:
Container
(
width:
(
MediaQuery
.
of
(
context
).
size
.
width
-
16
)
/
3
,
decoration:
BoxDecoration
(
color:
_cselectedIndex
!=
2
?
kPrimaryColor
:
Colors
.
teal
[
300
]),
child:
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
Text
(
"YEAR"
,
textAlign:
TextAlign
.
center
,
style:
TextStyle
(
color:
Colors
.
white
,
fontWeight:
FontWeight
.
bold
),
),
),
),
),
)
],
),
)
],
),
),
ChartCard
(
width
,
"Carbohydrates"
,
"grams"
,
_chartCarbData
),
ChartCard
(
width
,
"Carbohydrates"
,
"grams"
,
_chartCarbData
),
//ChartCard(width, "","mg/dL", _chartCarbData),
],
),
...
...
@@ -215,7 +278,8 @@ class _ReportScreenState extends State<ReportScreen> {
);
}
Container
ChartCard
(
double
width
,
String
title
,
String
unit
,
List
<
SplineAreaWeightData
>
chartData
)
{
Container
ChartCard
(
double
width
,
String
title
,
String
unit
,
List
<
SplineAreaWeightData
>
chartData
)
{
return
Container
(
height:
380
,
width:
width
-
20
,
...
...
@@ -263,74 +327,83 @@ class _ReportScreenState extends State<ReportScreen> {
),
Container
(
height:
320
,
child:
chartData
.
isEmpty
?
const
Center
(
child:
Text
(
"No data to display."
,
style:
TextStyle
(
color:
Colors
.
white
),)):
SfCartesianChart
(
zoomPanBehavior:
ZoomPanBehavior
(
enablePinching:
true
,
enableDoubleTapZooming:
true
,
enablePanning:
true
,
),
enableAxisAnimation:
true
,
legend:
Legend
(
isVisible:
false
,
opacity:
0.7
),
// title: ChartTitle(text: 'Inflation rate'),
child:
chartData
.
isEmpty
?
const
Center
(
child:
Text
(
"No data to display."
,
style:
TextStyle
(
color:
Colors
.
white
),
))
:
SfCartesianChart
(
zoomPanBehavior:
ZoomPanBehavior
(
enablePinching:
true
,
enableDoubleTapZooming:
true
,
enablePanning:
true
,
),
enableAxisAnimation:
true
,
legend:
Legend
(
isVisible:
false
,
opacity:
0.7
),
// title: ChartTitle(text: 'Inflation rate'),
plotAreaBorderWidth:
0
,
primaryXAxis:
CategoryAxis
(
axisLine:
AxisLine
(
color:
Colors
.
white
,
width:
2
,
),
labelStyle:
TextStyle
(
color:
Colors
.
white
),
isVisible:
true
,
// maximumLabels: 5,
// interval: 1,
majorGridLines:
const
MajorGridLines
(
width:
0
),
edgeLabelPlacement:
EdgeLabelPlacement
.
shift
),
primaryYAxis:
NumericAxis
(
axisLine:
AxisLine
(
color:
Colors
.
white
,
width:
2
,
),
labelStyle:
TextStyle
(
color:
Colors
.
white
),
isVisible:
true
,
labelFormat:
'{value}'
,
// axisLine: const AxisLine(width: 0),
majorTickLines:
const
MajorTickLines
(
size:
0
)),
series:
<
ChartSeries
>[
SplineAreaSeries
<
SplineAreaWeightData
,
String
>(
// animationDuration: 100,
markerSettings:
MarkerSettings
(
isVisible:
true
,
borderColor:
Colors
.
white
,
height:
4
,
width:
4
),
// gradient: LinearGradient(
// colors: <Color>[
// Colors.white.withAlpha(100),
// Colors.white.withAlpha(10),
// ],
// begin: Alignment.topCenter,
// end: Alignment.bottomCenter,
// ),
onRendererCreated:
(
ChartSeriesController
controller
)
{
_chartSeriesController
=
controller
;
plotAreaBorderWidth:
0
,
primaryXAxis:
CategoryAxis
(
axisLine:
AxisLine
(
color:
Colors
.
white
,
width:
2
,
),
labelStyle:
TextStyle
(
color:
Colors
.
white
),
isVisible:
true
,
// maximumLabels: 5,
// interval: 1,
majorGridLines:
const
MajorGridLines
(
width:
0
),
edgeLabelPlacement:
EdgeLabelPlacement
.
shift
),
primaryYAxis:
NumericAxis
(
axisLine:
AxisLine
(
color:
Colors
.
white
,
width:
2
,
),
labelStyle:
TextStyle
(
color:
Colors
.
white
),
isVisible:
true
,
labelFormat:
'{value}'
,
// axisLine: const AxisLine(width: 0),
majorTickLines:
const
MajorTickLines
(
size:
0
)),
series:
<
ChartSeries
>[
SplineAreaSeries
<
SplineAreaWeightData
,
String
>(
// animationDuration: 100,
markerSettings:
MarkerSettings
(
isVisible:
true
,
borderColor:
Colors
.
white
,
height:
4
,
width:
4
),
// gradient: LinearGradient(
// colors: <Color>[
// Colors.white.withAlpha(100),
// Colors.white.withAlpha(10),
// ],
// begin: Alignment.topCenter,
// end: Alignment.bottomCenter,
// ),
onRendererCreated:
(
ChartSeriesController
controller
)
{
_chartSeriesController
=
controller
;
// setState(() {
// _chartSeriesController = controller;
// });
},
enableTooltip:
true
,
dataSource:
chartData
,
borderColor:
Colors
.
white
,
splineType:
SplineType
.
natural
,
color:
Colors
.
transparent
,
borderWidth:
3
,
name:
unit
,
xValueMapper:
(
SplineAreaWeightData
data
,
_
)
=>
data
.
title
,
yValueMapper:
(
SplineAreaWeightData
data
,
_
)
=>
data
.
value
,
)
],
tooltipBehavior:
TooltipBehavior
(
enable:
true
),
),
// setState(() {
// _chartSeriesController = controller;
// });
},
enableTooltip:
true
,
dataSource:
chartData
,
borderColor:
Colors
.
white
,
splineType:
SplineType
.
natural
,
color:
Colors
.
transparent
,
borderWidth:
3
,
name:
unit
,
xValueMapper:
(
SplineAreaWeightData
data
,
_
)
=>
data
.
title
,
yValueMapper:
(
SplineAreaWeightData
data
,
_
)
=>
data
.
value
,
)
],
tooltipBehavior:
TooltipBehavior
(
enable:
true
),
),
),
],
),
...
...
diabeta_app/lib/services/glucose_log_service.dart
View file @
72e11618
...
...
@@ -206,7 +206,7 @@ class GlucoseLogService {
}
static
Future
<
List
<
LogEntry
>>
getRecordsByTimeFrame
(
String
accountId
,
String
period
)
async
{
String
accountId
,
String
period
,
{
bool
isDecending
=
true
}
)
async
{
List
<
LogEntry
>
recordList
=
[];
DateTime
date
=
DateTime
.
now
();
...
...
@@ -218,7 +218,7 @@ class GlucoseLogService {
.
where
(
"userId"
,
isEqualTo:
accountId
)
.
where
(
"dateTime"
,
isGreaterThanOrEqualTo:
Timestamp
.
fromDate
(
firstDayOfWeek
))
.
orderBy
(
"dateTime"
,
descending:
true
)
.
orderBy
(
"dateTime"
,
descending:
isDecending
)
.
get
()
.
then
((
QuerySnapshot
querySnapshot
)
{
querySnapshot
.
docs
.
forEach
((
doc
)
{
...
...
@@ -245,7 +245,7 @@ class GlucoseLogService {
.
where
(
"dateTime"
,
isGreaterThanOrEqualTo:
Timestamp
.
fromDate
(
DateTime
(
now
.
year
,
now
.
month
,
1
)))
.
orderBy
(
"dateTime"
,
descending:
true
)
.
orderBy
(
"dateTime"
,
descending:
isDecending
)
.
get
()
.
then
((
QuerySnapshot
querySnapshot
)
{
querySnapshot
.
docs
.
forEach
((
doc
)
{
...
...
@@ -272,7 +272,7 @@ class GlucoseLogService {
.
where
(
"dateTime"
,
isGreaterThanOrEqualTo:
Timestamp
.
fromDate
(
DateTime
(
now
.
year
,
1
,
1
)))
.
orderBy
(
"dateTime"
,
descending:
true
)
.
orderBy
(
"dateTime"
,
descending:
isDecending
)
.
get
()
.
then
((
QuerySnapshot
querySnapshot
)
{
querySnapshot
.
docs
.
forEach
((
doc
)
{
...
...
@@ -295,7 +295,7 @@ class GlucoseLogService {
}
else
if
(
period
==
"All records"
)
{
await
_records
.
where
(
"userId"
,
isEqualTo:
accountId
)
.
orderBy
(
"dateTime"
,
descending:
true
)
.
orderBy
(
"dateTime"
,
descending:
isDecending
)
.
get
()
.
then
((
QuerySnapshot
querySnapshot
)
{
querySnapshot
.
docs
.
forEach
((
doc
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment