Flutter Desktop Apps: Getting Started

Mar 28 2023 · Dart 2.19, Flutter 3.7, Android Studio 2021.3.1 or higher, Visual Studo Code 1.7.4 or higher

Part 1: Flutter Desktop Apps

07. System Menu Coding: Part 2

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. System Menu Coding: Part 1 Next episode: 08. Challenge: Add Delete List Menu

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 07. System Menu Coding: Part 2

Android Studio

Now that you have the first two menus implemented, you will create the last three. First, let’s add the methods to the menu creation methods:

in createMenus add:

createTodosMenu(),
createFindMenu(),
createHelpMenu()

and in createWindowsMenus add:

createWindowsTodosMenu(),
createWindowsFindMenu(),
createWindowsHelpMenu()

Now, create the Todo menu:

PlatformMenu createTodosMenu() {
  return PlatformMenu(label: 'Todos', menus: [
    PlatformMenu(label: 'New', menus: [
      PlatformMenuItem(label: 'List', onSelected: () => newList()),
      PlatformMenuItem(label: 'Category', onSelected: () => newCategory()),
      PlatformMenuItem(label: 'Todo', onSelected: () => newTodo()),
    ]),
    PlatformMenu(label: 'Delete', menus: [
      PlatformMenuItem(label: 'List', onSelected: () => deleteList()),
      PlatformMenuItem(label: 'Category', onSelected: () => deleteCategory()),
      PlatformMenuItem(label: 'Todo', onSelected: () => deleteTodo()),
    ])
  ]);
}

Now the Windows version:

NativeSubmenu createWindowsTodosMenu() {
  return NativeSubmenu(label: 'Todos', children: [
    NativeSubmenu(label: 'New', children: [
      NativeMenuItem(label: 'List', onSelected: () => newList()),
      NativeMenuItem(label: 'Category', onSelected: () => newCategory()),
      NativeMenuItem(label: 'Todo', onSelected: () => newTodo()),
    ]),
    NativeSubmenu(label: 'Delete', children: [
      NativeMenuItem(label: 'List', onSelected: () => deleteList()),
      NativeMenuItem(label: 'Category', onSelected: () => deleteCategory()),
      NativeMenuItem(label: 'Todo', onSelected: () => deleteTodo()),
    ])
  ]);
}

This will create a menu with several sub-menus. The Todo menu will have a new menu which has a list, category and todo items. Only newList has any real functionality. The others are challenge items for you to try and implement.

Next go to createTodosMenu and add the find menu:

PlatformMenu createFindMenu() {
  return PlatformMenu(label: 'Find', menus: [
    PlatformMenuItem(label: 'Search', onSelected: () => handleSearch()),
    PlatformMenuItem(label: 'Next', onSelected: () => handleNext()),
    PlatformMenuItem(label: 'Previous', onSelected: () => handlePrevious())
  ]);
}

Now the Windows version:

NativeSubmenu createWindowsFindMenu() {
  return NativeSubmenu(label: 'Find', children: [
    NativeMenuItem(label: 'Search', onSelected: () => handleSearch()),
    NativeMenuItem(label: 'Next', onSelected: () => handleNext()),
    NativeMenuItem(label: 'Previous', onSelected: () => handlePrevious())
  ]);
}

This provides the ablitity to handle searches.

Finally, go to createHelpMenu and create the help menu:

PlatformMenu createHelpMenu() {
  return PlatformMenu(
      label: 'Help',
      menus: [PlatformMenuItem(label: 'Help', onSelected: () => handleHelp())]);
}

Now the Windows version:

NativeSubmenu createWindowsHelpMenu() {
  return NativeSubmenu(label: 'Help', children: [
    NativeMenuItem(label: 'Help', onSelected: () => handleHelp())
  ]);
}

Here, you can provide any help you want for the app. Stop and rerun the app and make sure all of these menus exist. If you try and execute any of these menus, nothing will happen. There is one menu item that works. Do you know which one?

Try selecting the New List menu. Here, a dialog comes up with an entry for the name of a new list. Once we type in the name, a new todo list will appear. Try entering in new categories and todos on this screen.

The other menus have been left as an exercise for you. How would handle these? How do you deal with the lack of a BuildContext class?

In our next episode you will implement the deletelist menu as a challenge.