Compare commits
3 Commits
e799c3349b
...
c75d905dd8
| Author | SHA1 | Date | |
|---|---|---|---|
| c75d905dd8 | |||
| 537c231253 | |||
| fd47053834 |
@@ -11,7 +11,11 @@ class FloodStationListView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
return ListView.separated(
|
||||
separatorBuilder: (context, index) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 15.0),
|
||||
child: Divider(),
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final item = _stations.elementAt(index);
|
||||
return ListTile(
|
||||
|
||||
@@ -12,10 +12,6 @@ class ReadingGraph extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_readings.isEmpty) {
|
||||
return Text('No readings on record.');
|
||||
}
|
||||
|
||||
final spots = _readings
|
||||
.map<FlSpot>(
|
||||
(e) => FlSpot(
|
||||
@@ -46,36 +42,53 @@ class ReadingGraph extends StatelessWidget {
|
||||
],
|
||||
titlesData: FlTitlesData(
|
||||
bottomTitles: getBottomTitles(spots),
|
||||
leftTitles: getLeftTitles(spots),
|
||||
topTitles: const AxisTitles(sideTitles: SideTitles()),
|
||||
rightTitles: const AxisTitles(sideTitles: SideTitles()),
|
||||
),
|
||||
lineTouchData: LineTouchData(
|
||||
touchTooltipData: LineTouchTooltipData(
|
||||
getTooltipItems: (touchedSpots) {
|
||||
return touchedSpots.map((touchedSpot) {
|
||||
return LineTooltipItem(
|
||||
'${touchedSpot.y.toString()}\n${getLongDate(touchedSpot.x)}',
|
||||
TextStyle(
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
fontWeight: FontWeight.bold));
|
||||
}).toList();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
AxisTitles getBottomTitles(List<FlSpot> spots) {
|
||||
final maxX = double.parse(
|
||||
spots.map<double>((e) => (e.x)).reduce(max).toStringAsFixed(0));
|
||||
final minX = double.parse(
|
||||
spots.map<double>((e) => e.x).reduce(min).toStringAsFixed(0));
|
||||
final middle =
|
||||
double.parse(spots[spots.length ~/ 2].x.toStringAsFixed(0)) + 4;
|
||||
|
||||
return AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
interval: 1,
|
||||
interval: 90,
|
||||
reservedSize: 40,
|
||||
showTitles: true,
|
||||
getTitlesWidget: (value, meta) {
|
||||
String text = '';
|
||||
if (value == maxX) {
|
||||
text = getDate(spots.first.x);
|
||||
} else if (double.parse(value.toStringAsFixed(0)) == minX) {
|
||||
text = getDate(spots.last.x);
|
||||
} else if (value == middle) {
|
||||
text = getDate(middle);
|
||||
maxIncluded: false,
|
||||
getTitlesWidget: (value, meta) => SideTitleWidget(
|
||||
meta: meta,
|
||||
child: Text(getDate(value)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Text(text);
|
||||
},
|
||||
|
||||
AxisTitles getLeftTitles(List<FlSpot> spots) {
|
||||
return AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
reservedSize: 50,
|
||||
showTitles: true,
|
||||
maxIncluded: false,
|
||||
minIncluded: false,
|
||||
getTitlesWidget: (value, meta) => SideTitleWidget(
|
||||
meta: meta,
|
||||
child: Text(value.toStringAsFixed(2)),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -85,4 +98,18 @@ class ReadingGraph extends StatelessWidget {
|
||||
return hmFormat.format(
|
||||
DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt()));
|
||||
}
|
||||
|
||||
String getLongDate(double value) {
|
||||
DateTime date =
|
||||
DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt());
|
||||
int daysDifference = (DateTime.now().weekday - date.weekday + 7) % 7;
|
||||
|
||||
if (daysDifference == 0) {
|
||||
return 'Today ${intl.DateFormat('Hm').format(date)}';
|
||||
} else if (daysDifference == 1) {
|
||||
return 'Yesterday ${intl.DateFormat('Hm').format(date)}';
|
||||
}
|
||||
|
||||
return intl.DateFormat('yyyy-MM-dd H:m').format(date);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,21 +19,21 @@ class FloodStationPage extends StatelessWidget {
|
||||
future: Api.fetchReadingsFromStation(_floodStation.id),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return ReadingGraph(
|
||||
if (snapshot.data!.isEmpty) {
|
||||
return Center(child: Text('No readings on record.'));
|
||||
}
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 20),
|
||||
child: ReadingGraph(
|
||||
readings: snapshot.data!,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// return ListView.builder(
|
||||
// itemBuilder: (context, index) {
|
||||
// return ListTile(
|
||||
// title:
|
||||
// Text(snapshot.data!.elementAt(index).value.toString()),
|
||||
// );
|
||||
// },
|
||||
// itemCount: snapshot.data!.length,
|
||||
// );
|
||||
} else if (snapshot.hasError) {
|
||||
return Center(child: Text('An unknown Error occured'));
|
||||
} else {
|
||||
return Placeholder();
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user