Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit ddf2e75

Browse files
srawlinsnshahan
authored andcommitted
Fix classes which extend StringSelectionOptions and implement Selectable.
Many classes extend StringSelectionOptions<T>, but implement Selectable<dynamic>. This will result in runtime errors if the MaterialDropdownSelectComponent which uses the class as options is typed with T other than dynamic. This CL is part of #TheGreatTypedMaterialDropdownSelectComponentMigration, but only a side change which is written to improve safety and improve correctness, but isn't necessary as a prerequisite to typing MaterialDropdownSelectComponent's itemRenderer. PiperOrigin-RevId: 225211488
1 parent 599d4df commit ddf2e75

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

examples/material_input_example/lib/material_auto_suggest_input_full_demo.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class MaterialAutoSuggestInputFullDemoComponent {
9292
final multiModel = SelectionModel<List>.multi();
9393

9494
final suggestionOptions =
95-
ExampleSelectionOptions<List<int>>.withOptionGroups(_optionGroups);
95+
ExampleSelectionOptions.withOptionGroups(_optionGroups);
9696
final suggestionOptionsWithItemRenderer =
97-
ExampleSelectionOptions<List<int>>.withOptionGroups(_optionGroups,
97+
ExampleSelectionOptions.withOptionGroups(_optionGroups,
9898
toFilterableString: _numberNameRenderer);
9999

100100
final emptySuggestionOptions = StringSelectionOptions(const <String>[]);
@@ -206,16 +206,16 @@ class ExampleLabelRendererComponent implements RendersValue {
206206
}
207207
}
208208

209-
class ExampleSelectionOptions<T> extends StringSelectionOptions<T>
210-
implements Selectable {
211-
ExampleSelectionOptions(List<T> options) : super(options);
209+
class ExampleSelectionOptions extends StringSelectionOptions<List<int>>
210+
implements Selectable<List<int>> {
211+
ExampleSelectionOptions(List<List<int>> options) : super(options);
212212
ExampleSelectionOptions.withOptionGroups(List<OptionGroup> optionGroups,
213-
{ItemRenderer<T> toFilterableString})
213+
{ItemRenderer<List<int>> toFilterableString})
214214
: super.withOptionGroups(optionGroups,
215215
toFilterableString: toFilterableString);
216216
@override
217-
SelectableOption getSelectable(item) {
218-
if (item is List && item.contains(13)) {
217+
SelectableOption getSelectable(List<int> item) {
218+
if (item.contains(13)) {
219219
return SelectableOption.Disabled;
220220
}
221221
return SelectableOption.Selectable;

examples/material_select_example/lib/material_dropdown_select_full_demo.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ class MaterialDropdownSelectFullDemoComponent {
129129
String deselectLabel = 'None';
130130

131131
/// Languages to choose from.
132-
ExampleSelectionOptions<Language> languageListOptions =
133-
ExampleSelectionOptions<Language>(_languagesList);
132+
ExampleSelectionOptions languageListOptions =
133+
ExampleSelectionOptions(_languagesList);
134134

135-
ExampleSelectionOptions<Language> languageGroupedOptions =
136-
ExampleSelectionOptions<Language>.withOptionGroups(_languagesGroups);
135+
ExampleSelectionOptions languageGroupedOptions =
136+
ExampleSelectionOptions.withOptionGroups(_languagesGroups);
137137

138138
StringSelectionOptions<Language> get languageOptions =>
139139
useOptionGroup ? languageGroupedOptions : languageListOptions;
@@ -305,15 +305,16 @@ class ExampleLabelRendererComponent implements RendersValue<OptionGroup> {
305305

306306
/// If the option does not support toString() that shows the label, the
307307
/// toFilterableString parameter must be passed to StringSelectionOptions.
308-
class ExampleSelectionOptions<T> extends StringSelectionOptions<T>
309-
implements Selectable {
310-
ExampleSelectionOptions(List<T> options)
311-
: super(options, toFilterableString: (T option) => option.toString());
308+
class ExampleSelectionOptions extends StringSelectionOptions<Language>
309+
implements Selectable<Language> {
310+
ExampleSelectionOptions(List<Language> options)
311+
: super(options,
312+
toFilterableString: (Language option) => option.toString());
312313
ExampleSelectionOptions.withOptionGroups(List<OptionGroup> optionGroups)
313314
: super.withOptionGroups(optionGroups,
314-
toFilterableString: (T option) => option.toString());
315+
toFilterableString: (Language option) => option.toString());
315316
@override
316-
SelectableOption getSelectable(item) =>
317+
SelectableOption getSelectable(Language item) =>
317318
item is Language && item.code.contains('en')
318319
? SelectableOption.Disabled
319320
: SelectableOption.Selectable;

0 commit comments

Comments
 (0)