You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
309 lines
8.7 KiB
309 lines
8.7 KiB
5 years ago
|
import 'package:flutter/material.dart';
|
||
|
import 'dart:ui';
|
||
|
|
||
|
import 'models/train_data.dart';
|
||
|
|
||
|
class StationsList extends StatelessWidget {
|
||
|
final TrainData trainData;
|
||
|
StationsList(this.trainData);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: <Widget>[
|
||
|
for (final station in trainData.stations)
|
||
|
...[
|
||
|
// IntrinsicHeight(
|
||
|
/* child: */ Row(
|
||
|
children: <Widget>[
|
||
|
StopListLine(station),
|
||
|
Expanded(child: StopOnLineDetails(station))
|
||
|
],
|
||
|
),
|
||
|
// )
|
||
|
]
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
enum LineStyle {
|
||
|
SOLID,
|
||
|
DASHED
|
||
|
}
|
||
|
|
||
|
enum NotchStyle {
|
||
|
BLOB,
|
||
|
LINE,
|
||
|
DOT
|
||
|
}
|
||
|
|
||
|
class StopListLine extends StatelessWidget {
|
||
3 years ago
|
final Station station;
|
||
5 years ago
|
final int width;
|
||
|
StopListLine(this.station, {this.width = 32}) : assert(width.isEven);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
// return CustomPaint(
|
||
|
// child: SizedBox(
|
||
|
// height: double.infinity,
|
||
|
// width: width.toDouble(),
|
||
|
// ),
|
||
|
// painter: StopListLinePainter(
|
||
|
// primaryColor: Theme.of(context).primaryColor,
|
||
|
// secondaryColor: Theme.of(context).accentColor,
|
||
|
// borderColor: Theme.of(context).brightness == Brightness.light
|
||
|
// ? Colors.grey.shade700
|
||
|
// : Colors.grey.shade200,
|
||
|
// lineStyle: station.real ? LineStyle.SOLID : LineStyle.DASHED,
|
||
|
// ),
|
||
|
// );
|
||
|
return Container();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class StopListLinePainter extends CustomPainter {
|
||
|
final Color primaryColor;
|
||
|
final Color secondaryColor;
|
||
|
final Color borderColor;
|
||
|
final int lineWidth;
|
||
|
final int borderWidth;
|
||
|
final LineStyle lineStyle;
|
||
|
final NotchStyle notchStyle;
|
||
|
|
||
|
StopListLinePainter({
|
||
|
this.primaryColor,
|
||
|
this.secondaryColor,
|
||
|
this.borderColor,
|
||
|
this.lineStyle = LineStyle.SOLID,
|
||
|
this.notchStyle = NotchStyle.BLOB,
|
||
|
this.lineWidth = 16,
|
||
|
this.borderWidth = 2
|
||
|
}) : assert(lineWidth >= borderWidth * 4), assert(borderWidth >= 1);
|
||
|
|
||
|
Size painterSize;
|
||
|
|
||
|
@override
|
||
|
void paint(Canvas canvas, Size size) {
|
||
|
painterSize = size;
|
||
|
// TODO: implement paint
|
||
|
|
||
|
final width = size.width.toInt();
|
||
|
final height = size.height;
|
||
|
|
||
|
// Draw line on center
|
||
|
final beginX = width / 2 - lineWidth / 2;
|
||
|
final beginY1 = beginX - borderWidth;
|
||
|
final beginY2 = beginX + lineWidth;
|
||
|
|
||
|
var xPaint = Paint();
|
||
|
xPaint.color = secondaryColor;
|
||
|
xPaint.style = PaintingStyle.fill;
|
||
|
|
||
|
switch (lineStyle) {
|
||
|
case LineStyle.SOLID:
|
||
|
canvas.drawRect(Rect.fromLTWH(beginX, 0, lineWidth.toDouble(), height), xPaint);
|
||
|
break;
|
||
|
case LineStyle.DASHED:
|
||
|
for (var pos = 0; true; pos += (lineWidth * 2 + borderWidth * 2)) {
|
||
|
// if ()
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
|
||
|
var yPaint = Paint();
|
||
|
yPaint.color = borderColor;
|
||
|
yPaint.style = PaintingStyle.fill;
|
||
|
|
||
|
switch (lineStyle) {
|
||
|
case LineStyle.SOLID:
|
||
|
canvas.drawRect(Rect.fromLTWH(beginY1, 0, borderWidth.toDouble(), height), yPaint);
|
||
|
canvas.drawRect(Rect.fromLTWH(beginY2, 0, borderWidth.toDouble(), height), yPaint);
|
||
|
break;
|
||
|
case LineStyle.DASHED:
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
// Draw notch
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
||
|
final oldPainter = (oldDelegate as StopListLinePainter);
|
||
|
|
||
|
if (painterSize == null) return true;
|
||
|
if (oldPainter.painterSize != painterSize) return true;
|
||
|
|
||
|
if (oldPainter.primaryColor != primaryColor) return true;
|
||
|
if (oldPainter.secondaryColor != secondaryColor) return true;
|
||
|
if (oldPainter.lineWidth != lineWidth) return true;
|
||
|
if (oldPainter.borderWidth != borderWidth) return true;
|
||
|
if (oldPainter.primaryColor != primaryColor) return true;
|
||
|
if (oldPainter.secondaryColor != secondaryColor) return true;
|
||
|
if (oldPainter.borderColor != borderColor) return true;
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class StopOnLineDetails extends StatelessWidget {
|
||
3 years ago
|
final Station station;
|
||
5 years ago
|
StopOnLineDetails(this.station);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Padding(
|
||
|
padding: const EdgeInsets.fromLTRB(4.0, 0.0, 4.0, 0.0),
|
||
|
child: Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: <Widget>[
|
||
|
Divider(
|
||
|
height: 0,
|
||
|
),
|
||
|
Padding(
|
||
|
padding: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 1.0),
|
||
|
child: Text(
|
||
|
station.name,
|
||
3 years ago
|
style: Theme.of(context).textTheme.headline5,
|
||
5 years ago
|
textAlign: TextAlign.center,
|
||
|
),
|
||
|
),
|
||
3 years ago
|
// if (station.observations == "ONI")
|
||
|
// Padding(
|
||
|
// padding: const EdgeInsets.fromLTRB(8.0, 0.0, 8.0, 0.5),
|
||
|
// child: Text("oprire ne-itinerarică", style: Theme.of(context).textTheme.bodyText2.copyWith(color: Colors.red.shade700),),
|
||
|
// ),
|
||
5 years ago
|
Padding(
|
||
|
padding: const EdgeInsets.fromLTRB(8.0, 0.5, 8.0, 8.0),
|
||
5 years ago
|
child: Text(
|
||
|
"km ${station.km}",
|
||
|
style: Theme.of(context).textTheme.caption,
|
||
|
textAlign: TextAlign.center,
|
||
|
),
|
||
|
),
|
||
|
StopOnLineTimeDetails(station),
|
||
3 years ago
|
// TODO: Figure out how to display delay info
|
||
|
// if (station.arrival != null && station.arrival.status != null || station.departure != null && station.departure.status != null)
|
||
|
// Padding(
|
||
|
// padding: const EdgeInsets.all(2.0),
|
||
|
// child: StopOnLineDelayDetails(station),
|
||
|
// ),
|
||
5 years ago
|
Divider(
|
||
|
height: 0,
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class StopOnLineTimeDetails extends StatelessWidget {
|
||
3 years ago
|
final Station station;
|
||
5 years ago
|
StopOnLineTimeDetails(this.station);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Row(
|
||
|
children: <Widget>[
|
||
3 years ago
|
if (station.arrival != null)
|
||
5 years ago
|
Padding(
|
||
|
padding: const EdgeInsets.all(4.0),
|
||
|
child: Align(
|
||
|
alignment: Alignment.topLeft,
|
||
|
child: Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: <Widget>[
|
||
|
Text(
|
||
|
"sosește la",
|
||
|
textAlign: TextAlign.left,
|
||
|
),
|
||
|
Text(
|
||
3 years ago
|
station.arrival.scheduleTime,
|
||
5 years ago
|
textAlign: TextAlign.left,
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
3 years ago
|
if (station.stoppingTime != null)
|
||
5 years ago
|
Expanded(
|
||
|
child: Padding(
|
||
|
padding: const EdgeInsets.all(4.0),
|
||
|
child: Align(
|
||
|
alignment: Alignment.topCenter,
|
||
|
child: Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: <Widget>[
|
||
|
Text(
|
||
|
"staționează pentru",
|
||
|
textAlign: TextAlign.center,
|
||
|
),
|
||
|
Text(
|
||
3 years ago
|
"${station.stoppingTime} ${station.stoppingTime == 1 ? "minut" : "minute"}",
|
||
5 years ago
|
textAlign: TextAlign.center,
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
)
|
||
|
else
|
||
|
Expanded(child: Container(),),
|
||
3 years ago
|
if (station.departure != null)
|
||
5 years ago
|
Padding(
|
||
|
padding: const EdgeInsets.all(4.0),
|
||
|
child: Align(
|
||
|
alignment: Alignment.topRight,
|
||
|
child: Column(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: <Widget>[
|
||
|
Text(
|
||
|
"pleacă la",
|
||
|
textAlign: TextAlign.right,
|
||
|
),
|
||
|
Text(
|
||
3 years ago
|
station.departure.scheduleTime,
|
||
5 years ago
|
textAlign: TextAlign.right,
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
// class StopOnLineDelayDetails extends StatelessWidget {
|
||
|
// final Station station;
|
||
|
// StopOnLineDelayDetails(this.station);
|
||
5 years ago
|
|
||
3 years ago
|
// @override
|
||
|
// Widget build(BuildContext context) {
|
||
|
// if (station.delay == 0) {
|
||
|
// return Text(
|
||
|
// "Fără întârziere",
|
||
|
// style: Theme.of(context).textTheme.caption,
|
||
|
// textAlign: TextAlign.center,
|
||
|
// );
|
||
|
// }
|
||
|
// else if (station.delay < 0) {
|
||
|
// return Text(
|
||
|
// "${-(station.delay)} minute mai devreme",
|
||
|
// style: Theme.of(context).textTheme.bodyText2.copyWith(color: Colors.green.shade700),
|
||
|
// textAlign: TextAlign.center,
|
||
|
// );
|
||
|
// }
|
||
|
// else {
|
||
|
// return Text(
|
||
|
// "${station.delay} minute întârziere",
|
||
|
// style: Theme.of(context).textTheme.bodyText2.copyWith(color: Colors.red.shade700),
|
||
|
// textAlign: TextAlign.center,
|
||
|
// );
|
||
|
// }
|
||
|
// }
|
||
|
// }
|