pinned_shortcuts 0.0.1
pinned_shortcuts: ^0.0.1 copied to clipboard
A Flutter plugin for creating and managing Android pinned shortcuts with support for various image types.
Flutter Pinned Shortcuts ๐ #
โจ A Flutter plugin that lets you create Android pinned shortcuts with style! Pin your app's most important features directly to the user's home screen.
โ Features #
- ๐ฑ Create pinned shortcuts on Android home screens
- ๐ผ๏ธ Support for various image sources:
- ๐ฆ Flutter assets
- ๐ค Android resources
- ๐ Network images (auto-downloaded)
- ๐ File paths
- ๐ Support for adaptive icons
- ๐ Listen to shortcut clicks in Flutter
- ๐ Check if a shortcut is pinned
๐ Getting Started #
๐ฅ Installation #
Add this to your package's pubspec.yaml
file:
dependencies:
pinned_shortcuts: any
Then run:
$ flutter pub get
๐ฑ Android Setup #
Ensure your minSdkVersion
is at least 16 (Android 4.1) in your app's android/app/build.gradle
file:
android {
defaultConfig {
minSdkVersion 16
// ...
}
}
For optimal functionality, Android 8.0 (API level 26) or higher is recommended.
๐ป Usage #
๐ Initialize the plugin #
First, initialize the plugin (typically in your main.dart
):
import 'package:pinned_shortcuts/pinned_shortcuts.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the plugin
await FlutterPinnedShortcuts.initialize();
runApp(MyApp());
}
โ Check if pinned shortcuts are supported #
bool isSupported = await FlutterPinnedShortcuts.isSupported();
if (isSupported) {
print('๐ Pinned shortcuts are supported!');
} else {
print('๐ Pinned shortcuts are not supported on this device');
}
๐ Create a pinned shortcut #
With a Flutter asset image
await FlutterPinnedShortcuts.createPinnedShortcut(
id: 'asset_shortcut',
label: 'My Shortcut',
imageSource: 'assets/icon.png',
imageSourceType: ImageSourceType.asset,
longLabel: 'My Flutter Asset Shortcut', // Optional
extraData: {'source': 'asset'}, // Optional data to pass when shortcut is clicked
);
With an Android resource image
await FlutterPinnedShortcuts.createPinnedShortcut(
id: 'resource_shortcut',
label: 'Resource Shortcut',
imageSource: 'ic_launcher', // drawable asset name
imageSourceType: ImageSourceType.resource,
);
With a network image
await FlutterPinnedShortcuts.createPinnedShortcut(
id: 'network_shortcut',
label: 'Network Shortcut',
imageSource: 'https://example.com/image.png',
imageSourceType: ImageSourceType.network,
);
With a file path
await FlutterPinnedShortcuts.createPinnedShortcut(
id: 'file_shortcut',
label: 'File Shortcut',
imageSource: '/path/to/file.png',
imageSourceType: ImageSourceType.file,
);
With Adaptive icon with background color
await FlutterPinnedShortcuts.createPinnedShortcut(
id: 'file_shortcut',
label: 'File Shortcut',
imageSource: 'https://example.com/image.png', // Legacy fallback
imageSourceType: ImageSourceType.network,
adaptiveIconForeground: 'https://example.com/image.png',
adaptiveIconBackground: '#2196F3', // Material Blue
adaptiveIconBackgroundType: AdaptiveIconBackgroundType.color,
extraData: {'type': 'adaptive_color'},
);
With Adaptive icon with background image
await FlutterPinnedShortcuts.createPinnedShortcut(
id: 'file_shortcut',
label: 'File Shortcut',
imageSource: 'assets/icon.png', // Legacy fallback
imageSourceType: ImageSourceType.asset,
adaptiveIconForeground: 'assets/icon_foreground.png',
adaptiveIconBackground: 'assets/icon_background.png',
adaptiveIconBackgroundType: AdaptiveIconBackgroundType.image,
extraData: {'type': 'adaptive_color'},
);
๐ Listen to shortcut clicks #
Set up a listener for when shortcuts are clicked:
FlutterPinnedShortcuts.onShortcutClick.listen((Map resultData) {
debugPrint('๐ Shortcut clicked: id : ${resultData['id']}, extraData: ${resultData['extraData']}');
// Handle the shortcut click, e.g., navigate to a specific screen
});
๐ Check if a shortcut is pinned #
bool isPinned = await FlutterPinnedShortcuts.isPinned('shortcut_id');
if (isPinned) {
print('๐ Shortcut is pinned!');
} else {
print('๐ซ Shortcut is not pinned');
}
โป๏ธ Dispose the plugin #
// Call this when you're done with the plugin, typically in the dispose method
@override
void dispose() {
FlutterPinnedShortcuts.dispose();
super.dispose();
}
๐ API Reference #
FlutterPinnedShortcuts #
Method | Description |
---|---|
initialize() |
๐ Initialize the plugin and set up shortcut click listener |
isSupported() |
โ Check if pinned shortcuts are supported on the device |
createPinnedShortcut() |
๐ Create a new pinned shortcut |
isPinned() |
๐ Check if a shortcut is pinned |
dispose() |
โป๏ธ Clean up resources used by the plugin |
ImageSourceType #
Value | Description |
---|---|
asset |
๐ฆ Flutter asset from the assets folder |
resource |
๐ค Android resource from res folder |
network |
๐ Image from a network URL |
file |
๐ Image from a file path |
โ ๏ธ Known Limitations #
- ๐ฑ Android only - not available on iOS
- ๐งช Full functionality requires Android 8.0 (API 26) or higher
- ๐ Older Android versions have limited support for shortcut management
- ๐ผ๏ธ For best results, shortcut icons should be 48x48dp or 96x96px
๐ฎ Future Plans #
- โ Support for dynamic shortcuts
- โ Multiple shortcut creation at once
- โ Improved error handling and reporting
- โ More customization options for shortcut appearance
๐ค Contributing #
Contributions are welcome! Feel free to submit a Pull Request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ฑ Compatibility #
Android Version | API Level | Support Level |
---|---|---|
Android 8.0+ | 26+ | โ Full support |
Android 7.1 | 25 | โ ๏ธ Limited support |
Android 7.0 - 4.1 | 24-16 | โ ๏ธ Basic support |
Android < 4.1 | <16 | โ Not supported |
๐ฎ Contact #
Have questions or suggestions? Please open an issue on GitHub!
Made with โค๏ธ by Lokesh Jangid