@ -1,178 +1,100 @@
import ' package:flutter/material.dart ' hide Badge ;
import ' package:flutter/material.dart ' ;
import ' package:hooks_riverpod/hooks_riverpod.dart ' ;
import ' package:info_tren/components/train_id_text_span.dart ' ;
import ' package:info_tren/models.dart ' ;
import ' package:info_tren/models.dart ' ;
import ' package:info_tren/components/badge/badge.dart ' ;
import ' package:info_tren/components/badge/badge.dart ' ;
import ' package:info_tren/pages/train_info_page/view_train/train_info_material.dart ' ;
import ' package:info_tren/pages/train_info_page/view_train/train_info_material.dart ' ;
import ' package:info_tren/providers.dart ' ;
class DisplayTrainStation extends StatelessWidget {
class DisplayTrainStation extends StatelessWidget {
final TrainData Station station ;
final Station station ;
final void Function ( ) ? onTap ;
final void Function ( ) ? onTap ;
const DisplayTrainStation ( {
const DisplayTrainStation ( { required this . station , this . onTap , super . key , } ) ;
required this . station ,
this . onTap ,
super . key ,
} ) ;
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
return Column (
return Card (
mainAxisSize: MainAxisSize . min ,
child: InkWell (
children: [
onTap: onTap ,
if ( station . notes . whereType < TrainDataNoteDepartsAs > ( ) . isNotEmpty )
child: Padding (
Builder (
padding: const EdgeInsets . all ( 2 ) ,
builder: ( context ) {
child: Column (
final note =
mainAxisSize: MainAxisSize . min ,
station . notes . whereType < TrainDataNoteDepartsAs > ( ) . first ;
crossAxisAlignment: CrossAxisAlignment . center ,
return Padding (
children: < Widget > [
padding: const EdgeInsets . all ( 2.0 ) ,
Row (
child: Text . rich (
mainAxisSize: MainAxisSize . max ,
TextSpan (
children: [
const TextSpan ( text: ' Trenul pleacă cu numărul ' ) ,
trainIdSpan ( rank: note . rank , number: note . number ) ,
] ,
) ,
) ,
) ;
} ,
) ,
Card (
child: InkWell (
onTap: onTap ,
child: Padding (
padding: const EdgeInsets . all ( 2 ) ,
child: Column (
mainAxisSize: MainAxisSize . min ,
crossAxisAlignment: CrossAxisAlignment . center ,
children: < Widget > [
children: < Widget > [
Row (
Expanded (
mainAxisSize: MainAxisSize . max ,
flex: 1 ,
children: < Widget > [
child: Align (
Expanded (
alignment: Alignment . centerLeft ,
flex: 1 ,
child: Builder (
child: Align (
builder: ( context ) {
alignment: Alignment . centerLeft ,
final departureStatus = station . departure ? . status ;
child: Builder ( builder: ( context ) {
final arrivalStatus = station . arrival ? . status ;
final departureStatus = station . departure ? . status ;
int delay ;
final arrivalStatus = station . arrival ? . status ;
bool real ;
int delay ;
if ( departureStatus = = null ) {
bool real ;
delay = arrivalStatus ? . delay ? ? 0 ;
if ( departureStatus = = null ) {
real = arrivalStatus ? . real ? ? false ;
delay = arrivalStatus ? . delay ? ? 0 ;
}
real = arrivalStatus ? . real ? ? false ;
else if ( arrivalStatus = = null ) {
} else if ( arrivalStatus = = null ) {
delay = departureStatus . delay ;
delay = departureStatus . delay ;
real = departureStatus . real ;
real = departureStatus . real ;
}
} else {
else {
delay = departureStatus . delay ;
delay = departureStatus . delay ;
real = departureStatus . real ;
real = departureStatus . real ;
if ( ! real & & arrivalStatus . real ) {
if ( ! real & & arrivalStatus . real ) {
delay = arrivalStatus . delay ;
delay = arrivalStatus . delay ;
real = arrivalStatus . real ;
real = arrivalStatus . real ;
}
}
}
}
final isDelayed = delay > 0 & & real = = true ;
final isOnTime = delay < = 0 & & real = = true ;
final isDelayed = delay > 0 & & real = = true ;
const isNotScheduled = false ;
final isOnTime = delay < = 0 & & real = = true ;
const isNotScheduled = false ;
return Badge (
text: station . km . toString ( ) ,
return Badge (
caption: ' km ' ,
text: station . km . toString ( ) ,
isNotScheduled: isNotScheduled ,
caption: ' km ' ,
isDelayed: isDelayed ,
isNotScheduled: isNotScheduled ,
isOnTime: isOnTime ,
isDelayed: isDelayed ,
) ;
isOnTime: isOnTime ,
} ) ,
) ;
) ,
}
) ,
Title (
station: station ,
) ,
) ,
Expanded (
) ,
flex: 1 ,
child: ( station . platform = = null )
? Container ( )
: Align (
alignment: Alignment . centerRight ,
child: Badge (
text: station . platform ! ,
caption: ' linia ' ,
) ,
) ,
) ,
] ,
) ,
) ,
Tim e (
Title (
station: station ,
station: station ,
) ,
) ,
if ( station . notes
Expanded (
. whereType < TrainDataNoteDetachingWagons > ( )
flex: 1 ,
. isNotEmpty )
child: ( station . platform = = null )
Builder (
? Container ( )
builder: ( context ) {
: Align (
final note = station . notes
alignment: Alignment . centerRight ,
. whereType < TrainDataNoteDetachingWagons > ( )
child: Badge ( text: station . platform ! , caption: ' linia ' , ) ,
. first ;
) ,
return Text (
' Trenul detașează vagoane către ${ note . station } ' ,
textAlign: TextAlign . center ,
) ;
} ,
) ,
if ( station . notes
. whereType < TrainDataNoteReceivingWagons > ( )
. isNotEmpty )
Builder (
builder: ( context ) {
final note = station . notes
. whereType < TrainDataNoteReceivingWagons > ( )
. first ;
return Text (
' Trenul primește vagoane de la ${ note . station } ' ,
textAlign: TextAlign . center ,
) ;
} ,
) ,
Delay (
station: station ,
) ,
) ,
] ,
] ,
) ,
) ,
) ,
Time (
station: station ,
) ,
Delay (
station: station ,
) ,
] ,
) ,
) ,
) ,
) ,
if ( station . notes
) ,
. whereType < TrainDataNoteTrainNumberChange > ( )
. isNotEmpty )
Builder (
builder: ( context ) {
final note = station . notes
. whereType < TrainDataNoteTrainNumberChange > ( )
. first ;
return Padding (
padding: const EdgeInsets . all ( 2.0 ) ,
child: Text . rich (
TextSpan (
children: [
const TextSpan ( text: ' Trenul își schimbă numărul în ' ) ,
trainIdSpan ( rank: note . rank , number: note . number ) ,
] ,
) ,
) ,
) ;
} ,
) ,
] ,
) ;
) ;
}
}
}
}
class Title extends StatelessWidget {
class Title extends StatelessWidget {
final TrainData Station station ;
final Station station ;
const Title ( {
const Title ( {
required this . station ,
required this . station ,
@ -181,22 +103,20 @@ class Title extends StatelessWidget {
@ override
@ override
Widget build ( BuildContext context ) {
Widget build ( BuildContext context ) {
return Text (
return Text (
station . name ,
station . name ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
fontWeight: MediaQuery . of ( context ) . boldText
fontWeight: MediaQuery . of ( context ) . boldText ? FontWeight . w500 : FontWeight . w300 ,
? FontWeight . w500
/ / fontStyle: items [ 1 ] = = " ONI " ? FontStyle . italic : FontStyle . normal ,
: FontWeight . w300 ,
) ,
/ / fontStyle: items [ 1 ] = = " ONI " ? FontStyle . italic : FontStyle . normal ,
) ,
textAlign: TextAlign . center ,
textAlign: TextAlign . center ,
) ;
) ;
}
}
}
}
class Time extends StatelessWidget {
class Time extends StatelessWidget {
final TrainData Station station ;
final Station station ;
const Time ( {
const Time ( {
required this . station ,
required this . station ,
@ -227,43 +147,29 @@ class Time extends StatelessWidget {
Text (
Text (
" → " ,
" → " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
) ,
) ,
) ,
Container (
width: 2 ,
) ,
ArrivalTime (
station: station ,
) ,
Expanded (
child: Container ( ) ,
) ,
StopTime (
station: station ,
) ,
Expanded (
child: Container ( ) ,
) ,
DepartureTime (
station: station ,
) ,
Container (
width: 2 ,
) ,
) ,
Container ( width: 2 , ) ,
ArrivalTime ( station: station , ) ,
Expanded ( child: Container ( ) , ) ,
StopTime ( station: station , ) ,
Expanded ( child: Container ( ) , ) ,
DepartureTime ( station: station , ) ,
Container ( width: 2 , ) ,
Text (
Text (
" → " ,
" → " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
) ,
) ,
) ,
) ,
] ,
] ,
) ;
) ;
}
}
}
}
class ArrivalTime extends Consumer Widget {
class ArrivalTime extends StatelessWidget {
final TrainData Station station ;
final Station station ;
final bool finalStation ;
final bool finalStation ;
const ArrivalTime ( {
const ArrivalTime ( {
@ -273,8 +179,7 @@ class ArrivalTime extends ConsumerWidget {
} ) ;
} ) ;
@ override
@ override
Widget build ( BuildContext context , WidgetRef ref ) {
Widget build ( BuildContext context ) {
final tz = ref . watch ( uiTimeZoneProvider ) ;
if ( station . arrival = = null ) {
if ( station . arrival = = null ) {
return Container ( ) ;
return Container ( ) ;
}
}
@ -285,29 +190,24 @@ class ArrivalTime extends ConsumerWidget {
Text (
Text (
" → " ,
" → " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
fontSize: isSmallScreen ( context ) ? 18 : 22 ,
) ,
) ,
) ,
Container (
width: 2 ,
) ,
) ,
Container ( width: 2 , ) ,
const Text ( " sosire la " ) ,
const Text ( " sosire la " ) ,
ArrivalTime (
ArrivalTime ( station: station , ) ,
station: station ,
Expanded ( child: Container ( ) , ) ,
) ,
Expanded (
child: Container ( ) ,
) ,
] ,
] ,
) ;
) ;
} else {
}
else {
final delay = station . arrival ! . status ? . delay ? ? 0 ;
final delay = station . arrival ! . status ? . delay ? ? 0 ;
final time = tz . convertDateTime ( station . arrival ! . scheduleTime ) ;
final time = station . arrival ! . scheduleTime . toLocal ( ) ;
if ( delay = = 0 ) {
if ( delay = = 0 ) {
return Text (
return Text ( " ${ time . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ time . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ) ;
" ${ time . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ time . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ) ;
}
} else if ( delay > 0 ) {
else if ( delay > 0 ) {
final oldDate = time ;
final oldDate = time ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
@ -317,18 +217,19 @@ class ArrivalTime extends ConsumerWidget {
Text (
Text (
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
decoration: TextDecoration . lineThrough ,
decoration: TextDecoration . lineThrough ,
) ,
) ,
) ,
) ,
Text (
Text (
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
color: Colors . red . shade300 ,
color: Colors . red . shade300 ,
) ,
) ,
) ,
) ,
] ,
] ,
) ;
) ;
} else {
}
else {
final oldDate = time ;
final oldDate = time ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
@ -338,14 +239,14 @@ class ArrivalTime extends ConsumerWidget {
Text (
Text (
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
decoration: TextDecoration . lineThrough ,
decoration: TextDecoration . lineThrough ,
) ,
) ,
) ,
) ,
Text (
Text (
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
color: Colors . green . shade300 ,
color: Colors . green . shade300 ,
) ,
) ,
) ,
) ,
] ,
] ,
) ;
) ;
@ -355,7 +256,7 @@ class ArrivalTime extends ConsumerWidget {
}
}
class StopTime extends StatelessWidget {
class StopTime extends StatelessWidget {
final TrainData Station station ;
final Station station ;
const StopTime ( {
const StopTime ( {
required this . station ,
required this . station ,
@ -384,12 +285,14 @@ class StopTime extends StatelessWidget {
" 1 ${ minutes ? ' minut ' : ' secundă ' } " ,
" 1 ${ minutes ? ' minut ' : ' secundă ' } " ,
textAlign: TextAlign . center ,
textAlign: TextAlign . center ,
) ;
) ;
} else if ( stopsForInt < 20 ) {
}
else if ( stopsForInt < 20 ) {
return Text (
return Text (
" $ stopsForInt ${ minutes ? ' minute ' : ' secunde ' } " ,
" $ stopsForInt ${ minutes ? ' minute ' : ' secunde ' } " ,
textAlign: TextAlign . center ,
textAlign: TextAlign . center ,
) ;
) ;
} else {
}
else {
return Text (
return Text (
" $ stopsForInt de ${ minutes ? ' minute ' : ' secunde ' } " ,
" $ stopsForInt de ${ minutes ? ' minute ' : ' secunde ' } " ,
textAlign: TextAlign . center ,
textAlign: TextAlign . center ,
@ -402,8 +305,8 @@ class StopTime extends StatelessWidget {
}
}
}
}
class DepartureTime extends Consumer Widget {
class DepartureTime extends Stateless Widget {
final TrainData Station station ;
final Station station ;
final bool firstStation ;
final bool firstStation ;
const DepartureTime ( {
const DepartureTime ( {
@ -413,8 +316,7 @@ class DepartureTime extends ConsumerWidget {
} ) ;
} ) ;
@ override
@ override
Widget build ( BuildContext context , WidgetRef ref ) {
Widget build ( BuildContext context ) {
final tz = ref . watch ( uiTimeZoneProvider ) ;
if ( station . departure = = null ) {
if ( station . departure = = null ) {
return Container ( ) ;
return Container ( ) ;
}
}
@ -422,32 +324,27 @@ class DepartureTime extends ConsumerWidget {
return Row (
return Row (
crossAxisAlignment: CrossAxisAlignment . center ,
crossAxisAlignment: CrossAxisAlignment . center ,
children: < Widget > [
children: < Widget > [
Expanded (
Expanded ( child: Container ( ) , ) ,
child: Container ( ) ,
) ,
const Text ( " plecare la " ) ,
const Text ( " plecare la " ) ,
DepartureTime (
DepartureTime ( station: station , ) ,
station: station ,
Container ( width: 2 , ) ,
) ,
Container (
width: 2 ,
) ,
Text (
Text (
" → " ,
" → " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
fontSize: 22 ,
fontSize: 22 ,
) ,
) ,
) ,
) ,
] ,
] ,
) ;
) ;
} else {
}
else {
final delay = station . departure ! . status ? . delay ? ? 0 ;
final delay = station . departure ! . status ? . delay ? ? 0 ;
final time = tz . convertDateTime ( station . departure ! . scheduleTime ) ;
final time = station . departure ! . scheduleTime . toLocal ( ) ;
if ( delay = = 0 ) {
if ( delay = = 0 ) {
return Text (
return Text ( " ${ time . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ time . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ) ;
" ${ time . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ time . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ) ;
}
} else if ( delay > 0 ) {
else if ( delay > 0 ) {
final oldDate = time ;
final oldDate = time ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
@ -457,18 +354,19 @@ class DepartureTime extends ConsumerWidget {
Text (
Text (
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
decoration: TextDecoration . lineThrough ,
decoration: TextDecoration . lineThrough ,
) ,
) ,
) ,
) ,
Text (
Text (
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
color: Colors . red . shade300 ,
color: Colors . red . shade300 ,
) ,
) ,
) ,
) ,
] ,
] ,
) ;
) ;
} else {
}
else {
final oldDate = time ;
final oldDate = time ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
final newDate = oldDate . add ( Duration ( minutes: delay ) ) ;
@ -478,14 +376,14 @@ class DepartureTime extends ConsumerWidget {
Text (
Text (
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ oldDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ oldDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
decoration: TextDecoration . lineThrough ,
decoration: TextDecoration . lineThrough ,
) ,
) ,
) ,
) ,
Text (
Text (
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
" ${ newDate . hour . toString ( ) . padLeft ( 2 , ' 0 ' ) } : ${ newDate . minute . toString ( ) . padLeft ( 2 , ' 0 ' ) } " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
color: Colors . green . shade300 ,
color: Colors . green . shade300 ,
) ,
) ,
) ,
) ,
] ,
] ,
) ;
) ;
@ -494,8 +392,9 @@ class DepartureTime extends ConsumerWidget {
}
}
}
}
class Delay extends StatelessWidget {
class Delay extends StatelessWidget {
final TrainData Station station ;
final Station station ;
const Delay ( {
const Delay ( {
required this . station ,
required this . station ,
@ -518,19 +417,20 @@ class Delay extends StatelessWidget {
return Text (
return Text (
" $ delay ${ delay = = 1 ? ' minut ' : ' minute ' } întârziere " ,
" $ delay ${ delay = = 1 ? ' minut ' : ' minute ' } întârziere " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
color: Colors . red . shade300 ,
color: Colors . red . shade300 ,
fontSize: 14 ,
fontSize: 14 ,
fontStyle: FontStyle . italic ,
fontStyle: FontStyle . italic ,
) ,
) ,
) ;
) ;
} else if ( delay < 0 ) {
}
else if ( delay < 0 ) {
return Text (
return Text (
" ${ - delay } ${ delay = = - 1 ? ' minut ' : ' minute ' } mai devreme " ,
" ${ - delay } ${ delay = = - 1 ? ' minut ' : ' minute ' } mai devreme " ,
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
style: Theme . of ( context ) . textTheme . bodyMedium ? . copyWith (
color: Colors . green . shade300 ,
color: Colors . green . shade300 ,
fontSize: 14 ,
fontSize: 14 ,
fontStyle: FontStyle . italic ,
fontStyle: FontStyle . italic ,
) ,
) ,
) ;
) ;
}
}