AngularDart tour of heroes tutorial throws an error 'Hero' isn't a function?

Issue

error: ‘Hero’ isn’t a function. (invocation_of_non_function at [angular_dart_tour_of_heroes] lib\app_component.dart:18)

hero.dart

class Hero {
  final int id;
  String name;

  Hero(this.id, this.name);
}

app_component.dart

import 'package:angular/angular.dart';
import 'package:angular_components/angular_components.dart';

import 'hero.dart';

@Component(
  selector: 'my-app',
  styleUrls: const ['app_component.css'],
  templateUrl: 'app_component.html',
  directives: const [materialDirectives,],
  providers: const [materialProviders],
)
class AppComponent {
  final title = 'Tour of Heroes';
  Hero hero = Hero(1, 'Windstorm');

}

app_component.html

<h1>{{title}}</h1>
<h2>{{hero.name}}</h2>
<div><label>id: </label>{{hero.id}}</div>
<div><label>name: </label>{{hero.name}}</div>

Solution

Sounds like you are using a too old Dart version that still requires the now optional new

Answered By – Günter Zöchbauer

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

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