Compare commits
3 Commits
e799c3349b
...
c75d905dd8
| Author | SHA1 | Date | |
|---|---|---|---|
| c75d905dd8 | |||
| 537c231253 | |||
| fd47053834 |
@@ -11,7 +11,11 @@ class FloodStationListView extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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) {
|
itemBuilder: (context, index) {
|
||||||
final item = _stations.elementAt(index);
|
final item = _stations.elementAt(index);
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ class ReadingGraph extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (_readings.isEmpty) {
|
|
||||||
return Text('No readings on record.');
|
|
||||||
}
|
|
||||||
|
|
||||||
final spots = _readings
|
final spots = _readings
|
||||||
.map<FlSpot>(
|
.map<FlSpot>(
|
||||||
(e) => FlSpot(
|
(e) => FlSpot(
|
||||||
@@ -46,36 +42,53 @@ class ReadingGraph extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
titlesData: FlTitlesData(
|
titlesData: FlTitlesData(
|
||||||
bottomTitles: getBottomTitles(spots),
|
bottomTitles: getBottomTitles(spots),
|
||||||
|
leftTitles: getLeftTitles(spots),
|
||||||
topTitles: const AxisTitles(sideTitles: SideTitles()),
|
topTitles: const AxisTitles(sideTitles: SideTitles()),
|
||||||
rightTitles: 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) {
|
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(
|
return AxisTitles(
|
||||||
sideTitles: SideTitles(
|
sideTitles: SideTitles(
|
||||||
interval: 1,
|
interval: 90,
|
||||||
|
reservedSize: 40,
|
||||||
showTitles: true,
|
showTitles: true,
|
||||||
getTitlesWidget: (value, meta) {
|
maxIncluded: false,
|
||||||
String text = '';
|
getTitlesWidget: (value, meta) => SideTitleWidget(
|
||||||
if (value == maxX) {
|
meta: meta,
|
||||||
text = getDate(spots.first.x);
|
child: Text(getDate(value)),
|
||||||
} else if (double.parse(value.toStringAsFixed(0)) == minX) {
|
),
|
||||||
text = getDate(spots.last.x);
|
),
|
||||||
} else if (value == middle) {
|
);
|
||||||
text = getDate(middle);
|
|
||||||
}
|
}
|
||||||
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(
|
return hmFormat.format(
|
||||||
DateTime.fromMillisecondsSinceEpoch((value * 1000 * 60).toInt()));
|
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),
|
future: Api.fetchReadingsFromStation(_floodStation.id),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
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!,
|
readings: snapshot.data!,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
} else if (snapshot.hasError) {
|
||||||
// return ListView.builder(
|
return Center(child: Text('An unknown Error occured'));
|
||||||
// itemBuilder: (context, index) {
|
|
||||||
// return ListTile(
|
|
||||||
// title:
|
|
||||||
// Text(snapshot.data!.elementAt(index).value.toString()),
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// itemCount: snapshot.data!.length,
|
|
||||||
// );
|
|
||||||
} else {
|
} else {
|
||||||
return Placeholder();
|
return Center(child: CircularProgressIndicator());
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user