From f30c2a4dde26ec914194ad170bfdbae2481e37ab Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Sun, 15 Sep 2019 03:01:46 +0300 Subject: [PATCH 1/3] Move DisplayTrainStation out of main file Next step is to break it up in small parts --- lib/train_info_page/train_info_cupertino.dart | 218 +---------------- ...in_info_cupertino_DisplayTrainStation.dart | 219 ++++++++++++++++++ lib/train_info_page/train_info_prompt.dart | 9 +- 3 files changed, 226 insertions(+), 220 deletions(-) create mode 100644 lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart diff --git a/lib/train_info_page/train_info_cupertino.dart b/lib/train_info_page/train_info_cupertino.dart index fe9c5c3..93aa3ec 100644 --- a/lib/train_info_page/train_info_cupertino.dart +++ b/lib/train_info_page/train_info_cupertino.dart @@ -3,6 +3,7 @@ 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_animation_helpers.dart'; import 'package:info_tren/train_info_page/train_info_constants.dart'; +import 'package:info_tren/train_info_page/train_info_cupertino_DisplayTrainStation.dart'; import 'package:info_tren/utils/stream_list.dart'; class TrainInfoCupertino extends StatefulWidget { @@ -962,223 +963,6 @@ class DisplayTrainStations extends StatelessWidget { } } -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: [ - Padding( - padding: const EdgeInsets.all(8), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - border: Border.all( - width: 2, - color: FOREGROUND_WHITE, - ), - // 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, - ), - textAlign: TextAlign.center, - ); - }, - ), - ), - ), - Text( - "km", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 10), - ), - ], - ), - ), - ), - 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 CupertinoDivider extends StatelessWidget { final Color color; diff --git a/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart b/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart new file mode 100644 index 0000000..667406d --- /dev/null +++ b/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart @@ -0,0 +1,219 @@ +import 'package:flutter/cupertino.dart'; +import 'package:info_tren/models/train_data.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: [ + Padding( + padding: const EdgeInsets.all(8), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + border: Border.all( + width: 2, + color: FOREGROUND_WHITE, + ), + // 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, + ), + textAlign: TextAlign.center, + ); + }, + ), + ), + ), + Text( + "km", + style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 10), + ), + ], + ), + ), + ), + 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(); + }, + ) + ], + ); + } +} \ No newline at end of file diff --git a/lib/train_info_page/train_info_prompt.dart b/lib/train_info_page/train_info_prompt.dart index cd78164..5bea6db 100644 --- a/lib/train_info_page/train_info_prompt.dart +++ b/lib/train_info_page/train_info_prompt.dart @@ -331,9 +331,12 @@ class _TrainInfoPromptCupertinoState extends State wit ), ), Expanded( - child: getOperatorsListView(context, currentInput: trainNoController.text, onTrainSelected: (number) { - onTrainSelected(context, number); - }) + child: getOperatorsListView( + context, + currentInput: trainNoController.text, onTrainSelected: (number) { + onTrainSelected(context, number); + } + ) ) ], ), From 53b676266bff2f4289167248bced7959d74191c7 Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Sun, 15 Sep 2019 03:41:43 +0300 Subject: [PATCH 2/3] Added Km Badge colour - separated KmBadge - added colour for different types of events --- lib/main.dart | 17 ++- ...in_info_cupertino_DisplayTrainStation.dart | 142 +++++++++++++----- 2 files changed, 114 insertions(+), 45 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 866890c..f6ad378 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'dart:io' show Platform; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.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_cupertino.dart'; import 'package:info_tren/train_info_page/train_info_material.dart'; @@ -32,8 +33,12 @@ class StartPoint extends StatelessWidget { return TrainInfoPromptMaterial(); }, TrainInfo.routeName: (context) { - return TrainInfoMaterial( - trainNumber: ModalRoute.of(context).settings.arguments as int, + return TrainDataWebViewAdapter( + builder: (context) { + return TrainInfoMaterial( + trainNumber: ModalRoute.of(context).settings.arguments as int, + ); + }, ); }, }, @@ -55,8 +60,12 @@ class StartPoint extends StatelessWidget { return TrainInfoPromptCupertino(); }, TrainInfo.routeName: (context) { - return TrainInfoCupertino( - trainNumber: ModalRoute.of(context).settings.arguments as int, + return TrainDataWebViewAdapter( + builder: (context) { + return TrainInfoCupertino( + trainNumber: ModalRoute.of(context).settings.arguments as int, + ); + }, ); }, } diff --git a/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart b/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart index 667406d..c2ae599 100644 --- a/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart +++ b/lib/train_info_page/train_info_cupertino_DisplayTrainStation.dart @@ -1,5 +1,7 @@ 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; @@ -15,46 +17,24 @@ class DisplayTrainStation extends StatelessWidget { Row( mainAxisSize: MainAxisSize.max, children: [ - Padding( - padding: const EdgeInsets.all(8), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - border: Border.all( - width: 2, - color: FOREGROUND_WHITE, - ), - // 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, - ), - textAlign: TextAlign.center, - ); - }, - ), - ), - ), - Text( - "km", - style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 10), - ), - ], - ), - ), + 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>( @@ -216,4 +196,84 @@ class DisplayTrainStation extends StatelessWidget { ], ); } -} \ No newline at end of file +} + +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, + ), + ), + ], + ), + ), + ); + } +} From 5eebaf406f1581102a338dc2b2c711a1c2112dcf Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Sun, 15 Sep 2019 03:43:24 +0300 Subject: [PATCH 3/3] Added v2.0.3 changelog --- CHANGELOG.TXT | 7 +++++++ pubspec.yaml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.TXT b/CHANGELOG.TXT index 702f8ea..c9ab78a 100644 --- a/CHANGELOG.TXT +++ b/CHANGELOG.TXT @@ -1,3 +1,10 @@ +v2.0.3 +- added km badge colour for iOS + + will be added for Android soon + + green for being on time + + yellow for a non planned stop + + red for a delay + v2.0.2 - added translucency to the navigation bar on iOS diff --git a/pubspec.yaml b/pubspec.yaml index 5facb60..dc16d26 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: O aplicație de vizualizare a datelor puse la dispoziție de Inform # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 2.0.2 +version: 2.0.3 environment: sdk: ">=2.3.0 <3.0.0"