Skip to content

Commit

Permalink
Update data page ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Ritam Chakraborty committed Oct 19, 2020
1 parent d91e253 commit 5c98c9c
Showing 1 changed file with 56 additions and 20 deletions.
76 changes: 56 additions & 20 deletions lib/pages/data_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:coronatracker/data/constants.dart';
import 'package:coronatracker/models/country.dart';
import 'package:coronatracker/models/history.dart';
import 'package:coronatracker/models/single_record.dart';
Expand Down Expand Up @@ -37,6 +36,11 @@ class DataPage extends StatelessWidget {
Size size = MediaQuery.of(context).size;
String type = _heading.toLowerCase();

final textStyle = TextStyle(
color: Colors.white,
fontSize: Theme.of(context).textTheme.headline5.fontSize,
);

final Widget text = Text(
NumberFormat("###,###,###,###").format(int.parse(_value)),
style: TextStyle(
Expand All @@ -46,15 +50,13 @@ class DataPage extends StatelessWidget {
),
);

final loadingWidget = Card(
shape: SHAPE,
child: ListTile(
title: Text(
"Loading past records",
textAlign: TextAlign.center,
),
subtitle: LinearProgressIndicator(),
final loadingWidget = ListTile(
title: Text(
"Loading past records",
textAlign: TextAlign.center,
style: textStyle,
),
subtitle: LinearProgressIndicator(),
);

final boxDecoration = BoxDecoration(
Expand All @@ -65,12 +67,9 @@ class DataPage extends StatelessWidget {
),
);

Widget recordWidget({@required SingleRecord record}) => Card(
shape: SHAPE,
child: ListTile(
title: Text("Date: ${record.date}"),
trailing: Text("${record.value.toString()}"),
),
Widget recordWidget({@required SingleRecord record}) => ListTile(
title: Text("Date: ${record.date}"),
trailing: Text("${record.value.toString()}"),
);

Widget body() {
Expand Down Expand Up @@ -104,11 +103,38 @@ class DataPage extends StatelessWidget {
List<SingleRecord> records =
history.records.reversed.toList();

return ListView.builder(
itemCount: history.records.length,
itemBuilder: (BuildContext context, int index) {
return recordWidget(record: records[index]);
},
double averageDailyIncrement =
getAverageDailyIncrement(records);

return Column(
children: [
ListTile(
title: Text(
"Past Records",
textAlign: TextAlign.center,
style: textStyle,
),
subtitle: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Average daily increment: ${averageDailyIncrement.round()}",
textAlign: TextAlign.center,
),
),
),
SizedBox(height: 16),
Expanded(
child: ListView.separated(
itemCount: history.records.length,
itemBuilder: (BuildContext context, int index) {
return recordWidget(record: records[index]);
},
separatorBuilder: (BuildContext context, int index) {
return Divider();
},
),
),
],
);
},
),
Expand Down Expand Up @@ -144,4 +170,14 @@ class DataPage extends StatelessWidget {
),
);
}

double getAverageDailyIncrement(List<SingleRecord> records) {
double sum = 0.0;

for (int i = 1; i < records.length; ++i) {
sum += records[i - 1].value - records[i].value;
}

return sum / records.length;
}
}

0 comments on commit 5c98c9c

Please sign in to comment.