Allowed any digits in train number (ex: IRN 01641)
This commit is contained in:
parent
e83f36eb86
commit
d9325afcdb
7 changed files with 17 additions and 16 deletions
|
@ -3,7 +3,7 @@ import 'package:info_tren/models/train_data.dart';
|
||||||
|
|
||||||
const AUTHORITY = 'scraper.infotren.dcdevelop.xyz';
|
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'));
|
final response = await http.get(Uri.https(AUTHORITY, 'train/$trainNumber'));
|
||||||
return trainDataFromJson(response.body);
|
return trainDataFromJson(response.body);
|
||||||
}
|
}
|
|
@ -11,7 +11,7 @@ import 'package:tuple/tuple.dart';
|
||||||
class SelectTrainSuggestions extends StatefulWidget {
|
class SelectTrainSuggestions extends StatefulWidget {
|
||||||
final UiDesign? uiDesign;
|
final UiDesign? uiDesign;
|
||||||
final String userInput;
|
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);
|
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';
|
String getUseCurrentInputWidgetText(String currentInput) => 'Caută trenul cu numărul $currentInput';
|
||||||
Widget getUseCurrentInputWidget(int currentInput, void Function(int) onTrainSelected);
|
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -107,7 +107,7 @@ abstract class SelectTrainSuggestionsState extends State<SelectTrainSuggestions>
|
||||||
slivers: <Widget>[
|
slivers: <Widget>[
|
||||||
...slivers,
|
...slivers,
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: int.tryParse(userInput) != null ? getUseCurrentInputWidget(int.parse(userInput), widget.onTrainSelected) : Container(),
|
child: int.tryParse(userInput) != null ? getUseCurrentInputWidget(userInput, widget.onTrainSelected) : Container(),
|
||||||
),
|
),
|
||||||
SliverToBoxAdapter(
|
SliverToBoxAdapter(
|
||||||
child: Container(
|
child: Container(
|
||||||
|
@ -149,7 +149,7 @@ class OperatorAutocompleteSliver extends StatelessWidget {
|
||||||
final UiDesign? uiDesign;
|
final UiDesign? uiDesign;
|
||||||
final String operatorName;
|
final String operatorName;
|
||||||
final List<TrainOperatorTrainDescription> trains;
|
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);
|
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 {
|
abstract class OperatorAutocompleteTile extends StatelessWidget {
|
||||||
final String operatorName;
|
final String operatorName;
|
||||||
final TrainOperatorTrainDescription train;
|
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);
|
const OperatorAutocompleteTile({ Key? key, required this.onTrainSelected, required this.operatorName, required this.train }) : super(key: key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import 'package:info_tren/models/train_operator_lines.dart';
|
||||||
|
|
||||||
class SelectTrainSuggestionsStateCupertino extends SelectTrainSuggestionsState {
|
class SelectTrainSuggestionsStateCupertino extends SelectTrainSuggestionsState {
|
||||||
@override
|
@override
|
||||||
Widget getUseCurrentInputWidget(int currentInput, void Function(int p1) onTrainSelected) {
|
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
@ -31,7 +31,7 @@ class OperatorAutocompleteTileCupertino extends OperatorAutocompleteTile {
|
||||||
OperatorAutocompleteTileCupertino({
|
OperatorAutocompleteTileCupertino({
|
||||||
Key? key,
|
Key? key,
|
||||||
required String operatorName,
|
required String operatorName,
|
||||||
required void Function(int) onTrainSelected,
|
required void Function(String) onTrainSelected,
|
||||||
required TrainOperatorTrainDescription train
|
required TrainOperatorTrainDescription train
|
||||||
}): super(
|
}): super(
|
||||||
onTrainSelected: onTrainSelected,
|
onTrainSelected: onTrainSelected,
|
||||||
|
@ -47,7 +47,7 @@ class OperatorAutocompleteTileCupertino extends OperatorAutocompleteTile {
|
||||||
children: [
|
children: [
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
onTrainSelected(train.internalNumber);
|
onTrainSelected(train.number);
|
||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 4, 16, 4),
|
padding: const EdgeInsets.fromLTRB(16, 4, 16, 4),
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:info_tren/models/train_operator_lines.dart';
|
||||||
|
|
||||||
class SelectTrainSuggestionsStateMaterial extends SelectTrainSuggestionsState {
|
class SelectTrainSuggestionsStateMaterial extends SelectTrainSuggestionsState {
|
||||||
@override
|
@override
|
||||||
Widget getUseCurrentInputWidget(int currentInput, void Function(int) onTrainSelected) {
|
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected) {
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
@ -24,7 +24,7 @@ class OperatorAutocompleteTileMaterial extends OperatorAutocompleteTile {
|
||||||
OperatorAutocompleteTileMaterial({
|
OperatorAutocompleteTileMaterial({
|
||||||
Key? key,
|
Key? key,
|
||||||
required String operatorName,
|
required String operatorName,
|
||||||
required void Function(int) onTrainSelected,
|
required void Function(String) onTrainSelected,
|
||||||
required TrainOperatorTrainDescription train
|
required TrainOperatorTrainDescription train
|
||||||
}): super(
|
}): super(
|
||||||
onTrainSelected: onTrainSelected,
|
onTrainSelected: onTrainSelected,
|
||||||
|
@ -40,7 +40,7 @@ class OperatorAutocompleteTileMaterial extends OperatorAutocompleteTile {
|
||||||
title: Text("${train.rang} ${train.number}"),
|
title: Text("${train.rang} ${train.number}"),
|
||||||
subtitle: Text(operatorName),
|
subtitle: Text(operatorName),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
onTrainSelected(train.internalNumber);
|
onTrainSelected(train.number);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,8 @@ Map<String, WidgetBuilder> routesByUiDesign(UiDesign uiDesign) => {
|
||||||
},
|
},
|
||||||
TrainInfo.routeName: (context) {
|
TrainInfo.routeName: (context) {
|
||||||
return TrainInfo(
|
return TrainInfo(
|
||||||
trainNumber: ModalRoute.of(context)!.settings.arguments as int,
|
trainNumber: ModalRoute.of(context)!.settings.arguments as String,
|
||||||
|
uiDesign: uiDesign,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SelectTrainPage extends StatefulWidget {
|
||||||
|
|
||||||
static String routeName = "/trainInfo/selectTrain";
|
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);
|
Navigator.of(context).pushNamed(TrainInfo.routeName, arguments: selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class TrainInfo extends StatelessWidget {
|
||||||
static String routeName = "/trainInfo/display";
|
static String routeName = "/trainInfo/display";
|
||||||
|
|
||||||
final UiDesign? uiDesign;
|
final UiDesign? uiDesign;
|
||||||
final int trainNumber;
|
final String trainNumber;
|
||||||
|
|
||||||
TrainInfo({Key? key, required this.trainNumber, this.uiDesign}): super(key: key);
|
TrainInfo({Key? key, required this.trainNumber, this.uiDesign}): super(key: key);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue