After completing the environment setup, we can start creating our hotkey application project. This chapter will guide you through the project creation and basic configuration.
Create Flutter Project
Open terminal, navigate to your desired project directory, and execute the following commands:
Terminal window flutter create hotkey_appcd hotkey_appEnable macOS support:
Terminal window flutter create . --platforms=macos
Configure Project
Open
pubspec.yamlfile and add necessary dependencies:dependencies:flutter:sdk: flutterwindow_manager: ^0.3.7hotkey_manager: ^0.1.8shared_preferences: ^2.2.2Install dependencies:
Terminal window flutter pub get
Configure macOS Permissions
Open
macos/Runner/DebugProfile.entitlementsfile and add the following permissions:<dict><!-- Other existing configurations --><key>com.apple.security.temporary-exception.apple-events</key><string>com.apple.systemevents</string></dict>Add the same configuration to
macos/Runner/Release.entitlements.
Clean Default Code
Open
lib/main.dartand remove the default counter example code.Create the basic application structure:
import 'package:flutter/material.dart';import 'package:window_manager/window_manager.dart';import 'package:hotkey_manager/hotkey_manager.dart';void main() async {WidgetsFlutterBinding.ensureInitialized();// Initialize window managerawait windowManager.ensureInitialized();// Initialize hotkey managerawait hotKeyManager.unregisterAll();runApp(const MyApp());}class MyApp extends StatelessWidget {const MyApp({super.key});@overrideWidget build(BuildContext context) {return MaterialApp(title: 'Hotkey App',theme: ThemeData(primarySwatch: Colors.blue,useMaterial3: true,),home: const MyHomePage(),);}}class MyHomePage extends StatefulWidget {const MyHomePage({super.key});@overrideState<MyHomePage> createState() => _MyHomePageState();}class _MyHomePageState extends State<MyHomePage> {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text('Hotkey App'),),body: const Center(child: Text('Welcome to Hotkey App!'),),);}}
Run Project
Ensure macOS platform is enabled:
Terminal window flutter devicesRun the project:
Terminal window flutter run -d macos
Common Issues
Dependency Installation Failure
- Check network connection
- Ensure Flutter SDK version compatibility
- Try using mirror sources
macOS Permission Issues
- Ensure entitlements files are correctly configured
- Check Xcode project settings
Runtime Errors
- Check Flutter and Dart SDK versions
- Ensure all dependencies are properly installed
- Review console error messages
Next Step
Now that we have created the basic project structure, we will learn how to control the application window behavior in the Window Management chapter.
