我想在应用程序中使用polymer 实现一个主要功能.

我try 在DART文件中实现主函数,其中实现了polymer 代码. 不执行该代码.

不允许在主函数中包含第二个DART脚本-

我的错误在哪里? TNX云母.

推荐答案

index.html

 <head>
   <!-- <link rel="import" href="packages/polymer/polymer.html"> not necessary anymore (only in elements)-->
   <!-- <script src="packages/web_components/platform.js"></script>
        not necessary anymore with Polymer >= 0.14.0 -->
   <!-- <script src="packages/web_components/dart_support.js"></script> 
        not necessary anymore with Polymer >= 0.15.0 -->

   <!-- old -->
   <script type="application/dart">
      export 'package:polymer/init.dart';</script> 

   <!-- new  -->
   <script type="application/dart">export 'index.dart';</script>
 </head>
 <body>
   ...
   <!-- ... when you use a custom main method (see https://code.google.com/p/dart/issues/detail?id=17546#c16) -->
   <script type="application/dart" src="index.dart"></script>
 </body>

index.dart

Polymer 0.17.0(Polymer.js 1.0)

main() async {
  await initPolymer();
  // Any other code here.
}

Before Polymer 0.17.0

polymer 0.16.1引入了更简单的初始化方式. 使用带有@whenPolymerReady注释方法而不是main()

// >= Polymer 0.16.1
import 'package:polymer/polymer.dart';
export 'package:polymer/init.dart';

@whenPolymerReady
void onReady() {
  /// Custom setup code here.
}

Before Polymer.dart 0.16.1

// >= Polymer 0.16.0
import "package:polymer/polymer.dart";

main() {
  initPolymer().then((zone) => zone.run(() {
    // code here works most of the time
    Polymer.onReady.then((_) {     
      // some things must wait until onReady callback is called
      // for an example look at the discussion linked below
    });
  }));
}

有关更多详细信息,请查看Polmer 0.16.0的更改日志(log),地址为 https://pub.dartlang.org/packages/polymer

Before Polymer 0.16.0

// < Polymer 0.16.0    
import "package:polymer/polymer.dart";

main() {
  initPolymer().run(() {
    // code here works most of the time
    Polymer.onReady.then((_) {     
      // some things must wait until onReady callback is called
      // for an example look at the discussion linked below
    });
  });
}

simple tooltip working in dartium, not as javascript

Dart相关问答推荐

如何在将构造函数参数赋给最终变量和传递给超级构造函数之前操作它?

Flutter Getx - 未找到Xxx.您需要调用Get.put(Xxx()) - 但我已调用 Get.put(Xxx())

Flutter Web:无法用鼠标向下滚动(drag)(Flutter 2.5+)

Asset图像作为Card背景,Flutter 中顶部有文本

从 Future 实例中获取值

如何在没有 Scaffold.drawer 的情况下使用 Drawer?

如何使用文本小部件设置多行文本?

Dart 捕获 http 异常

自定义声音推送通知不起作用

表单的 TextFormField 中的多个光标(cursor)

Flutter中图像纵横比的变化

在小部件构建期间,如何在Flutter中导航?

Flutter 在整个屏幕上禁用touch

单击 TextField 小部件时 Flutter 小部件重建

Dart 后期初始化final变量

从dart语言列表中过滤空值的最佳方法是什么

用于 dartlang 的 REPL

Dart 会支持服务器端开发吗?

如何在 Dart SDK 0.4+ 中使用 setInterval/setTimeout

Dart 语言中的 Console.log