Dylan Meeus Dylan Meeus - 1 month ago 12
Dart Question

Dart can't find BrowserClient

I'm sure this is a basic mistake, but I seem unable to build an Angular2 application when using a BrowserClient in Dart.

main.dart

import 'package:angular2/platform/browser.dart';
import 'package:dartblog/app_component.dart';
import 'package:http/browser_client.dart';

void main(){
bootstrap(
AppComponent,
const [BrowserClient]
);
}


I did alter my pubspec.yaml; the important part:

- angular2:
platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
platform_pipes:
- 'package:angular2/common.dart#COMMON_PIPES'
entry_points: web/main.dart
resolved_identifiers:
BrowserClient: 'package:http/browser_client.dart'


The error I am getting when running
pub build
is the following:

[Error from Dart2JS on dartblog|web/main.dart]:
web/main.template.dart:15:1:
Can't read 'package:http/browser_client.dart' (Could not find asset http|lib/browser_client.dart.).
import 'package:http/browser_client.dart';
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Warning from Dart2JS]:
web/main.dart:6:40:
Cannot resolve 'BrowserClient'.
bootstrapStatic(AppComponent, const [BrowserClient], () { ngStaticInit.initReflector(); });
^^^^^^^^^^^^^
[Error from Dart2JS]:
web/main.dart:6:40:
Not a compile-time constant.
bootstrapStatic(AppComponent, const [BrowserClient], () { ngStaticInit.initReflector(); });
^^^^^^^^^^^^^


I am trying to make get requests with Dart.

Answer

BrowserClient in not injectable AFAICT.

try this:

@Injectable()
BrowserClient newBrowserClient() => new BrowserClient();
...
const Provider(BrowserClient, useFactory: newBrowserClient)

Obviously, you need to have the http package in your pub dependencies.