Browse Source

Added original time for delays

iOS only
working_branch
Kenneth Bruen 5 years ago
parent
commit
7f5feff9c2
  1. 507
      lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart

507
lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart

@ -24,8 +24,8 @@ class DisplayTrainStation extends StatelessWidget {
station.observations, station.observations,
]), ]),
builder: (context, data) { builder: (context, data) {
final isDelayed = (data[0] as int) > 0; final isDelayed = (data[0] as int) > 0 && (data[1] as RealOrEstimate) == RealOrEstimate.real;
final isOnTime = !isDelayed && (data[1] as RealOrEstimate) == RealOrEstimate.real; final isOnTime = (data[0] as int) <= 0 && (data[1] as RealOrEstimate) == RealOrEstimate.real;
final isNotScheduled = data[2] == "ONI"; final isNotScheduled = data[2] == "ONI";
return KmBadge( return KmBadge(
@ -37,7 +37,113 @@ class DisplayTrainStation extends StatelessWidget {
} }
), ),
Expanded( Expanded(
child: FutureDisplay<List<String>>( child: Title(
station: station,
),
)
],
),
Time(
station: station,
),
Delay(
station: station,
),
],
);
}
}
class KmBadge extends StatelessWidget {
final OnDemandStation station;
final bool isNotScheduled;
final bool isOnTime;
final bool isDelayed;
KmBadge({
@required this.station,
this.isNotScheduled = false,
this.isOnTime = false,
this.isDelayed = false,
});
@override
Widget build(BuildContext context) {
Color foregroundColor = FOREGROUND_WHITE;
Color backgroundColor;
if (isNotScheduled) {
foregroundColor = Color.fromRGBO(225, 175, 30, 1);
backgroundColor = Color.fromRGBO(80, 40, 10, 1);
}
else if (isOnTime) {
foregroundColor = Color.fromRGBO(130, 175, 65, 1);
backgroundColor = Color.fromRGBO(40, 80, 10, 1);
}
else if (isDelayed) {
foregroundColor = Color.fromRGBO(225, 75, 30, 1);
backgroundColor = Color.fromRGBO(80, 20, 10, 1);
}
return Padding(
padding: const EdgeInsets.all(8),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
width: 2,
color: foregroundColor,
),
color: backgroundColor,
// color: CupertinoColors.activeOrange,
),
width: 48,
height: 48,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: Center(
child: FutureDisplay<int>(
future: station.km,
builder: (context, value) {
return Text(
value.toString(),
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 18,
fontWeight: FontWeight.w100,
color: foregroundColor
),
textAlign: TextAlign.center,
);
},
),
),
),
Text(
"km",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 10,
color: foregroundColor,
),
),
],
),
),
);
}
}
class Title extends StatelessWidget {
final OnDemandStation station;
Title({
@required this.station
});
@override
Widget build(BuildContext context) {
return FutureDisplay<List<String>>(
future: Future.wait([ future: Future.wait([
station.stationName, station.stationName,
station.observations station.observations
@ -53,24 +159,95 @@ class DisplayTrainStation extends StatelessWidget {
textAlign: TextAlign.center, textAlign: TextAlign.center,
); );
}, },
) );
) }
], }
),
FutureDisplay<List<String>>( class Time extends StatelessWidget {
final OnDemandStation station;
Time({
@required this.station,
});
@override
Widget build(BuildContext context) {
return FutureDisplay<List<String>>(
future: Future.wait([ future: Future.wait([
station.arrivalTime, station.arrivalTime,
station.stopsFor, station.stopsFor,
station.departureTime station.departureTime,
]), ]),
builder: (context, items) { builder: (context, items) {
if (items[0].isEmpty) { if (items[0].isEmpty) {
// Plecare // Plecare
return DepartureTime(
station: station,
firstStation: true,
);
}
if (items[2].isEmpty) {
// Sosire
return ArrivalTime(
station: station,
finalStation: true,
);
}
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text(
"",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 22,
),
),
Container(width: 2,),
ArrivalTime(station: station,),
Expanded(child: Container(),),
// Column(
// mainAxisSize: MainAxisSize.min,
// children: <Widget>[
// Builder(
// builder: (context) {
// if (items[1].isEmpty || items[1] == "0") {
// return Container();
// }
// if (items[1] == "1") {
// return Text(
// "staționează pentru\n1 minut",
// textAlign: TextAlign.center,
// );
// }
// return Text(
// "staționează pentru\n${items[1]} minute",
// textAlign: TextAlign.center,
// );
// }
// ),
// FutureBuilder<String>(
// future: station.observations,
// builder: (context, snapshot) {
// if (snapshot.data == "ONI") {
// return Text(
// "oprire ne-itinerarică",
// style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
// fontStyle: FontStyle.italic,
// ),
// textAlign: TextAlign.center,
// );
// }
//
// return Container();
// },
// )
// ],
// ),
StopTime(station: station,),
Expanded(child: Container(),), Expanded(child: Container(),),
Text("plecare la ${items[2]}"), DepartureTime(station: station,),
Container(width: 2,), Container(width: 2,),
Text( Text(
"", "",
@ -80,10 +257,29 @@ class DisplayTrainStation extends StatelessWidget {
), ),
], ],
); );
},
);
}
} }
if (items[2].isEmpty) { class ArrivalTime extends StatelessWidget {
// Sosire final OnDemandStation station;
final bool finalStation;
ArrivalTime({
@required this.station,
this.finalStation = false,
});
@override
Widget build(BuildContext context) {
return FutureDisplay<List<Object>>(
future: Future.wait([
station.arrivalTime,
station.delay,
]),
builder: (context, data) {
if (finalStation) {
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
@ -94,64 +290,145 @@ class DisplayTrainStation extends StatelessWidget {
), ),
), ),
Container(width: 2,), Container(width: 2,),
Text("sosire la ${items[0]}"), Text("sosire la "),
ArrivalTime(station: station,),
Expanded(child: Container(),), Expanded(child: Container(),),
], ],
); );
} }
else {
if (data[1] == 0) {
return Text("${data[0]}");
}
else if (data[1] as int > 0) {
final splits = (data[0] as String).split(":").map((s) => int.parse(s)).toList();
return Row( final now = DateTime.now();
crossAxisAlignment: CrossAxisAlignment.center, final newDate = DateTime(now.year, now.month, now.day, splits[0], splits[1]);
final oldDate = newDate.subtract(Duration(minutes: data[1] as int));
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
Text( Text(
"", "${oldDate.hour.toString().padLeft(2, '0')}:${oldDate.minute.toString().padLeft(2, '0')}",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 22, decoration: TextDecoration.lineThrough,
), ),
), ),
Container(width: 2,), Text(
Text(items[0]), "${data[0]}",
Expanded(child: Container(),), style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
Column( color: CupertinoColors.destructiveRed,
),
),
],
);
}
else {
final splits = (data[0] as String).split(":").map((s) => int.parse(s)).toList();
final now = DateTime.now();
final newDate = DateTime(now.year, now.month, now.day, splits[0], splits[1]);
final oldDate = newDate.subtract(Duration(minutes: data[1] as int));
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
"${oldDate.hour.toString().padLeft(2, '0')}:${oldDate.minute.toString().padLeft(2, '0')}",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
decoration: TextDecoration.lineThrough,
),
),
Text(
"${data[0]}",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
color: CupertinoColors.activeGreen,
),
),
],
);
}
}
},
);
}
}
class StopTime extends StatelessWidget {
final OnDemandStation station;
StopTime({
@required this.station,
});
@override
Widget build(BuildContext context) {
return FutureDisplay<String>(
future: station.stopsFor,
builder: (context, stopsFor) {
return Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
Text(
"staționează pentru",
textAlign: TextAlign.center,
),
Builder( Builder(
builder: (context) { builder: (context) {
if (items[1].isEmpty || items[1] == "0") { int stopsForInt = int.parse(stopsFor);
return Container(); if (stopsForInt == 1) {
}
if (items[1] == "1") {
return Text( return Text(
"staționează pentru\n1 minut", "1 minut",
textAlign: TextAlign.center, textAlign: TextAlign.center,
); );
} }
else if (stopsForInt < 20) {
return Text( return Text(
"staționează pentru\n${items[1]} minute", "$stopsFor minute",
textAlign: TextAlign.center, textAlign: TextAlign.center,
); );
} }
), else {
FutureBuilder<String>(
future: station.observations,
builder: (context, snapshot) {
if (snapshot.data == "ONI") {
return Text( return Text(
"oprire ne-itinerarică", "$stopsFor de minute",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontStyle: FontStyle.italic,
),
textAlign: TextAlign.center, textAlign: TextAlign.center,
); );
} }
return Container();
}, },
) )
], ],
), );
},
);
}
}
class DepartureTime extends StatelessWidget {
final OnDemandStation station;
final bool firstStation;
DepartureTime({
@required this.station,
this.firstStation = false,
});
@override
Widget build(BuildContext context) {
return FutureDisplay<List<Object>>(
future: Future.wait([
station.departureTime,
station.delay,
]),
builder: (context, data) {
if (firstStation) {
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Expanded(child: Container(),), Expanded(child: Container(),),
Text(items[2]), Text("plecare la "),
DepartureTime(station: station,),
Container(width: 2,), Container(width: 2,),
Text( Text(
"", "",
@ -161,119 +438,107 @@ class DisplayTrainStation extends StatelessWidget {
), ),
], ],
); );
}, }
), else {
FutureDisplay<int>( if (data[1] == 0) {
future: station.delay, return Text("${data[0]}");
builder: (context, delay) { }
if (delay == 0) return Container(); else if (data[1] as int > 0) {
final splits = (data[0] as String).split(":").map((s) => int.parse(s)).toList();
else if (delay > 0) { final now = DateTime.now();
return Text( final newDate = DateTime(now.year, now.month, now.day, splits[0], splits[1]);
"$delay minute întârziere", final oldDate = newDate.subtract(Duration(minutes: data[1] as int));
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
"${oldDate.hour.toString().padLeft(2, '0')}:${oldDate.minute.toString().padLeft(2, '0')}",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
decoration: TextDecoration.lineThrough,
),
),
Text(
"${data[0]}",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
color: CupertinoColors.destructiveRed, color: CupertinoColors.destructiveRed,
fontSize: 12,
fontStyle: FontStyle.italic,
), ),
),
],
); );
} }
else {
final splits = (data[0] as String).split(":").map((s) => int.parse(s)).toList();
else if (delay < 0) { final now = DateTime.now();
return Text( final newDate = DateTime(now.year, now.month, now.day, splits[0], splits[1]);
"${-delay} minute mai devreme", final oldDate = newDate.subtract(Duration(minutes: data[1] as int));
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
"${oldDate.hour.toString().padLeft(2, '0')}:${oldDate.minute.toString().padLeft(2, '0')}",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
decoration: TextDecoration.lineThrough,
),
),
Text(
"${data[0]}",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
color: CupertinoColors.activeGreen, color: CupertinoColors.activeGreen,
fontSize: 12,
fontStyle: FontStyle.italic,
), ),
),
],
); );
} }
}
return Container();
}, },
)
],
); );
} }
} }
class KmBadge extends StatelessWidget {
class Delay extends StatelessWidget {
final OnDemandStation station; final OnDemandStation station;
final bool isNotScheduled;
final bool isOnTime;
final bool isDelayed;
KmBadge({ Delay({
@required this.station, @required this.station,
this.isNotScheduled = false,
this.isOnTime = false,
this.isDelayed = false,
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Color foregroundColor = FOREGROUND_WHITE; return FutureDisplay<int>(
Color backgroundColor; future: station.delay,
builder: (context, delay) {
if (delay == 0) return Container();
if (isNotScheduled) { else if (delay > 0) {
foregroundColor = Color.fromRGBO(225, 175, 30, 1); return Text(
backgroundColor = Color.fromRGBO(80, 40, 10, 1); "$delay minute întârziere",
} style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
else if (isOnTime) { color: CupertinoColors.destructiveRed,
foregroundColor = Color.fromRGBO(130, 175, 65, 1); fontSize: 12,
backgroundColor = Color.fromRGBO(40, 80, 10, 1); fontStyle: FontStyle.italic,
} ),
else if (isDelayed) { );
foregroundColor = Color.fromRGBO(225, 75, 30, 1);
backgroundColor = Color.fromRGBO(80, 20, 10, 1);
} }
return Padding( else if (delay < 0) {
padding: const EdgeInsets.all(8),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
width: 2,
color: foregroundColor,
),
color: backgroundColor,
// color: CupertinoColors.activeOrange,
),
width: 48,
height: 48,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: Center(
child: FutureDisplay<int>(
future: station.km,
builder: (context, value) {
return Text( return Text(
value.toString(), "${-delay} minute mai devreme",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 18, color: CupertinoColors.activeGreen,
fontWeight: FontWeight.w100, fontSize: 12,
color: foregroundColor fontStyle: FontStyle.italic,
), ),
textAlign: TextAlign.center,
); );
}
return Container();
}, },
),
),
),
Text(
"km",
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(
fontSize: 10,
color: foregroundColor,
),
),
],
),
),
); );
} }
} }

Loading…
Cancel
Save