Browse Source

Allowed any digits in train number (ex: IRN 01641)

tmp
Dan Cojocaru 3 years ago
parent
commit
d9325afcdb
Signed by: kbruen
GPG Key ID: 818A889458EDC937
  1. 2
      lib/api/train_data.dart
  2. 12
      lib/components/select_train_suggestions/select_train_suggestions.dart
  3. 6
      lib/components/select_train_suggestions/select_train_suggestions_cupertino.dart
  4. 6
      lib/components/select_train_suggestions/select_train_suggestions_material.dart
  5. 3
      lib/main.dart
  6. 2
      lib/pages/train_info_page/select_train/select_train.dart
  7. 2
      lib/pages/train_info_page/view_train/train_info.dart

2
lib/api/train_data.dart

@ -3,7 +3,7 @@ import 'package:info_tren/models/train_data.dart';
const AUTHORITY = 'scraper.infotren.dcdevelop.xyz';
Future<TrainData> getTrain(int trainNumber) async {
Future<TrainData> getTrain(String trainNumber) async {
final response = await http.get(Uri.https(AUTHORITY, 'train/$trainNumber'));
return trainDataFromJson(response.body);
}

12
lib/components/select_train_suggestions/select_train_suggestions.dart

@ -11,7 +11,7 @@ import 'package:tuple/tuple.dart';
class SelectTrainSuggestions extends StatefulWidget {
final UiDesign? uiDesign;
final String userInput;
final void Function(int trainNumber) onTrainSelected;
final void Function(String trainNumber) onTrainSelected;
const SelectTrainSuggestions({ Key? key, required this.uiDesign, required this.userInput, required this.onTrainSelected }) : super(key: key);
@ -70,8 +70,8 @@ abstract class SelectTrainSuggestionsState extends State<SelectTrainSuggestions>
}
}
String getUseCurrentInputWidgetText(int currentInput) => 'Caută trenul cu numărul $currentInput';
Widget getUseCurrentInputWidget(int currentInput, void Function(int) onTrainSelected);
String getUseCurrentInputWidgetText(String currentInput) => 'Caută trenul cu numărul $currentInput';
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected);
@override
Widget build(BuildContext context) {
@ -107,7 +107,7 @@ abstract class SelectTrainSuggestionsState extends State<SelectTrainSuggestions>
slivers: <Widget>[
...slivers,
SliverToBoxAdapter(
child: int.tryParse(userInput) != null ? getUseCurrentInputWidget(int.parse(userInput), widget.onTrainSelected) : Container(),
child: int.tryParse(userInput) != null ? getUseCurrentInputWidget(userInput, widget.onTrainSelected) : Container(),
),
SliverToBoxAdapter(
child: Container(
@ -149,7 +149,7 @@ class OperatorAutocompleteSliver extends StatelessWidget {
final UiDesign? uiDesign;
final String operatorName;
final List<TrainOperatorTrainDescription> trains;
final void Function(int) onTrainSelected;
final void Function(String) onTrainSelected;
const OperatorAutocompleteSliver({ Key? key, required this.uiDesign, required this.operatorName, required this.trains, required this.onTrainSelected }) : super(key: key);
@ -203,7 +203,7 @@ class OperatorAutocompleteSliver extends StatelessWidget {
abstract class OperatorAutocompleteTile extends StatelessWidget {
final String operatorName;
final TrainOperatorTrainDescription train;
final void Function(int) onTrainSelected;
final void Function(String) onTrainSelected;
const OperatorAutocompleteTile({ Key? key, required this.onTrainSelected, required this.operatorName, required this.train }) : super(key: key);
}

6
lib/components/select_train_suggestions/select_train_suggestions_cupertino.dart

@ -5,7 +5,7 @@ import 'package:info_tren/models/train_operator_lines.dart';
class SelectTrainSuggestionsStateCupertino extends SelectTrainSuggestionsState {
@override
Widget getUseCurrentInputWidget(int currentInput, void Function(int p1) onTrainSelected) {
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
@ -31,7 +31,7 @@ class OperatorAutocompleteTileCupertino extends OperatorAutocompleteTile {
OperatorAutocompleteTileCupertino({
Key? key,
required String operatorName,
required void Function(int) onTrainSelected,
required void Function(String) onTrainSelected,
required TrainOperatorTrainDescription train
}): super(
onTrainSelected: onTrainSelected,
@ -47,7 +47,7 @@ class OperatorAutocompleteTileCupertino extends OperatorAutocompleteTile {
children: [
GestureDetector(
onTap: () {
onTrainSelected(train.internalNumber);
onTrainSelected(train.number);
},
child: Padding(
padding: const EdgeInsets.fromLTRB(16, 4, 16, 4),

6
lib/components/select_train_suggestions/select_train_suggestions_material.dart

@ -4,7 +4,7 @@ import 'package:info_tren/models/train_operator_lines.dart';
class SelectTrainSuggestionsStateMaterial extends SelectTrainSuggestionsState {
@override
Widget getUseCurrentInputWidget(int currentInput, void Function(int) onTrainSelected) {
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
@ -24,7 +24,7 @@ class OperatorAutocompleteTileMaterial extends OperatorAutocompleteTile {
OperatorAutocompleteTileMaterial({
Key? key,
required String operatorName,
required void Function(int) onTrainSelected,
required void Function(String) onTrainSelected,
required TrainOperatorTrainDescription train
}): super(
onTrainSelected: onTrainSelected,
@ -40,7 +40,7 @@ class OperatorAutocompleteTileMaterial extends OperatorAutocompleteTile {
title: Text("${train.rang} ${train.number}"),
subtitle: Text(operatorName),
onTap: () {
onTrainSelected(train.internalNumber);
onTrainSelected(train.number);
},
);
}

3
lib/main.dart

@ -32,7 +32,8 @@ Map<String, WidgetBuilder> routesByUiDesign(UiDesign uiDesign) => {
},
TrainInfo.routeName: (context) {
return TrainInfo(
trainNumber: ModalRoute.of(context)!.settings.arguments as int,
trainNumber: ModalRoute.of(context)!.settings.arguments as String,
uiDesign: uiDesign,
);
},
};

2
lib/pages/train_info_page/select_train/select_train.dart

@ -19,7 +19,7 @@ class SelectTrainPage extends StatefulWidget {
static String routeName = "/trainInfo/selectTrain";
void onTrainSelected(BuildContext context, int selection) {
void onTrainSelected(BuildContext context, String selection) {
Navigator.of(context).pushNamed(TrainInfo.routeName, arguments: selection);
}

2
lib/pages/train_info_page/view_train/train_info.dart

@ -15,7 +15,7 @@ class TrainInfo extends StatelessWidget {
static String routeName = "/trainInfo/display";
final UiDesign? uiDesign;
final int trainNumber;
final String trainNumber;
TrainInfo({Key? key, required this.trainNumber, this.uiDesign}): super(key: key);

Loading…
Cancel
Save