-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtop10.dart
87 lines (81 loc) · 2.65 KB
/
top10.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
import 'dart:io';
import 'package:ascent/model/ascent.dart';
import 'package:ascent/database.dart';
import 'package:flutter/material.dart';
class Top10Screen extends StatefulWidget {
@override
_Top10ScreenState createState() => _Top10ScreenState();
}
class _Top10ScreenState extends State<Top10Screen> {
@override
Widget build(BuildContext context) {
if (Platform.isIOS) {
return Material(
child: Container(
padding: EdgeInsets.only(top: 100.0, bottom: 100),
child: ListView(
children: [
buildHeader(context),
buildRows(context, DatabaseHelper.getTop10AllTime()),
buildRows(context, DatabaseHelper.getTop10Last12Months())
],
),
));
}
return Scaffold(
appBar: AppBar(
title: Text('Top 10'),
),
body: ListView(
children: [
buildHeader(context),
buildRows(context, DatabaseHelper.getTop10AllTime()),
buildRows(context, DatabaseHelper.getTop10Last12Months())
],
),
);
}
Widget buildHeader(BuildContext context) {
return FutureBuilder<List<int>>(
future: Future.wait([DatabaseHelper.getTop10ScoreAllTime(), DatabaseHelper.getTop10ScoreLast12Months()]),
builder: (context, AsyncSnapshot<List<int>> snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
int scoreAllTime = snapshot.data![0];
int scoreLast12 = snapshot.data![1];
return Row(children: [Text("All Time: $scoreAllTime"), Spacer(), Text("Last 12 Months: $scoreLast12")]);
});
}
Widget buildRows(BuildContext context, Future<List<Ascent>> future) {
return FutureBuilder<List<Ascent>>(
future: future,
initialData: List.empty(),
builder: (context, snapshot) {
if (!snapshot.hasData) return CircularProgressIndicator();
return Row(children: [
DataTable(
showCheckboxColumn: false,
columns: const [
DataColumn(label: Text("Score")),
DataColumn(label: Text("Grade")),
DataColumn(label: Text("Name")),
],
rows: <DataRow>[
for (int i = 0; i < snapshot.data!.length; i++) buildRow(snapshot.data![i]),
],
)
]);
},
);
}
DataRow buildRow(Ascent e) {
String crag = e.route!.crag != null && e.route!.crag!.name != null ? e.route!.crag!.name! : "";
String name = e.route!.name! + "\n" + crag;
return DataRow(
cells: [
DataCell(Text(e.score!.toString())),
DataCell(Text(e.route!.grade!)),
DataCell(Text(name)),
],
);
}
}