pinned_shortcuts 0.0.1 copy "pinned_shortcuts: ^0.0.1" to clipboard
pinned_shortcuts: ^0.0.1 copied to clipboard

PlatformAndroid

A Flutter plugin for creating and managing Android pinned shortcuts with support for various image types.

Flutter Pinned Shortcuts ๐Ÿ“Œ #

Pub License: MIT

โœจ 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.

pinned-shortcuts

โœ… 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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. 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

3
likes
140
points
110
downloads

Publisher

verified publisherlkrjangid.tech

Weekly Downloads

A Flutter plugin for creating and managing Android pinned shortcuts with support for various image types.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, http, path, path_provider

More

Packages that depend on pinned_shortcuts