DEV Community

Cover image for Modern Way to Launch Flutter Desktop Apps on Boot
Codexlancers
Codexlancers

Posted on

Modern Way to Launch Flutter Desktop Apps on Boot

Imagine building a brilliant productivity tool, a system monitor, or a sleek menu bar utility in Flutter, only for users to forget to open it. If your desktop application relies on seamless, background availability, integrating a "Launch at Startup" feature is essential.

While doing this natively requires writing platform-specific code (C++ for Windows, Swift for macOS, and C for Linux), the Flutter ecosystem has a fantastic package that handles the heavy lifting: launch_at_startup.

Why Launch at Startup?

Auto-launching your application can be useful for:

  • Background utilities
  • Productivity applications
  • Communication tools
  • System monitoring software
  • Menu bar or tray applications

Instead of asking users to manually open the app every time they restart their computer, your application can automatically start when the operating system launches.

Adding the Package

First, add the latest version of launch_at_startup and the package_info_plus package (which is highly recommended for dynamically fetching your app's name and executable path) to your pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  launch_at_startup: ^0.2.2 # Use the latest version
  package_info_plus: ^8.0.0
Enter fullscreen mode Exit fullscreen mode

Run flutter pub get in your terminal to fetch the packages.

Initialize launch_at_startup

Before enabling startup launch, initialize the package with your application details.

import 'dart:io';

import 'package:launch_at_startup/launch_at_startup.dart';
import 'package:package_info_plus/package_info_plus.dart';

Future<void> main() async {
  final packageInfo = await PackageInfo.fromPlatform();

  launchAtStartup.setup(
    appName: packageInfo.appName,
    appPath: Platform.resolvedExecutable,
    // Required when using MSIX packaging on Windows
    packageName: 'com.app.startup_launch',
  );

  runApp(const MyApp());
}
Enter fullscreen mode Exit fullscreen mode

Platform.resolvedExecutable automatically provides the correct executable path for the running app.

Check Current Status

Before enabling or disabling startup behavior, you may want to check whether it is already enabled.

final isEnabled = await launchAtStartup.isEnabled();
print('Launch at startup: $isEnabled');
Enter fullscreen mode Exit fullscreen mode

This is useful for displaying the current state in your settings screen.

Enable Auto Launch

To register the application for startup:

await launchAtStartup.enable();
Enter fullscreen mode Exit fullscreen mode

Disable Auto Launch

If the user decides to turn off the feature:

await launchAtStartup.disable();
Enter fullscreen mode Exit fullscreen mode

Creating a Settings Toggle

A common implementation is providing a switch in your app settings.

final isStartupEnabled = await launchAtStartup.isEnabled();

SwitchListTile(
  title: const Text('Launch at Startup'),
  value: isStartupEnabled,
  onChanged: (value) async {
    if (value) {
      await launchAtStartup.enable();
    } else {
      await launchAtStartup.disable();
    }
    setState(() => isStartupEnabled = value);
  },
)
Enter fullscreen mode Exit fullscreen mode

This gives users full control over the startup behavior.

Supported Platforms

The package currently supports:

  • Windows
  • macOS
  • Linux

Make sure to test the functionality on your target operating system before releasing your application.

Things to Keep in Mind

  • Auto-start should be optional whenever possible.
  • Always provide users with a way to disable it.
  • Consider combining startup launch with system tray support for a better desktop experience.
  • Test both debug and release builds, as startup behavior is typically used in production environments.

Final Thoughts

Adding startup launch support is a small feature that can significantly improve the desktop user experience. With the launch_at_startup package, Flutter developers can implement this functionality with just a few lines of code across Windows, macOS, and Linux.

If you're building a desktop utility, communication tool, or productivity application, enabling auto-launch can make your app feel much more professional and convenient for users.

Top comments (0)