diff --git a/README.md b/README.md index d23bb43..59d6c00 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,25 @@ ## Show some :heart: and :star: the repo -[![GitHub followers](https://img.shields.io/github/followers/divshekhar.svg?style=social&label=Follow)](https://github.com/divshekhar/) +## Why use Flutter Shortcuts? + +Flutter Shortcuts Plugin is known for : + +| Flutter Shortcuts | +| :--------------------------------- | +| Fast, performant & compatible | +| Free & Open-source | +| Production ready | +| Make App Reactive | + +## Features + +All the features listed below can be performed at the runtime. + +✅   Create Shortcuts
+✅   Clear Shortcuts
+✅   Update Shortcuts
+✅   Use both flutter and android asset as shortcut icon
## Demo @@ -30,7 +48,9 @@ Run pub get and get packages. final FlutterShortcuts flutterShortcuts = FlutterShortcuts(); ``` -### Step 3: Initialize Flutter Shortcuts +## Example + +### Define Shortcut Action ```dart flutterShortcuts.initialize((String incomingAction) { @@ -42,21 +62,179 @@ flutterShortcuts.initialize((String incomingAction) { }); ``` -## Arguments +### Get Max Shortcut Limit + +Return the maximum number of static and dynamic shortcuts that each launcher icon can have at a time. + +```dart +int? result = await flutterShortcuts.getMaxShortcutLimit(); +``` + +### Shortcut Icon Asset + +Flutter Shortcuts allows you to create shortcut icon from both android `drawable` or `mipmap` and flutter Assets. + +* If you want to use icon from Android resources, `drawable` or `mipmap`. + +use: `ShortcutIconAsset.androidAsset` + +```dart +FlutterShortcutItem( + id: "2", + action: 'Bookmark page action', + shortLabel: 'Bookmark Page', + icon: "ic_launcher", + shortcutIconAsset: ShortcutIconAsset.androidAsset, +), +``` + +* If you want to create shortcut icon from flutter asset. (DEFAULT) + +use: `ShortcutIconAsset.flutterAsset` + +```dart +FlutterShortcutItem( + id: "2", + action: 'Bookmark page action', + shortLabel: 'Bookmark Page', + icon: 'assets/icons/bookmark.png', + shortcutIconAsset: ShortcutIconAsset.flutterAsset, +), +``` + +### Set shortcut items + +Publishes the list of shortcuts. All existing shortcuts will be replaced. + +```dart +flutterShortcuts.setShortcutItems( + shortcutItems: [ + const FlutterShortcutItem( + id: "1", + action: 'Home page action', + shortLabel: 'Home Page', + icon: 'assets/icons/home.png', + ), + const FlutterShortcutItem( + id: "2", + action: 'Bookmark page action', + shortLabel: 'Bookmark Page', + icon: "ic_launcher", + shortcutIconAsset: ShortcutIconAsset.androidAsset, + ), + ], +), +``` + +### Clear shortcut item + +Delete all dynamic shortcuts from the app. + +```dart +flutterShortcuts.clearShortcutItems(); +``` + +### Push Shortcut Item + +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. + +```dart +flutterShortcuts.pushShortcutItem( + shortcut: FlutterShortcutItem( + id: "5", + action: "Play Music Action", + shortLabel: "Play Music", + icon: 'assets/icons/music.png', + ), +); +``` + +### Push Shortcut Items + +Pushes a list of 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. + +```dart +flutterShortcuts.pushShortcutItems( + shortcutList: [ + const FlutterShortcutItem( + id: "1", + action: 'Home page new action', + shortLabel: 'Home Page', + icon: 'assets/icons/home.png', + ), + const FlutterShortcutItem( + id: "2", + action: 'Bookmark page new action', + shortLabel: 'Bookmark Page', + icon: 'assets/icons/bookmark.png', + ), + const FlutterShortcutItem( + id: "3", + action: 'Settings Action', + shortLabel: 'Setting', + icon: 'assets/icons/settings.png', + ), + ], +); +``` + +### Update Shortcut Item -There are several function that allow for more control: +Updates a single shortcut item based on id. If the ID of the shortcut is not same, no changes will be reflected. -| Properties | Description | -|--------------|-----------------| -| `initialize` | performs action when shortcut is initiated.| -| `getMaxShortcutLimit` | returns the maximum number of static or dynamic shortcuts that each launcher icon can have at a time. | -| `setShortcutItems` | will set all the shortcut items. | -| `clearShortcutItems` | will remove all the shortcut items.| -| `pushShortcutItem` | will 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. | -| `addShortcutItems` |updates dynamic or pinned shortcuts with same IDs and pushes new shortcuts with different IDs. | -| `updateShortcutItems` | updates shortcut items. If the IDs of the shortcuts are not same, no changes will be reflected. | -| `updateShortcutItem` | updates a single shortcut item based on id. If the ID of the shortcut is not same, no changes will be reflected. | -| `changeShortcutItemIcon` | will change the icon of the shortcut based on id.s If the ID of the shortcut is not same, no changes will be reflected. | +```dart +flutterShortcuts.updateShortcutItem( + shortcut: FlutterShortcutItem( + id: "1", + action: 'Go to url action', + shortLabel: 'Visit Page', + icon: 'assets/icons/url.png', + ), +); +``` + +### Update Shortcut Items + + Updates shortcut items. If the IDs of the shortcuts are not same, no changes will be reflected. + + ```dart +flutterShortcuts.updateShortcutItems( + shortcutList: [ + const FlutterShortcutItem( + id: "1", + action: 'Resume playing Action', + shortLabel: 'Resume playing', + icon: 'assets/icons/play.png', + ), + const FlutterShortcutItem( + id: "2", + action: 'Search Songs Action', + shortLabel: 'Search Songs', + icon: 'assets/icons/search.png', + ), + ], +); + ``` + +### Change Shortcut Item Icon + +Change the icon of the shortcut based on id. If the ID of the shortcut is not same, no changes will be reflected. + +```dart +flutterShortcuts.changeShortcutItemIcon( + id: "2", + icon: "assets/icons/next.png", +); +``` + +### Get shortcut icon properties + +Get the icon properties of your shortcut icon. + +```dart +Map result = await flutterShortcuts.getIconProperties(); +print( "maxHeight: ${result["maxHeight"]}, maxWidth: ${result["maxWidth"]}"); +``` ## Project Created & Maintained By @@ -64,10 +242,35 @@ There are several function that allow for more control: +[![GitHub followers](https://img.shields.io/github/followers/divshekhar.svg?style=social&label=Follow)](https://github.com/divshekhar/) + ### Subham Praharaj +[![GitHub followers](https://img.shields.io/github/followers/thechamp865-skp.svg?style=social&label=Follow)](https://github.com/thechamp865-skp/) + +## Contributions + +Contributions are welcomed! + +If you feel that a hook is missing, feel free to open a pull-request. + +For a custom-hook to be merged, you will need to do the following: + +Describe the use-case. + +* Open an issue explaining why we need this hook, how to use it, ... + This is important as a hook will not get merged if the hook doens't appeal to + a large number of people. + +* If your hook is rejected, don't worry! A rejection doesn't mean that it won't + be merged later in the future if more people shows an interest in it. + In the mean-time, feel free to publish your hook as a package on https://pub.dev. + +* A hook will not be merged unles fully tested, to avoid breaking it inadvertendly + in the future. + ## Copyright & License Code and documentation Copyright (c) 2021 [Divyanshu Shekhar](https://divyanshushekhar.com). Code released under the [BSD 3-Clause License](./LICENSE). \ No newline at end of file diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index e59aebf..85dcb0e 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -5,7 +5,6 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_shortcuts_example/main.dart';