diff --git a/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart b/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart index c2ae599..bed28ae 100644 --- a/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart +++ b/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart @@ -24,8 +24,8 @@ class DisplayTrainStation extends StatelessWidget { station.observations, ]), builder: (context, data) { - final isDelayed = (data[0] as int) > 0; - final isOnTime = !isDelayed && (data[1] as RealOrEstimate) == RealOrEstimate.real; + final isDelayed = (data[0] as int) > 0 && (data[1] as RealOrEstimate) == RealOrEstimate.real; + final isOnTime = (data[0] as int) <= 0 && (data[1] as RealOrEstimate) == RealOrEstimate.real; final isNotScheduled = data[2] == "ONI"; return KmBadge( @@ -37,162 +37,18 @@ class DisplayTrainStation extends StatelessWidget { } ), Expanded( - child: FutureDisplay>( - future: Future.wait([ - station.stationName, - station.observations - ]), - builder: (context, items) { - return Text( - items[0], - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( - fontSize: 22, - fontWeight: FontWeight.w100, - fontStyle: items[1] == "ONI" ? FontStyle.italic : FontStyle.normal, - ), - textAlign: TextAlign.center, - ); - }, - ) + child: Title( + station: station, + ), ) ], ), - FutureDisplay>( - future: Future.wait([ - station.arrivalTime, - station.stopsFor, - station.departureTime - ]), - builder: (context, items) { - if (items[0].isEmpty) { - // Plecare - return Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Expanded(child: Container(),), - Text("plecare la ${items[2]}"), - Container(width: 2,), - Text( - "→", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( - fontSize: 22, - ), - ), - ], - ); - } - - if (items[2].isEmpty) { - // Sosire - return Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - "→", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( - fontSize: 22, - ), - ), - Container(width: 2,), - Text("sosire la ${items[0]}"), - Expanded(child: Container(),), - ], - ); - } - - return Row( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - "→", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( - fontSize: 22, - ), - ), - Container(width: 2,), - Text(items[0]), - Expanded(child: Container(),), - Column( - mainAxisSize: MainAxisSize.min, - children: [ - 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( - 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(); - }, - ) - ], - ), - Expanded(child: Container(),), - Text(items[2]), - Container(width: 2,), - Text( - "→", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( - fontSize: 22, - ), - ), - ], - ); - }, + Time( + station: station, + ), + Delay( + station: station, ), - FutureDisplay( - future: station.delay, - builder: (context, delay) { - if (delay == 0) return Container(); - - else if (delay > 0) { - return Text( - "$delay minute întârziere", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( - color: CupertinoColors.destructiveRed, - fontSize: 12, - fontStyle: FontStyle.italic, - ), - ); - } - - else if (delay < 0) { - return Text( - "${-delay} minute mai devreme", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( - color: CupertinoColors.activeGreen, - fontSize: 12, - fontStyle: FontStyle.italic, - ), - ); - } - - return Container(); - }, - ) ], ); } @@ -277,3 +133,412 @@ class KmBadge extends StatelessWidget { ); } } + +class Title extends StatelessWidget { + final OnDemandStation station; + + Title({ + @required this.station + }); + + @override + Widget build(BuildContext context) { + return FutureDisplay>( + future: Future.wait([ + station.stationName, + station.observations + ]), + builder: (context, items) { + return Text( + items[0], + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( + fontSize: 22, + fontWeight: FontWeight.w100, + fontStyle: items[1] == "ONI" ? FontStyle.italic : FontStyle.normal, + ), + textAlign: TextAlign.center, + ); + }, + ); + } +} + +class Time extends StatelessWidget { + final OnDemandStation station; + + Time({ + @required this.station, + }); + + @override + Widget build(BuildContext context) { + return FutureDisplay>( + future: Future.wait([ + station.arrivalTime, + station.stopsFor, + station.departureTime, + ]), + builder: (context, items) { + if (items[0].isEmpty) { + // Plecare + return DepartureTime( + station: station, + firstStation: true, + ); + } + + if (items[2].isEmpty) { + // Sosire + return ArrivalTime( + station: station, + finalStation: true, + ); + } + + return Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "→", + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( + fontSize: 22, + ), + ), + Container(width: 2,), + ArrivalTime(station: station,), + Expanded(child: Container(),), +// Column( +// mainAxisSize: MainAxisSize.min, +// children: [ +// 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( +// 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(),), + DepartureTime(station: station,), + Container(width: 2,), + Text( + "→", + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( + fontSize: 22, + ), + ), + ], + ); + }, + ); + } +} + +class ArrivalTime extends StatelessWidget { + final OnDemandStation station; + final bool finalStation; + + ArrivalTime({ + @required this.station, + this.finalStation = false, + }); + + @override + Widget build(BuildContext context) { + return FutureDisplay>( + future: Future.wait([ + station.arrivalTime, + station.delay, + ]), + builder: (context, data) { + if (finalStation) { + return Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "→", + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( + fontSize: 22, + ), + ), + Container(width: 2,), + Text("sosire la "), + ArrivalTime(station: station,), + 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(); + + 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: [ + 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.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: [ + 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( + future: station.stopsFor, + builder: (context, stopsFor) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "staționează pentru", + textAlign: TextAlign.center, + ), + Builder( + builder: (context) { + int stopsForInt = int.parse(stopsFor); + if (stopsForInt == 1) { + return Text( + "1 minut", + textAlign: TextAlign.center, + ); + } + else if (stopsForInt < 20) { + return Text( + "$stopsFor minute", + textAlign: TextAlign.center, + ); + } + else { + return Text( + "$stopsFor de minute", + textAlign: TextAlign.center, + ); + } + }, + ) + ], + ); + }, + ); + } +} + +class DepartureTime extends StatelessWidget { + final OnDemandStation station; + final bool firstStation; + + DepartureTime({ + @required this.station, + this.firstStation = false, + }); + + @override + Widget build(BuildContext context) { + return FutureDisplay>( + future: Future.wait([ + station.departureTime, + station.delay, + ]), + builder: (context, data) { + if (firstStation) { + return Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded(child: Container(),), + Text("plecare la "), + DepartureTime(station: station,), + Container(width: 2,), + Text( + "→", + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( + fontSize: 22, + ), + ), + ], + ); + } + 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(); + + 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: [ + 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.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: [ + 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 Delay extends StatelessWidget { + final OnDemandStation station; + + Delay({ + @required this.station, + }); + + @override + Widget build(BuildContext context) { + return FutureDisplay( + future: station.delay, + builder: (context, delay) { + if (delay == 0) return Container(); + + else if (delay > 0) { + return Text( + "$delay minute întârziere", + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( + color: CupertinoColors.destructiveRed, + fontSize: 12, + fontStyle: FontStyle.italic, + ), + ); + } + + else if (delay < 0) { + return Text( + "${-delay} minute mai devreme", + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith( + color: CupertinoColors.activeGreen, + fontSize: 12, + fontStyle: FontStyle.italic, + ), + ); + } + + return Container(); + }, + ); + } +} +