|
|
@ -1,50 +1,70 @@ |
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/widgets.dart'; |
|
|
|
import 'package:flutter/widgets.dart'; |
|
|
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart'; |
|
|
|
import 'package:info_tren/components/select_train_suggestions/select_train_suggestions_cupertino.dart'; |
|
|
|
import 'package:info_tren/components/select_train_suggestions/select_train_suggestions_cupertino.dart'; |
|
|
|
import 'package:info_tren/components/select_train_suggestions/select_train_suggestions_material.dart'; |
|
|
|
import 'package:info_tren/components/select_train_suggestions/select_train_suggestions_material.dart'; |
|
|
|
import 'package:info_tren/models.dart'; |
|
|
|
import 'package:info_tren/models.dart'; |
|
|
|
|
|
|
|
import 'package:info_tren/providers.dart'; |
|
|
|
import 'package:info_tren/utils/default_ui_design.dart'; |
|
|
|
import 'package:info_tren/utils/default_ui_design.dart'; |
|
|
|
|
|
|
|
|
|
|
|
class SelectTrainSuggestions extends StatefulWidget { |
|
|
|
class SelectTrainSuggestions extends ConsumerWidget { |
|
|
|
final UiDesign? uiDesign; |
|
|
|
|
|
|
|
final List<TrainsResult> choices; |
|
|
|
final List<TrainsResult> choices; |
|
|
|
final String? currentInput; |
|
|
|
final String? currentInput; |
|
|
|
final void Function(String trainNumber) onTrainSelected; |
|
|
|
final void Function(String trainNumber) onTrainSelected; |
|
|
|
|
|
|
|
|
|
|
|
const SelectTrainSuggestions({Key? key, required this.uiDesign, required this.choices, this.currentInput, required this.onTrainSelected }) : super(key: key); |
|
|
|
const SelectTrainSuggestions({required this.choices, this.currentInput, required this.onTrainSelected, super.key, }); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
SelectTrainSuggestionsState createState() { |
|
|
|
Widget build(BuildContext context, WidgetRef ref) { |
|
|
|
final uiDesign = this.uiDesign ?? defaultUiDesign; |
|
|
|
final uiDesign = ref.watch(uiDesignProvider); |
|
|
|
|
|
|
|
|
|
|
|
switch(uiDesign) { |
|
|
|
switch(uiDesign) { |
|
|
|
case UiDesign.MATERIAL: |
|
|
|
case UiDesign.MATERIAL: |
|
|
|
return SelectTrainSuggestionsStateMaterial(); |
|
|
|
return SelectTrainSuggestionsMaterial( |
|
|
|
|
|
|
|
choices: choices, |
|
|
|
|
|
|
|
onTrainSelected: onTrainSelected, |
|
|
|
|
|
|
|
currentInput: currentInput, |
|
|
|
|
|
|
|
); |
|
|
|
case UiDesign.CUPERTINO: |
|
|
|
case UiDesign.CUPERTINO: |
|
|
|
return SelectTrainSuggestionsStateCupertino(); |
|
|
|
return SelectTrainSuggestionsCupertino( |
|
|
|
|
|
|
|
choices: choices, |
|
|
|
|
|
|
|
onTrainSelected: onTrainSelected, |
|
|
|
|
|
|
|
currentInput: currentInput, |
|
|
|
|
|
|
|
); |
|
|
|
default: |
|
|
|
default: |
|
|
|
throw UnmatchedUiDesignException(uiDesign); |
|
|
|
throw UnmatchedUiDesignException(uiDesign); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
abstract class SelectTrainSuggestionsState extends State<SelectTrainSuggestions> { |
|
|
|
abstract class SelectTrainSuggestionsShared extends StatelessWidget { |
|
|
|
String getUseCurrentInputWidgetText(String currentInput) => 'Caută trenul cu numărul ${widget.currentInput}'; |
|
|
|
String getUseCurrentInputWidgetText(String currentInput) => 'Caută trenul cu numărul $currentInput'; |
|
|
|
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected); |
|
|
|
Widget getUseCurrentInputWidget(String currentInput, void Function(String) onTrainSelected); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final List<TrainsResult> choices; |
|
|
|
|
|
|
|
final String? currentInput; |
|
|
|
|
|
|
|
final void Function(String trainNumber) onTrainSelected; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const SelectTrainSuggestionsShared({ |
|
|
|
|
|
|
|
required this.choices, |
|
|
|
|
|
|
|
this.currentInput, |
|
|
|
|
|
|
|
required this.onTrainSelected, |
|
|
|
|
|
|
|
super.key, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context) { |
|
|
|
var slivers = widget.choices.map((c) => c.company).toSet().map((operator) => OperatorAutocompleteSliver( |
|
|
|
var slivers = choices.map((c) => c.company).toSet().map((operator) => OperatorAutocompleteSliver( |
|
|
|
uiDesign: widget.uiDesign, |
|
|
|
|
|
|
|
operatorName: operator, |
|
|
|
operatorName: operator, |
|
|
|
trains: widget.choices.where((c) => c.company == operator).toList(), |
|
|
|
trains: choices.where((c) => c.company == operator).toList(), |
|
|
|
onTrainSelected: widget.onTrainSelected, |
|
|
|
onTrainSelected: onTrainSelected, |
|
|
|
)).toList(); |
|
|
|
)).toList(); |
|
|
|
|
|
|
|
|
|
|
|
return CustomScrollView( |
|
|
|
return CustomScrollView( |
|
|
|
slivers: <Widget>[ |
|
|
|
slivers: <Widget>[ |
|
|
|
...slivers, |
|
|
|
...slivers, |
|
|
|
SliverToBoxAdapter( |
|
|
|
SliverToBoxAdapter( |
|
|
|
child: widget.currentInput != null && int.tryParse(widget.currentInput!) != null ? getUseCurrentInputWidget(widget.currentInput!, widget.onTrainSelected) : Container(), |
|
|
|
child: currentInput != null && int.tryParse(currentInput!) != null ? getUseCurrentInputWidget(currentInput!, onTrainSelected) : Container(), |
|
|
|
), |
|
|
|
), |
|
|
|
SliverToBoxAdapter( |
|
|
|
SliverToBoxAdapter( |
|
|
|
child: Container( |
|
|
|
child: Container( |
|
|
@ -56,16 +76,19 @@ abstract class SelectTrainSuggestionsState extends State<SelectTrainSuggestions> |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class OperatorAutocompleteSliver extends StatelessWidget { |
|
|
|
class OperatorAutocompleteSliver extends ConsumerWidget { |
|
|
|
final UiDesign? uiDesign; |
|
|
|
|
|
|
|
final String operatorName; |
|
|
|
final String operatorName; |
|
|
|
final List<TrainsResult> trains; |
|
|
|
final List<TrainsResult> trains; |
|
|
|
final void Function(String) 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({ |
|
|
|
|
|
|
|
super.key, |
|
|
|
|
|
|
|
required this.operatorName, |
|
|
|
|
|
|
|
required this.trains, |
|
|
|
|
|
|
|
required this.onTrainSelected, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Widget mapTrainToItem(TrainsResult train) { |
|
|
|
Widget mapTrainToItem(TrainsResult train, UiDesign uiDesign) { |
|
|
|
final uiDesign = this.uiDesign ?? defaultUiDesign; |
|
|
|
|
|
|
|
switch (uiDesign) { |
|
|
|
switch (uiDesign) { |
|
|
|
case UiDesign.MATERIAL: |
|
|
|
case UiDesign.MATERIAL: |
|
|
|
return OperatorAutocompleteTileMaterial( |
|
|
|
return OperatorAutocompleteTileMaterial( |
|
|
@ -85,7 +108,8 @@ class OperatorAutocompleteSliver extends StatelessWidget { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
Widget build(BuildContext context, WidgetRef ref) { |
|
|
|
|
|
|
|
final uiDesign = ref.watch(uiDesignProvider); |
|
|
|
if (trains.isEmpty) { |
|
|
|
if (trains.isEmpty) { |
|
|
|
return SliverToBoxAdapter(child: Container(),); |
|
|
|
return SliverToBoxAdapter(child: Container(),); |
|
|
|
} |
|
|
|
} |
|
|
@ -93,14 +117,14 @@ class OperatorAutocompleteSliver extends StatelessWidget { |
|
|
|
return SliverPrototypeExtentList( |
|
|
|
return SliverPrototypeExtentList( |
|
|
|
prototypeItem: Column( |
|
|
|
prototypeItem: Column( |
|
|
|
children: <Widget>[ |
|
|
|
children: <Widget>[ |
|
|
|
mapTrainToItem(const TrainsResult(company: 'Company', number: '123', rank: 'R')), |
|
|
|
mapTrainToItem(const TrainsResult(company: 'Company', number: '123', rank: 'R'), uiDesign), |
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
delegate: SliverChildBuilderDelegate( |
|
|
|
delegate: SliverChildBuilderDelegate( |
|
|
|
(context, index) { |
|
|
|
(context, index) { |
|
|
|
return Column( |
|
|
|
return Column( |
|
|
|
children: <Widget>[ |
|
|
|
children: <Widget>[ |
|
|
|
mapTrainToItem(trains[index]), |
|
|
|
mapTrainToItem(trains[index], uiDesign), |
|
|
|
], |
|
|
|
], |
|
|
|
); |
|
|
|
); |
|
|
|
}, |
|
|
|
}, |
|
|
|