import 'package:flutter/material.dart'; import 'package:info_tren/stations_list.dart.old'; import 'models/train_data.dart'; class TrainInfoDisplayData extends StatelessWidget { final TrainData trainData; TrainInfoDisplayData(this.trainData); @override Widget build(BuildContext context) { return SingleChildScrollView( child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: TrainName(trainData), ), Padding( padding: const EdgeInsets.all(4.0), child: TrainRoute(trainData), ), Padding( padding: const EdgeInsets.all(4.0), child: TrainOperator(trainData), ), Padding( padding: const EdgeInsets.all(4.0), child: TotalDetails(trainData), ), CustomDivider(), Padding( padding: const EdgeInsets.all(4.0), child: Destination(trainData), ), CustomDivider(), Padding( padding: const EdgeInsets.all(4.0), child: LastUpdate(trainData), ), // if (trainData.nextStop.station.isNotEmpty) // ...[ // CustomDivider(), // Padding( // padding: const EdgeInsets.all(4.0), // child: NextStop(trainData), // ), // ], CustomDivider(), Padding( padding: const EdgeInsets.all(4.0), child: TrainStatus(trainData), ), Divider(color: Theme.of(context).colorScheme.secondary,), Padding( padding: const EdgeInsets.all(4.0), child: StationsList(trainData), ), SafeArea( child: Container(), bottom: true, left: false, right: false, top: false, ) ], ), ); } } class TrainName extends StatelessWidget { final TrainData trainData; TrainName(this.trainData); @override Widget build(BuildContext context) { return Text( "${trainData.rank} ${trainData.number}", style: Theme.of(context).textTheme.headline3, ); } } class TrainRoute extends StatelessWidget { final TrainData trainData; TrainRoute(this.trainData); @override Widget build(BuildContext context) { return Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: Text( trainData.route.from, style: Theme.of(context).textTheme.bodyText1?.copyWith(fontStyle: FontStyle.italic), textAlign: TextAlign.left, ), ), Text( "-", style: Theme.of(context).textTheme.bodyText1?.copyWith(fontStyle: FontStyle.italic), textAlign: TextAlign.center, ), Expanded( child: Text( trainData.route.to, style: Theme.of(context).textTheme.bodyText1?.copyWith(fontStyle: FontStyle.italic), textAlign: TextAlign.right, ), ), ] ); } } class TrainOperator extends StatelessWidget { final TrainData trainData; TrainOperator(this.trainData); @override Widget build(BuildContext context) { return Text( "Operat de ${trainData.operator}", style: Theme.of(context).textTheme.bodyText2, textAlign: TextAlign.center, ); } } class TrainStatus extends StatelessWidget { final TrainData trainData; TrainStatus(this.trainData); @override Widget build(BuildContext context) { return Text( trainData.status.toString(), textAlign: TextAlign.center, style: Theme.of(context).textTheme.headline5, ); } } class Destination extends StatelessWidget { final TrainData trainData; Destination(this.trainData); @override Widget build(BuildContext context) { final destinationStation = trainData.stations.last; return Column( children: [ Text( "Destinația: ${destinationStation.name}", textAlign: TextAlign.center, ), Text( "Sosește la ${destinationStation.arrival!.scheduleTime}", textAlign: TextAlign.center, ), ], ); } } class LastUpdate extends StatelessWidget { final TrainData trainData; LastUpdate(this.trainData); @override Widget build(BuildContext context) { if (trainData.status == null) { return Container(); } return Column( mainAxisSize: MainAxisSize.min, children: [ Padding( padding: const EdgeInsets.all(2.0), child: Text("Ultima informație", style: Theme.of(context).textTheme.headline5,), ), Row( children: [ Padding( padding: const EdgeInsets.all(2.0), child: Text(trainData.status!.station, textAlign: TextAlign.left,), ), Expanded(child: Container(),), Padding( padding: const EdgeInsets.all(2.0), child: Text(trainData.status!.state.toString(), textAlign: TextAlign.right,), ) ], ), Padding( padding: const EdgeInsets.all(2.0), child: trainData.status!.delay == 0 ? Text("Fără întârziere", style: Theme.of(context).textTheme.caption,) : trainData.status!.delay > 0 ? Text("${trainData.status!.delay} minute întârziere", style: Theme.of(context).textTheme.bodyText2?.copyWith(color: Colors.red.shade700),) : Text("${-(trainData.status!.delay)} minute mai devreme", style: Theme.of(context).textTheme.bodyText2?.copyWith(color: Colors.green.shade700),) ), // TODO: Implement status report time detection // Padding( // padding: const EdgeInsets.all(2.0), // child: Text("Raportat la ${trainData.lastInfo.dateAndTime}"), // ), ], ); } } // class NextStop extends StatelessWidget { // final TrainData trainData; // NextStop(this.trainData); // @override // Widget build(BuildContext context) { // return Column( // mainAxisSize: MainAxisSize.min, // children: [ // Padding( // padding: const EdgeInsets.all(2.0), // child: Text("Următoarea oprire", style: Theme.of(context).textTheme.headline5,), // ), // Row( // children: [ // Padding( // padding: const EdgeInsets.all(2.0), // child: Text(trainData.nextStop.station, textAlign: TextAlign.left,), // ), // Expanded(child: Container(),), // Padding( // padding: const EdgeInsets.all(2.0), // child: Text(trainData.nextStop.dateAndTime, textAlign: TextAlign.right,), // ) // ], // ), // ], // ); // } // } class TotalDetails extends StatelessWidget { final TrainData trainData; TotalDetails(this.trainData); @override Widget build(BuildContext context) { return Row( children: [ Text( '${trainData.stations.last.km} km', style: Theme.of(context).textTheme.caption, textAlign: TextAlign.left, ), Expanded( child: Container() ), // Text( // trainData.tripLength, // style: Theme.of(context).textTheme.caption, // textAlign: TextAlign.right, // ) ], ); } } class CustomDivider extends StatelessWidget { @override Widget build(BuildContext context) { return Column( mainAxisSize: MainAxisSize.min, children: [ Container(height: 4,), Divider(), Container(height: 4,), ], ); } }