Selection in Angular Dart material dropdown select gives error


I have a component with a material dropdown select and when the [(selection)] is of type SingleSelectionModel I got an error “angular dart Expected a value of type ‘SingleSelectionModel’, but got one of type ‘Term'”. When it’s of type Term it’s fine.
I need SingleSelectionModel to access its changes stream and to do some operations with the selected value.

I have Dart 2.2.0, angular: ^5.2.0, angular_components: ^0.11.0.

Can anybody help how to use SingleSelectionModel for [(selection)]?

  selector: 'x-plan-edit-rule',
  template: '''
  directives: const [
class EditPlanRuleComponent implements OnInit {

  @Input() Rule rule;
  SelectionOptions<Term> terms;
  SingleSelectionModel<Term> selectedTerm = SelectionModel<Term>.single(); // GIVES ERROR
  //Term selectedTerm; // WORKS FINE WITHOUT ERROR


  ngOnInit() {
    // List<Term> rule.availableTerms
    terms = SelectionOptions.fromList(rule.availableTerms);
    selectedTerm?.selectionChanges?.listen((_) {
      // do some checks after the selection change

  String get buttonText =>  'Some button text';


Finally I found a solution

I’ve split template binding [()] to [] and () so the template is

  template: '''

In Dart file I have a method validateTerm(Term term) which does some validation checks and assings selected term to selectedTerm. So I don’t need to monitor selection changes stream.

 Term selectedTerm;

 void validateTerm(Term term) {
    // do some validations...
    selectedTerm = term;

Answered By – Martin Edlman

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *