Flutter plugin for creating static & dynamic app/conversation shortcuts on home screen. Supports iOS android
Address of the original author, Adapt iOS based on this code
dependencies:
flutter_shortcut_plus: <latest version>
Run pub get and get packages.
Officially Supported Platforms/Implementations:
- Android
FlutterShortcut.initialize(debug: true);
FlutterShortcut.listenAction((String incomingAction) {
setState(() {
if (incomingAction != null) {
action = incomingAction;
}
});
});
Return the maximum number of static and dynamic shortcuts that each launcher icon can have at a time.
Officially Supported Platforms/Implementations:
- Android
int? result = await FlutterShortcut.getMaxShortcutLimit();
Flutter Shortcuts allows you to create shortcut icon from both android drawable
or mipmap
and flutter Assets.
- Android resources,
drawable
ormipmap
. - iOS resources , Assets.xcassets
use: ShortcutIconAsset.nativeAsset
ShortcutItem(
id: "2",
action: 'shortcut.messages',
shortLabel: 'Messages',
icon: "message",
shortcutIconAsset: ShortcutIconAsset.nativeAsset,
),
- If you want to create shortcut icon from flutter asset. (DEFAULT)
use: ShortcutIconAsset.flutterAsset
ShortcutItem(
id: "1",
action: 'shortcut.scan',
shortLabel: 'Scan code',
icon: 'assets/scan.png',
shortcutIconAsset: ShortcutIconAsset.flutterAsset,
),
Publishes the list of shortcuts. All existing shortcuts will be replaced.
FlutterShortcut.setShortcutItems(
shortcutItems: <ShortcutItem>[
const ShortcutItem(
id: "1",
action: 'shortcut.scan',
shortLabel: 'Scan code',
icon: 'assets/scan.png',
),
const ShortcutItem(
id: "2",
action: 'shortcut.messages',
shortLabel: 'Messages',
icon: "messages",
shortcutIconAsset: ShortcutIconAsset.nativeAsset,
),
],
),
Delete all dynamic shortcuts from the app.
FlutterShortcut.clearShortcutItems();
Push a new shortcut item. If there is already a dynamic or pinned shortcut with the same ID, the shortcut will be updated and pushed at the end of the shortcut list.
FlutterShortcut.pushShortcutItem(
shortcut: ShortcutItem(
id: "2",
action: 'shortcut.messages',
shortLabel: 'Messages',
icon: "messages",
shortcutIconAsset: ShortcutIconAsset.nativeAsset,
),
);