Skip to content

Commit a5de071

Browse files
committed
Add keybinder
1 parent 7d58db1 commit a5de071

File tree

200 files changed

+6890
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+6890
-0
lines changed

crowdin.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ commit_message: '[ci skip]'
22
files:
33
- source: /packages/material_leap/lib/l10n/leap_en.arb
44
translation: /packages/material_leap/lib/l10n/leap_%osx_locale%.arb
5+
- source: /packages/keybinder/lib/l10n/keybinder_en.arb
6+
translation: /packages/keybinder/lib/l10n/keybinder_%osx_locale%.arb

packages/keybinder/.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.flutter-plugins-dependencies
30+
/build/
31+
/coverage/

packages/keybinder/.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "adc901062556672b4138e18a4dc62a4be8f4b3c2"
8+
channel: "[user-branch]"
9+
10+
project_type: package

packages/keybinder/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
* TODO: Describe initial release.

packages/keybinder/LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: Add your license here.

packages/keybinder/README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Keybinder
2+
3+
> A Flutter package to easily manage and record custom keyboard shortcuts.
4+
5+
## Features
6+
7+
- 🎹 Record custom key combinations
8+
- 💾 Abstract persistence (bring your own storage)
9+
- 🔄 Reactive updates with `ChangeNotifier`
10+
- 🌍 Localized UI
11+
- 🛠 Modular and easy to integrate
12+
13+
## Usage
14+
15+
### 1. Define your Intents
16+
17+
```dart
18+
class IncrementIntent extends Intent { const IncrementIntent(); }
19+
class DecrementIntent extends Intent { const DecrementIntent(); }
20+
```
21+
22+
### 2. Implement Persistence (Optional)
23+
24+
Implement `KeybinderStore` to save/load shortcuts.
25+
26+
```dart
27+
class MyStore implements KeybinderStore {
28+
@override
29+
Future<String?> load() async {
30+
// Load from shared_preferences, file, etc.
31+
return null;
32+
}
33+
34+
@override
35+
Future<void> save(String data) async {
36+
// Save to shared_preferences, file, etc.
37+
}
38+
}
39+
```
40+
41+
### 3. Initialize Keybinder
42+
43+
```dart
44+
final keybinder = Keybinder(
45+
definitions: [
46+
ShortcutDefinition(
47+
id: 'increment',
48+
displayName: 'Increment Counter',
49+
intentType: IncrementIntent,
50+
defaultActivator: const SingleActivator(LogicalKeyboardKey.arrowUp),
51+
),
52+
ShortcutDefinition(
53+
id: 'decrement',
54+
displayName: 'Decrement Counter',
55+
intentType: DecrementIntent,
56+
defaultActivator: const SingleActivator(LogicalKeyboardKey.arrowDown),
57+
),
58+
],
59+
store: MyStore(), // Optional
60+
);
61+
```
62+
63+
### 4. Use in your App
64+
65+
Wrap your app with `Shortcuts` and listen to `Keybinder`. Don't forget to add localizations!
66+
67+
```dart
68+
class MyApp extends StatelessWidget {
69+
@override
70+
Widget build(BuildContext context) {
71+
return ListenableBuilder(
72+
listenable: keybinder,
73+
builder: (context, child) {
74+
return MaterialApp(
75+
localizationsDelegates: KeybinderLocalizations.localizationsDelegates,
76+
supportedLocales: KeybinderLocalizations.supportedLocales,
77+
home: Shortcuts(
78+
shortcuts: keybinder.getShortcuts([
79+
const IncrementIntent(),
80+
const DecrementIntent(),
81+
]),
82+
child: Actions(
83+
actions: <Type, Action<Intent>>{
84+
IncrementIntent: CallbackAction<IncrementIntent>(onInvoke: (_) => print("Increment!")),
85+
DecrementIntent: CallbackAction<DecrementIntent>(onInvoke: (_) => print("Decrement!")),
86+
},
87+
child: HomePage(),
88+
),
89+
),
90+
);
91+
},
92+
);
93+
}
94+
}
95+
```
96+
97+
### 5. Record new keys
98+
99+
Use the `KeyRecorder` widget in your settings page.
100+
101+
```dart
102+
KeyRecorder(
103+
currentActivator: keybinder.getActivator(IncrementIntent),
104+
onNewKey: (newKey) => keybinder.updateBinding(IncrementIntent, newKey),
105+
)
106+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.build/
9+
.buildlog/
10+
.history
11+
.svn/
12+
.swiftpm/
13+
migrate_working_dir/
14+
15+
# IntelliJ related
16+
*.iml
17+
*.ipr
18+
*.iws
19+
.idea/
20+
21+
# The .vscode folder contains launch configuration and tasks you configure in
22+
# VS Code which you may wish to be included in version control, so this line
23+
# is commented out by default.
24+
#.vscode/
25+
26+
# Flutter/Dart/Pub related
27+
**/doc/api/
28+
**/ios/Flutter/.last_build_id
29+
.dart_tool/
30+
.flutter-plugins-dependencies
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
/coverage/
35+
36+
# Symbolication related
37+
app.*.symbols
38+
39+
# Obfuscation related
40+
app.*.map.json
41+
42+
# Android Studio will place build artifacts here
43+
/android/app/debug
44+
/android/app/profile
45+
/android/app/release
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "adc901062556672b4138e18a4dc62a4be8f4b3c2"
8+
channel: "[user-branch]"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
17+
base_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
18+
- platform: android
19+
create_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
20+
base_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
21+
- platform: ios
22+
create_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
23+
base_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
24+
- platform: linux
25+
create_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
26+
base_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
27+
- platform: macos
28+
create_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
29+
base_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
30+
- platform: web
31+
create_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
32+
base_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
33+
- platform: windows
34+
create_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
35+
base_revision: adc901062556672b4138e18a4dc62a4be8f4b3c2
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# keybinder_example
2+
3+
A new Flutter project.

0 commit comments

Comments
 (0)