gpt4 book ai didi

dart - 现在,使用CoreScaffold和CoreTabs类会导致异常

转载 作者:行者123 更新时间:2023-12-03 03:45:21 28 4
gpt4 key购买 nike

我有一个称为main-app的聚合物元素:



    <link rel="import" href="../../packages/polymer/polymer.html">

<link rel="import" href="../../packages/paper_elements/paper_input.html">
<link rel="import" href="../../packages/paper_elements/paper_input.html">
<link rel="import" href="../../packages/paper_elements/paper_tabs.html">
<link rel="import" href="../../packages/paper_elements/paper_dialog.html">
<link rel="import" href="../../packages/paper_elements/paper_icon_button.html">
<link rel="import" href="../../packages/core_elements/core_toolbar.html">
<link rel="import" href="../../packages/core_elements/core_scaffold.html">
<link rel="import" href="../../packages/core_elements/core_header_panel.html">
<link rel="import" href="../../packages/core_elements/core_menu.html">
<link rel="import" href="../../packages/core_elements/core_item.html">
<link rel="import" href="../../packages/paper_elements/paper_input.html">
<link rel="import" href="../../packages/paper_elements/paper_button.html">
<link rel="import" href="../../packages/paper_elements/paper_dialog.html">
<link rel="import" href="../../packages/core_elements/core_scaffold.html">
<link rel="import" href="../../packages/core_elements/core_pages.html">

<polymer-element name="main-app" class="dark-primary-color">
<template>
<style type="text/css">
:host {
display: block;
}
</style>
<core-scaffold>

<core-header-panel id="menu-panel" navigation flex>

<core-toolbar id="navheader">
<span>Menu</span>
</core-toolbar>
<core-menu>
<core-item label="Home" on-click="{{homeClicked}}"></core-item>
<core-item label="About Us" on-click="{{aboutClicked}}"></core-item>
<core-item label="Contact Us" on-click="{{contactClicked}}"></core-item>
</core-menu>
</core-header-panel>

<span tool>{{title}}</span>
<paper-tabs class="main-menu bottom fit" selected="0">
<paper-tab on-click="{{homeClicked}}">Home</paper-tab>
<paper-tab on-click="{{aboutClicked}}">About Us</paper-tab>
<paper-tab on-click="{{contactClicked}}">Contact Us</paper-tab>
</paper-tabs>
<div class="content" forceNarrow>
<p>Lorem ipsum ...</p>
</div>

...
</core-scaffold>
</template>
<script type="application/dart" src="main-app.dart"></script>
</polymer-element>

main-app.dart:

import 'package:polymer/polymer.dart';
import 'util/util.dart';
import 'event/event.dart';

import 'dart:html';

import 'page/home-page.dart';
import 'page/about-page.dart';
import 'page/contact-page.dart';

@CustomTag('main-app')
class MainApp extends PolymerElement {

@observable String page = "home";
@observable String title = "Home";

MainApp.created() : super.created();

...

homeClicked(event, detail, target) {
CoreScaffold e = shadowRoot.querySelector('core-scaffold');
e.doSomething <<-- fails
...
}

...

}

这是我得到的异常(exception):

Exception: 'package:falm/main-app.dart': malformed type: line 73 pos 5: type 'CoreScaffold' is not loaded
CoreScaffold e = shadowRoot.querySelector('core-scaffold');
^
type 'CoreScaffold' is not a subtype of type 'malformed' of 'e'.

为了摆脱异常,我现在必须做:

  homeClicked(event, detail, target) {
Element e = shadowRoot.querySelector('core-scaffold');
e.doSomething <<-- works
...
}

失败的代码在昨天早晨进行 Dart 更新之前一直有效(不确定在更新完整的pub,进行pub缓存修复和pub下载之前完全重新安装SDK时是从哪个版本更新的),PaperTabs在做同样的事情。

这是否意味着我不能再在Dart代码中使用CoreElement和PaperTabs类?

更新:这是来自pubspec.lock的相关内容:

core_elements:
description: core_elements
source: hosted
version: "0.6.0+4"
paper_elements:
description: paper_elements
source: hosted
version: "0.6.0+4"
polymer:
description: polymer
source: hosted
version: "0.15.5"
polymer_expressions:
description: polymer_expressions
source: hosted
version: "0.13.0+1"
web_components:
description: web_components
source: hosted
version: "0.10.1"

最佳答案

您需要导入定义了类的库。

import 'package:core_elements/core_scaffold.dart'; 
import 'package:paper_elements/paper_tabs.dart';

已选中/未选中

命令行运行Dart脚本时,默认为生产模式(未选中模式)。 dart bin/somescript.dart,或明确设置为 dart -c bin/somescript.dart时的检查模式。

启动Dart脚本或Web应用程序时,DartEditor 默认为选中模式。 DartEditor允许(停用) Run in checked mode中的 Manage Launches(运行配置)。

我假设 Dart插件中有Eclipse 的类似设置(请勿自己使用)。

WebStorm 允许在 Run > Edit Configurations ...中为命令行应用程序设置它。对于Web应用程序,您可以创建一个新的浏览器配置,并在 --checked中添加 Command line options

我认为它与 IntelliJ IDEA 类似,但我自己尚未使用过。

另请参阅 https://stackoverflow.com/a/21658630/217408

关于dart - 现在,使用CoreScaffold和CoreTabs类会导致异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28163853/

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