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

Commit ef4ca44

Browse files
srawlinsnshahan
authored andcommitted
Fix the type of MaterialDropdownSelectComponent's itemRenderer.
PiperOrigin-RevId: 225276100
1 parent eb5de2e commit ef4ca44

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

angular_components/lib/material_datepicker/material_time_picker.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import 'package:angular_components/utils/disposer/disposer.dart';
2727
materialInputDirectives,
2828
NgStyle,
2929
],
30+
directiveTypes: [
31+
Typed<MaterialDropdownSelectComponent<DateTime>>(),
32+
],
3033
providers: [
3134
Provider(HasDisabled, useExisting: MaterialTimePickerComponent),
3235
],
@@ -353,7 +356,7 @@ class MaterialTimePickerComponent extends KeyboardHandlerMixin
353356
///
354357
/// Only options between [minTime] and [maxTime] are selectable.
355358
class TimeSelectionOptions extends StringSelectionOptions<DateTime>
356-
implements Selectable {
359+
implements Selectable<DateTime> {
357360
DateTime _minTime;
358361
DateTime _maxTime;
359362

@@ -363,7 +366,7 @@ class TimeSelectionOptions extends StringSelectionOptions<DateTime>
363366
set maxTime(DateTime time) => _maxTime = time;
364367

365368
@override
366-
SelectableOption getSelectable(item) {
369+
SelectableOption getSelectable(DateTime item) {
367370
return item is DateTime &&
368371
((_minTime != null && item.isBefore(_minTime)) ||
369372
(_maxTime != null && item.isAfter(_maxTime)))

angular_components/lib/material_select/material_dropdown_select.dart

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,10 @@ class MaterialDropdownSelectComponent<T> extends MaterialSelectBase<T>
232232
}
233233

234234
/// Function to convert an option object to string.
235-
///
236-
// TODO(google): Fix this now that generics are supported.
237-
// Ideally, [value] would be a [ItemRenderer<T>], where T is also the type
238-
// parameter of the SelectionOptions and the SelectionModel, as parent
239-
// components typically use a function that accepts a specific type (T).
240-
//
241-
// However, we don't have a T. Angular doesn't support injecting a
242-
// type-annotated component yet, and setters, like [itemRenderer], cannot
243-
// be type-annotated. This forces us to accept a plain old [Function] as
244-
// [value], in order to avoid uses_dynamic_as_bottom errors. (Basically, a
245-
// function like [MaterialTimePicker]'s `String renderTime(DateTime time)`
246-
// cannot work as a [ItemRenderer], since it expects DateTime, not dynamic.)
247235
@Input()
248236
@override
249-
set itemRenderer(Function value) {
250-
super.itemRenderer = (item) => value(item);
237+
set itemRenderer(ItemRenderer<T> value) {
238+
super.itemRenderer = value;
251239
}
252240

253241
/// Width of the dropdown/list, default none, valid values are 0-5.

0 commit comments

Comments
 (0)