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

06. System Menu Coding: Part 1

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: 05. Create System Menus Next episode: 07. System Menu Coding: Part 2

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.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Android Studio

Now open up menus.dart. You will see a lot of empty methods. RiverPod is used to create the MenuProvider. This allows menus to access any other provider via the ref variable. There are two main methods: createMenus for the Mac and createWindowsMenus for Windows. Here you will build up your main menu system. You want a File, Edit, Todos, Find and Help menus. Most of these will just be empty menus that you can add functionality to later.

return [
  createFileMenu(),
  createEditMenu(),
];
}
setApplicationMenu([
  createWindowsFileMenu(),
  createWindowsEditMenu(),
]);
PlatformMenu createFileMenu() {
  return PlatformMenu(label: 'File', menus: [
    PlatformMenuItem(label: 'Import', onSelected: () => handleImport()),
    PlatformMenuItem(label: 'Export', onSelected: () => handleExport())
      PlatformMenuItemGroup(members: [
        PlatformMenuItem(
            label: 'Quit',
            onSelected: () => handleQuit(),
            shortcut: const SingleActivator(
                LogicalKeyboardKey.keyQ, meta: true))
      ])
  ]);
}
NativeSubmenu createWindowsFileMenu() {
  return NativeSubmenu(label: 'File', children: [
    NativeMenuItem(label: 'Import', onSelected: () => handleImport()),
    NativeMenuItem(label: 'Export', onSelected: () => handleExport())
    NativeMenuItem(
        label: 'Quit',
        onSelected: () => handleQuit(),
        shortcut:
            LogicalKeySet(LogicalKeyboardKey.meta, LogicalKeyboardKey.keyQ)),
  ]);
}
PlatformMenu createEditMenu() {
  return PlatformMenu(label: 'Edit', menus: [
    PlatformMenuItem(label: 'Cut', onSelected: () => handleCut()),
    PlatformMenuItem(label: 'Copy', onSelected: () => handleCopy()),
    PlatformMenuItem(label: 'Paste', onSelected: () => handlePaste())
  ]);
}
NativeSubmenu createWindowsEditMenu() {
  return NativeSubmenu(label: 'Edit', children: [
    NativeMenuItem(label: 'Cut', onSelected: () => handleCut()),
    NativeMenuItem(label: 'Copy', onSelected: () => handleCopy()),
    NativeMenuItem(label: 'Paste', onSelected: () => handlePaste())
  ]);
}