I can not access it from any list element method (Invalid argument (index): "2") in Angular dart


  selector: 'my-app',   
  template: '''  <div> <button (click)="getItemName(2)"> get</button> </div>    ''',
class ListComponent {  //...
  List<Product> listProducts;

  void getItemName(int id) {
    print(listProducts[id].name); // <- invalid argumant (index) : "2"

html_dart2js.dart:3558 EXCEPTION: Invalid argument (index): “0”
STACKTRACE: Invalid argument (index): “0”
at Object.wrapException (
at Interceptor.$index (
at Object.J.$index$asx (
at GroupsComponent.add$1 (
at Object.J.add$1$ax (
at ViewGroupsComponent0.dart.ViewGroupsComponent0._handle_click_131_0$1

where do i make mistakes thanks


The index parameter needs to be an integer value, not a string.

Answered By – Günter Zöchbauer

Answer Checked By – Senaida (FlutterFixes Volunteer)

Leave a Reply

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