我试图听一个按钮单击工具栏上的按钮,当单击该按钮时,该按钮会切换drawer_panel的主抽屉,但没有太大成功。
代码如下所示 - 方法 void menu_icon_handler() 中的代码不正确。
<!DOCTYPE html>
<link rel="import" href="../../../packages/polymer/polymer.html">
<link rel="import" href="../../../packages/core_elements/core_drawer_panel.html">
<link rel="import" href="../../../packages/core_elements/core_icon_button.html">
<link rel="import" href="../../../packages/core_elements/core_toolbar.html">
<link rel="import" href="../../../packages/paper_elements/roboto.html">
<link rel="import" href="../../../packages/core_elements/core_toolbar.html">
<link rel="import" href="../../../packages/paper_elements/paper_icon_button.html">
<link rel="import" href="./reg/registrant-view.html">
<link rel="import" href="./reg/patient-view.html">
<link rel="import" href="drawer-form.html">
<polymer-element name="main-form">
<template>
<core-drawer-panel id="core_drawer_panel">
<section id="drawer" drawer>
<drawer-form on-new-patient-event='{{newPatientHandler}}'></drawer-form>
</section>
<section id="main" main>
<core-toolbar id="core_toolbar">
<paper-icon-button
icon="menu"
id='menu_icon'
on-click='{{menu_icon_handler}}'></paper-icon-button>
<div id="div" flex>Toolbar</div>
</core-toolbar>
<section id='new-patient'>
</section>
</section>
</core-drawer-panel>
</template>
<script type="application/dart">
import 'package:polymer/polymer.dart';
import 'dart:html';
import 'package:core_elements/core_drawer_panel.dart';
@CustomTag( 'main-form' )
class MainForm extends PolymerElement
{
CoreDrawerPanel drawerPanel;
MainForm.created() : super.created();
void toggleDrawer()
{
bool state = drawerPanel.narrow;
}
void menu_icon_handler()
{
bool state = drawerPanel.narrow;
print ( state );
}
@override
void attached()
{
super.attached();
drawerPanel = $['drawerPanel'] as CoreDrawerPanel;
}
}
</script>
</polymer-element>
单击工具栏按钮时,我得到以下堆栈跟踪
例外:空对象没有 getter 'narrow'。
NoSuchMethodError: method not found: 'narrow'
Receiver: null
我看到空值,查看文档“窄”是 CoreDrawerPanel 的一个属性