No top-level getter <className> declared

3,728

This looks like you have either a missing import or a parse error in your code. I would recommend checking with flutter analyze as one of the posters above suggests.

No top-level getter 'JournalDemo' declared means that it cannot find the value JournalDemo in the global scope. Either because it's not imported, or because there is a parse error before this error.

Share:
3,728
Tree
Author by

Tree

Updated on December 01, 2022

Comments

  • Tree
    Tree over 1 year

    I am expanding on the flutter_gallery example.

    I try to create new Gallery Item

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

    and I imported import '../journal/journal_all.dart';

    Inside I have export 'journal_demo.dart';

    JournalDemo class is the same class as ListDemo, I only changed the class name and state name:

    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> {
     .......
    

    This is the exception I get

    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)

    What should I change?

    Thank you