【问题标题】:Dart simple webcomponent confusionDart 简单的 webcomponent 混淆
【发布时间】:2013-03-22 01:05:10
【问题描述】:

不知何故,我无法构建我的第一个 Dart Web 组件示例。该项目非常简单,取自Seth blog

首先build.dart 文件应该放在项目的根文件夹中(而不是在web/ 文件夹中)

代码如下:

Project
\--ui
    \-- test_component.html

          <!DOCTYPE html>
          <html lang="en">
           <body>
            <element name="x-click-counter" constructor="CounterComponent" extends="div">
            <template>
              <button on-click="increment()">Click me</button>
              <span>(click count: {{count}})</span>
            </template>
            <script type="application/dart" src="test_component.dart"></script>
            </element>
           <!-- more below... -->
          </body>
        </html>

     \-- test_component.dart

         library test_component;

         import 'package:web_ui/web_ui.dart';

         class CounterComponent extends WebComponent
         {
             int count = 0;
             void increment(e)
             {
                 count++;
             }
         }

 \-- web
      \-- index.html

          <!DOCTYPE html>
          <html lang="en">
          <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
            <link rel="components" href="ui/test_component.html">
            <title>Dart • TodoMVC</title>
          </head>
          <body>
            <x-click-counter></x-click-counter>
            <script type="application/dart">main() {}</script>
          </body>
         </html>

 \-- build.dart

     import 'dart:io';
     import 'packages/web_ui/component_build.dart';

     void main()
     {
          build(new Options().arguments, ['web/index.html']);
     }

就在我将build.dart 移动到根文件夹之后发生了奇怪的错误:

--- 00:51:50 01/04/2013 build.dart --machine --changed=web\index.html --- 文件:/C:/Projects/ProtonUiComponents/build.dart build.dart 返回错误代码 255

未捕获的错误:类“_File”没有具有匹配参数的实例方法“open”。

NoSuchMethodError:传递给名为“open”的方法的参数数量不正确 接收方:“_File@0x1da10ec4”的实例 尝试调用:open(模式:'FileMode'的实例) 找到:打开(模式) 堆栈跟踪:

#0      Object.noSuchMethod (dart:core-patch:1884:25)
#1      ConsoleFileSystem.writeString (file:///C:/Projects/ProtonUiComponents/packages/web_ui/src/file_system/console.dart:22:43)
#2      writeFile (file:///C:/Projects/ProtonUiComponents/packages/web_ui/dwc.dart:103:27)
#3      emitFiles.<anonymous closure> (file:///C:/Projects/ProtonUiComponents/packages/web_ui/dwc.dart:91:35)
#4      List.forEach (dart:core-patch:1219:8)
#5      emitFiles (file:///C:/Projects/ProtonUiComponents/packages/web_ui/dwc.dart:91:18)
#6      run.<anonymous closure>.<anonymous closure> (file:///C:/Projects/ProtonUiComponents/packages/web_ui/dwc.dart:85:29)
#7      _ThenFuture._sendValue (dart:async:463:24)
#8      _FutureImpl._setValue (dart:async:361:26)
#9      _FutureListenerWrapper._sendValue (dart:async:221:21)
#10     _FutureImpl._setValue (dart:async:361:26)
#11     _FutureImpl._setOrChainValue (dart:async:437:16)
#12     _ThenFuture._sendValue (dart:async:473:21)
#13     _FutureImpl._setValue (dart:async:361:26)
#14     _FutureListenerWrapper._sendValue (dart:async:221:21)
#15     _FutureImpl._setValue (dart:async:361:26)
#16     _FutureImpl._setOrChainValue (dart:async:437:16)
#17     _ThenFuture._sendValue (dart:async:473:21)
#18     _FutureImpl._setValue (dart:async:361:26)
#19     _CompleterImpl.complete (dart:async:190:21)
#20     _FutureImpl._FutureImpl.wait.<anonymous closure> (dart:async:273:29)
#21     _ThenFuture._sendValue (dart:async:463:24)
#22     _FutureImpl._setValue (dart:async:361:26)
#23     _CatchErrorFuture._sendValue (dart:async:485:14)
#24     _FutureImpl._setValue (dart:async:361:26)
#25     Stream.reduce.<anonymous closure> (dart:async:699:23)

如果我手动运行build.dart,我会收到dwc.dart 中的错误:

type 'ConsoleFileSystem' is not a subtype of type 'FileSystem' of 'fileSystem'.

那么 index.html 根本无法运行(既不是在 Dartium 也不是在 Javascript 中)出现 Dart 编辑器错误:

我做错了什么?

更新:

  • 我在 Windows 7 x64 上运行
  • Dart 编辑器版本 0.4.2_r20259
  • Dart SDK 版本 0.4.2.8_r20259

【问题讨论】:

  • 你使用什么版本的 Dart 编辑器?我的第一个猜测是版本不匹配(编辑器版本太旧或类似)。
  • Dart-Editor 的当前版本是 20602 (dartlang.org/docs/editor)。请尝试升级,看看错误是否仍然存在。据我在您的屏幕截图中看到的,“发送反馈”按钮旁边有一个绿色箭头。所以也应该有一个可用的自动更新。
  • @FlorianLoitsch - 是的!那是帮助!现在它编译了 :) 请将您的评论添加为“答案”,以便我可以将其作为该问题的“答案”进行检查

标签: dart dart-webui dart-editor


【解决方案1】:

当前的编辑器版本(截至 2013 年 4 月 1 日)是 20602。更新到最新版本应该可以修复它。

http://dartlang.org/docs/editor

【讨论】:

    猜你喜欢
    • 2013-06-01
    • 1970-01-01
    • 2012-01-02
    • 1970-01-01
    • 2013-03-26
    • 2013-04-12
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    相关资源
    最近更新 更多