gpt4 book ai didi

dart - 如何使用 main() 构造一个最小的 Dart Polymer 应用程序

转载 作者:行者123 更新时间:2023-12-04 18:24:57 25 4
gpt4 key购买 nike

Dart 编辑器目前只支持一个 dart polymer (/file) 新项目生成选项。这个选项在没有 main() 的/web 子目录中设置了 4 个文件,并且到达一个 main 需要一些对我来说并不完全明显的样板更改。

我在 Dart 论坛上得到了 Guenter Zoeckbauer 的帮助,解决了这个有点“howto”的问题,所以我想分享对这个不错的最小项目的那些最小更改的结果,它为我提供了重新开始所需的确切起点-基于我过时的代码和文件结构。

在我看来,它为重新构建已经过时的应用程序提供了良好的起点引用,这些应用程序在过去几个月中进行了所有快速且重要的更改。

最佳答案

这是必须修改的 6 个文件(应用程序名称是:app_with_main):

1 app_with_main.css 无变化

2 clickcounter.dart 无变化

3 clickcounter.html 无变化

4 索引.html:

<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sample app</title>
<!-- <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>

<link rel="import" href="clickcounter.html">

<!-- ORIGINAL SCRIPT
<script type="application/dart">export 'package:polymer/init.dart';</script>
<script src="packages/browser/dart.js"></script>
-->

<link rel="stylesheet" href="app_with_main.css">
</head>
<body>
<h1>App with main</h1>

<p>Hello world from Dart!</p>

<div id="sample_container_id">
<click-counter count="5"></click-counter>
</div>

<script type="application/dart">export 'init.dart';</script>

</body>
</html>

#5。 init.dart(新)

导入 "package:polymer/polymer.dart";

main() {

print("always before polymer initialization is complete");

initPolymer().run(() {

print('''Code here will be called almost immediately and cannot rely
on the polymer elements being instantiated.''');

Polymer.onReady.then((_) {

print('''at this point the onReady callback has been returned and thus the polymer
initialization process will be complete''');

});
});

6 必须修改项目 yaml 文件以将 entry_point 设置为 index.html 因此:

name: app_with_main
description: A sample Polymer application
dependencies:
polymer: ">=0.11.0-dev.2 <0.12.0"
transformers:
- polymer:
entry_points: web/index.html

而且应该做到这一点,您应该关闭并运行一个可以随着您的项目长期增长的代码结构....

再次感谢 Dart super 英雄 Guenter Zoecchbauer!

关于dart - 如何使用 main() 构造一个最小的 Dart Polymer 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24544708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com