Dart method$Class syntax

Issue

I’m new to dart, and following the tutorial provided on the Dart for the web page.

It all makes sense – apart from one piece of sytax:

final InjectorFactory injector = self.injector$Injector;

Here’s the full code from the tutorial:

import 'main.template.dart' as self;

const useHashLS = false;

@GenerateInjector([
  routerProvidersHash,
  ClassProvider(Client, useClass: InMemoryDataService),
  // Using a real back end?
  // Import 'package:http/browser_client.dart' and change the 
 above to:
  //   ClassProvider(Client, useClass: BrowserClient),
])
final InjectorFactory injector = self.injector$Injector;

void main() {
  runApp(ng.AppComponentNgFactory, createInjector: injector);
}

I’m a confused by the apparent .method$Class syntax. Can anyone explain to me what this means/what it’s doing?

It’s also underlined in Webstorm with the message The getter 'injector$Injector' isn't defined for the class 'self'. Regardless, it runs fine and works as expected.

Thanks in advance!

Solution

$ in an identifier has no special meaning. It’s by convention often used for names in generated code.

Angular also uses code generation and the code will only become available after code generation was executed for example by webdev serve or webdev build.

I don’t know the current state but the code might still be generated in a directory that is not analyzed by the DartAnalyzler and you might always see the error even wen the app can be run without problems.

Answered By – Günter Zöchbauer

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

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