繁体   English   中英

没有顶级吸气剂 <className> 声明

[英]No top-level getter <className> declared

我在扩展flutter_gallery示例。

我尝试创建新的图库项目

new GalleryItem(
  title: 'Journal',
  subtitle: 'Example app coding',
  category: 'Apps',
  routeName: JournalDemo.routeName,
  buildRoute: (BuildContext context) => new JournalDemo()
),

并且我导入了import '../journal/journal_all.dart';

里面我有export 'journal_demo.dart';

JournalDemo类与ListDemo是同一类,我只更改了类名和状态名:

class JournalDemo extends StatefulWidget {
  JournalDemo({ Key key }) : super(key: key);

  static const String routeName = '/journal';

  @override
  JournalDemoState createState() => new JournalDemoState();
} 

class JournalDemoState extends State<JournalDemo> {
 .......

这是我得到的例外

I/flutter : ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter : The following NoSuchMethodError was thrown building GalleryApp(dirty; state: I/flutter : GalleryAppState(48280642)): I/flutter : No top-level getter 'JournalDemo' declared. I/flutter : NoSuchMethodError: method not found: 'JournalDemo' I/flutter : Receiver: top-level I/flutter : Arguments: [...] I/flutter : When the exception was thrown, this was the stack: I/flutter : #0 NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:184) I/flutter : #1 kAllGalleryItems (/Users/matej/IdeaProjects/flutter/journal/lib/gallery/item.dart:51) I/flutter : #2 kAllGalleryItems (/Users/matej/IdeaProjects/flutter/journal/lib/gallery/item.dart:45)

我应该改变什么?

谢谢

看起来您的代码中缺少导入或解析错误。 我建议按照上述海报之一进行flutter analyze检查。

No top-level getter 'JournalDemo' declared意味着它无法在全局范围内找到值JournalDemo 原因可能是因为它没有被导入,或者是由于在此错误之前存在解析错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM