import 'package:flutter/cupertino.dart'; import 'package:info_tren/models/train_data.dart'; import 'package:info_tren/train_info_page/train_info.dart'; import 'package:info_tren/train_info_page/train_info_constants.dart'; class DisplayTrainStation extends StatelessWidget { final OnDemandStation station; DisplayTrainStation({@required this.station}); @override Widget build(BuildContext context) { return Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.center, children: [ Row( mainAxisSize: MainAxisSize.max, children: [ FutureDisplay( future: Future.wait([ station.delay, station.realOrEstimate, station.observations, ]), builder: (context, data) { final isDelayed = (data[0] as int) > 0; final isOnTime = !isDelayed && (data[1] as RealOrEstimate) == RealOrEstimate.real; final isNotScheduled = data[2] == "ONI"; return KmBadge( station: station, isNotScheduled: isNotScheduled, isDelayed: isDelayed, isOnTime: isOnTime, ); } ), 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, ); }, ) ) ], ), 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, ), ), ], ); }, ), 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(); }, ) ], ); } } 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: [ Expanded( child: Center( child: FutureDisplay( 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, ), ), ], ), ), ); } }