Compare commits
2 commits
Author | SHA1 | Date | |
---|---|---|---|
4e3955c277 | |||
|
6fab8e1974 |
11 changed files with 68 additions and 13 deletions
|
@ -6,6 +6,7 @@ import 'package:info_tren/components/select_train_suggestions/select_train_sugge
|
|||
import 'package:info_tren/models/train_operator_lines.dart';
|
||||
import 'package:info_tren/models/ui_design.dart';
|
||||
import 'package:info_tren/utils/default_ui_design.dart';
|
||||
import 'package:info_tren/utils/string_number_prefix.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
class SelectTrainSuggestions extends StatefulWidget {
|
||||
|
@ -100,7 +101,7 @@ abstract class SelectTrainSuggestionsState extends State<SelectTrainSuggestions>
|
|||
uiDesign: widget.uiDesign,
|
||||
operatorName: tuple.item2,
|
||||
trains: tuple.item1,
|
||||
onTrainSelected: widget.onTrainSelected,
|
||||
onTrainSelected: (s) => widget.onTrainSelected(s.numberPrefix),
|
||||
)).toList();
|
||||
|
||||
return CustomScrollView(
|
||||
|
|
|
@ -34,8 +34,10 @@ Map<String, WidgetBuilder> routesByUiDesign(UiDesign uiDesign) => {
|
|||
return SelectTrainPage(uiDesign: uiDesign);
|
||||
},
|
||||
TrainInfo.routeName: (context) {
|
||||
final params = ModalRoute.of(context)!.settings.arguments as TrainInfoParams;
|
||||
return TrainInfo(
|
||||
trainNumber: ModalRoute.of(context)!.settings.arguments as String,
|
||||
trainNumber: params.trainNumber,
|
||||
previousPageTitle: params.previousPageTitle,
|
||||
uiDesign: uiDesign,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:info_tren/utils/default_ui_design.dart';
|
|||
import 'package:info_tren/api/stations.dart' as apiStations;
|
||||
|
||||
class SelectStationPage extends StatefulWidget {
|
||||
static const pageTitle = 'Plecări/sosiri stație';
|
||||
final UiDesign? uiDesign;
|
||||
|
||||
const SelectStationPage({ Key? key, this.uiDesign }) : super(key: key);
|
||||
|
@ -26,7 +27,7 @@ class SelectStationPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
abstract class SelectStationPageState extends State<SelectStationPage> {
|
||||
static const pageTitle = 'Plecări/sosiri stație';
|
||||
static const pageTitle = SelectStationPage.pageTitle;
|
||||
static const textFieldLabel = 'Numele stației';
|
||||
static const roToEn = {
|
||||
'ă': 'a',
|
||||
|
|
|
@ -8,6 +8,7 @@ class SelectStationPageStateCupertino extends SelectStationPageState {
|
|||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(SelectStationPageState.pageTitle),
|
||||
previousPageTitle: 'Info Tren',
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
|
|
|
@ -30,7 +30,7 @@ class ViewStationPage extends StatefulWidget {
|
|||
|
||||
abstract class ViewStationPageState extends State<ViewStationPage> {
|
||||
static const arrivals = 'Sosiri';
|
||||
static const departures = 'Pleacări';
|
||||
static const departures = 'Plecări';
|
||||
static const loadingText = 'Se încarcă...';
|
||||
static const arrivesFrom = 'Sosește de la';
|
||||
static const departsTo = 'Pleacă către';
|
||||
|
@ -71,7 +71,13 @@ abstract class ViewStationPageState extends State<ViewStationPage> {
|
|||
}
|
||||
|
||||
void onTrainTapped(String trainNumber) {
|
||||
Navigator.of(context).pushNamed(TrainInfo.routeName, arguments: trainNumber);
|
||||
Navigator.of(context).pushNamed(
|
||||
TrainInfo.routeName,
|
||||
arguments: TrainInfoParams(
|
||||
trainNumber: trainNumber,
|
||||
previousPageTitle: stationName,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:info_tren/components/refresh_future_builder.dart';
|
|||
import 'package:flutter/src/widgets/framework.dart';
|
||||
import 'package:info_tren/components/sliver_persistent_header_padding.dart';
|
||||
import 'package:info_tren/models/station_data.dart';
|
||||
import 'package:info_tren/pages/station_arrdep_page/select_station/select_station.dart';
|
||||
import 'package:info_tren/pages/station_arrdep_page/view_station/view_station.dart';
|
||||
|
||||
class ViewStationPageStateCupertino extends ViewStationPageState {
|
||||
|
@ -12,6 +13,7 @@ class ViewStationPageStateCupertino extends ViewStationPageState {
|
|||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(snapshot.hasData ? snapshot.data!.stationName : stationName),
|
||||
previousPageTitle: SelectStationPage.pageTitle,
|
||||
),
|
||||
child: snapshot.hasData ? CupertinoTabScaffold(
|
||||
tabBar: CupertinoTabBar(
|
||||
|
|
|
@ -13,14 +13,21 @@ import 'package:tuple/tuple.dart';
|
|||
typedef TrainSelectedCallback(int trainNumber);
|
||||
|
||||
class SelectTrainPage extends StatefulWidget {
|
||||
static const String routeName = "/trainInfo/selectTrain";
|
||||
static const String pageTitle = 'Informații despre tren';
|
||||
|
||||
final UiDesign? uiDesign;
|
||||
|
||||
SelectTrainPage({Key? key, this.uiDesign}) : super(key: key);
|
||||
|
||||
static String routeName = "/trainInfo/selectTrain";
|
||||
|
||||
void onTrainSelected(BuildContext context, String selection) {
|
||||
Navigator.of(context).pushNamed(TrainInfo.routeName, arguments: selection);
|
||||
Navigator.of(context).pushNamed(
|
||||
TrainInfo.routeName,
|
||||
arguments: TrainInfoParams(
|
||||
trainNumber: selection,
|
||||
previousPageTitle: pageTitle,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -38,8 +45,8 @@ class SelectTrainPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
abstract class SelectTrainPageState extends State<SelectTrainPage> {
|
||||
final String pageTitle = 'Informații despre tren';
|
||||
final String textFieldLabel = 'Numărul trenului';
|
||||
final String pageTitle = SelectTrainPage.pageTitle;
|
||||
|
||||
TextEditingController trainNoController = TextEditingController();
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ class SelectTrainPageStateCupertino extends SelectTrainPageState {
|
|||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(pageTitle),
|
||||
previousPageTitle: 'Info Tren',
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
|
|
|
@ -10,14 +10,23 @@ import 'package:info_tren/pages/train_info_page/view_train/train_info_cupertino.
|
|||
import 'package:info_tren/pages/train_info_page/view_train/train_info_material.dart';
|
||||
import 'package:info_tren/utils/default_ui_design.dart';
|
||||
|
||||
class TrainInfoParams {
|
||||
final String trainNumber;
|
||||
final String? previousPageTitle;
|
||||
|
||||
TrainInfoParams({required this.trainNumber, this.previousPageTitle,});
|
||||
}
|
||||
|
||||
class TrainInfo extends StatelessWidget {
|
||||
static String routeName = "/trainInfo/display";
|
||||
|
||||
final UiDesign? uiDesign;
|
||||
final String trainNumber;
|
||||
final String previousPageTitle;
|
||||
|
||||
TrainInfo({Key? key, required this.trainNumber, this.uiDesign}): super(key: key);
|
||||
TrainInfo({Key? key, required this.trainNumber, this.uiDesign, String? previousPageTitle,})
|
||||
: previousPageTitle = previousPageTitle ?? 'Înapoi'
|
||||
, super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -46,10 +55,10 @@ class TrainInfo extends StatelessWidget {
|
|||
);
|
||||
case UiDesign.CUPERTINO:
|
||||
if ([RefreshFutureBuilderState.none, RefreshFutureBuilderState.waiting].contains(snapshot.state)) {
|
||||
return TrainInfoLoadingCupertino(title: trainNumber.toString(), loadingText: "Se încarcă...",);
|
||||
return TrainInfoLoadingCupertino(title: trainNumber.toString(), loadingText: "Se încarcă...", previousPageTitle: previousPageTitle,);
|
||||
}
|
||||
else if (snapshot.state == RefreshFutureBuilderState.error) {
|
||||
return TrainInfoErrorCupertino(title: '$trainNumber - Error', error: snapshot.error!, refresh: refresh,);
|
||||
return TrainInfoErrorCupertino(title: '$trainNumber - Error', error: snapshot.error!, refresh: refresh, previousPageTitle: previousPageTitle,);
|
||||
}
|
||||
|
||||
return TrainInfoCupertino(
|
||||
|
@ -57,6 +66,7 @@ class TrainInfo extends StatelessWidget {
|
|||
refresh: refresh,
|
||||
isRefreshing: snapshot.state == RefreshFutureBuilderState.refreshing,
|
||||
onViewYesterdayTrain: onViewYesterdayTrain,
|
||||
previousPageTitle: previousPageTitle,
|
||||
);
|
||||
default:
|
||||
throw UnmatchedUiDesignException(uiDesign);
|
||||
|
|
|
@ -12,7 +12,9 @@ import 'package:info_tren/pages/train_info_page/view_train/train_info_cupertino_
|
|||
import 'package:info_tren/utils/state_to_string.dart';
|
||||
|
||||
class TrainInfoLoadingCupertino extends TrainInfoLoading {
|
||||
TrainInfoLoadingCupertino({required String title, String? loadingText})
|
||||
final String? previousPageTitle;
|
||||
|
||||
TrainInfoLoadingCupertino({required String title, String? loadingText, this.previousPageTitle,})
|
||||
: super(
|
||||
title: title,
|
||||
loadingText: loadingText,
|
||||
|
@ -23,6 +25,7 @@ class TrainInfoLoadingCupertino extends TrainInfoLoading {
|
|||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(title),
|
||||
previousPageTitle: previousPageTitle ?? 'Înapoi',
|
||||
),
|
||||
child: Center(
|
||||
child: loadingWidget,
|
||||
|
@ -32,10 +35,13 @@ class TrainInfoLoadingCupertino extends TrainInfoLoading {
|
|||
}
|
||||
|
||||
class TrainInfoErrorCupertino extends TrainInfoError {
|
||||
final String? previousPageTitle;
|
||||
|
||||
TrainInfoErrorCupertino({
|
||||
required Object error,
|
||||
required String title,
|
||||
Future Function()? refresh,
|
||||
this.previousPageTitle,
|
||||
}) : super(
|
||||
error: error,
|
||||
title: title,
|
||||
|
@ -47,6 +53,7 @@ class TrainInfoErrorCupertino extends TrainInfoError {
|
|||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text(title),
|
||||
previousPageTitle: previousPageTitle ?? 'Înapoi',
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
|
@ -73,12 +80,14 @@ class TrainInfoCupertino extends StatelessWidget {
|
|||
final Future Function()? refresh;
|
||||
final bool? isRefreshing;
|
||||
final void Function()? onViewYesterdayTrain;
|
||||
final String previousPageTitle;
|
||||
|
||||
TrainInfoCupertino({
|
||||
required this.trainData,
|
||||
this.refresh,
|
||||
this.isRefreshing,
|
||||
this.onViewYesterdayTrain,
|
||||
required this.previousPageTitle,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -86,6 +95,7 @@ class TrainInfoCupertino extends StatelessWidget {
|
|||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text("Informații despre ${trainData.rank} ${trainData.number}"),
|
||||
previousPageTitle: previousPageTitle,
|
||||
trailing: refresh == null ? null : isRefreshing == true ? CupertinoActivityIndicator() : CupertinoButton(
|
||||
padding: const EdgeInsets.all(0),
|
||||
alignment: Alignment.center,
|
||||
|
|
14
lib/utils/string_number_prefix.dart
Normal file
14
lib/utils/string_number_prefix.dart
Normal file
|
@ -0,0 +1,14 @@
|
|||
extension NumberPrefix on String {
|
||||
String get numberPrefix {
|
||||
final sb = StringBuffer();
|
||||
for (final c in this.runes) {
|
||||
if ('0'.runes.first <= c && c <= '9'.runes.first) {
|
||||
sb.writeCharCode(c);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue