How can I execute two dart code in one HTML

这一生的挚爱 提交于 2020-01-01 06:12:12

问题


I'm trying to build an Dart App.

This is the process that I would like to have.

At the first connection, the user have a loading page. During this time, he has an animation, and in background, the big dart file is downloaded (came from dart2js for dart).

Once it's over, the downloaded script is execute and the app cans start to work.

Any idea about the possibility of this process ?

Thank you. EDIT:

import "dart:async";
@lazy
import 'test.dart' as foo;

const lazy = const DeferredLibrary('test');

void main() {
  foo.init(); // Supposed to throw a NoSuchMethodError.
  lazy.load().then(onFooLoaded);
}

void onFooLoaded(_) {
  foo.init();
}

test.dart

library test;

void init() {
  print("coucou");
}

回答1:


It's called deferred loading. Basically this feature exists a while already but I haven't used it myself yet. Because of some open issues this feature seemed of limited use. I saw a notice that several bugs or missing feature were fixed but I can't tell the current status.

For more information see
- https://api.dartlang.org/apidocs/channels/be/dartdoc-viewer/dart:async.DeferredLibrary
- http://blog.sethladd.com/2013/04/lazy-load-libraries-in-dart.html
- https://code.google.com/p/dart/issues/detail?id=10171 - Code Splitting in Dart
- https://code.google.com/p/dart/issues/detail?id=3940
- https://code.google.com/p/dart/issues/detail?id=9483

Update

I tried it and it works in Chrome (not in Dartium) with a few small changes

test.dart

library some_lib_name; // <== was missing

void init() {
  print("coucou");
}

index.dart

const lazy = const DeferredLibrary('some_lib_name'); // use the library name not the file name


来源:https://stackoverflow.com/questions/24827293/how-can-i-execute-two-dart-code-in-one-html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!