diff --git a/CHANGELOG.md b/CHANGELOG.md
index d435561..9d007c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## v1.4.0
+
+* **New Feature** Generate icon from JPEG images in memory (Uint8List) `ShortcutIconAsset.memoryAsset`
+
## v1.3.0
* **Breaking Change** renamed `FlutterShortcutsItem` to `ShortcutItem`
diff --git a/README.md b/README.md
index 35ef6d3..3087047 100644
--- a/README.md
+++ b/README.md
@@ -15,12 +15,12 @@
Flutter Shortcuts Plugin is known for :
-| Flutter Shortcuts |
-| :--------------------------------- |
+| Flutter Shortcuts |
+| :---------------------------- |
| Fast, performant & compatible |
-| Free & Open-source |
-| Production ready |
-| Make App Reactive |
+| Free & Open-source |
+| Production ready |
+| Make App Reactive |
## Features
@@ -34,8 +34,8 @@ All the features listed below can be performed at the runtime.
## Demo
-||
-|---|
+| |
+| ------------------------------------------------------- |
## Quick Start
@@ -88,31 +88,49 @@ Flutter Shortcuts allows you to create shortcut icon from both android `drawable
* If you want to use icon from Android resources, `drawable` or `mipmap`.
-use: `ShortcutIconAsset.androidAsset`
+ use: `ShortcutIconAsset.androidAsset`
-```dart
-ShortcutItem(
- id: "2",
- action: 'Bookmark page action',
- shortLabel: 'Bookmark Page',
- icon: "ic_launcher",
- shortcutIconAsset: ShortcutIconAsset.androidAsset,
-),
+ ```dart
+ ShortcutItem(
+ 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`
+ use: `ShortcutIconAsset.flutterAsset`
-```dart
-ShortcutItem(
- id: "2",
- action: 'Bookmark page action',
- shortLabel: 'Bookmark Page',
- icon: 'assets/icons/bookmark.png',
- shortcutIconAsset: ShortcutIconAsset.flutterAsset,
-),
-```
+ ```dart
+ ShortcutItem(
+ id: "2",
+ action: 'Bookmark page action',
+ shortLabel: 'Bookmark Page',
+ icon: 'assets/icons/bookmark.png',
+ shortcutIconAsset: ShortcutIconAsset.flutterAsset,
+ ),
+ ```
+
+* If you want to create shortcut icon from memory (`Uint8List`).
+
+ **This only works with JPEG images**!
+
+ use: `ShortcutIconAsset.memoryAsset`
+
+ ```dart
+ Unit8List jpegData = ...; // JPEG image in memory
+
+ ShortcutItem(
+ id: "2",
+ action: 'Bookmark page action',
+ shortLabel: 'Bookmark Page',
+ icon: ShortcutMemoryIcon(jpegData).toList(),
+ shortcutIconAsset: ShortcutIconAsset.flutterAsset,
+ ),
+ ```
### Set shortcut items
diff --git a/android/src/main/java/com/divyanshushekhar/flutter_shortcuts/MethodCallImplementation.java b/android/src/main/java/com/divyanshushekhar/flutter_shortcuts/MethodCallImplementation.java
index 3c8a657..7408d8f 100644
--- a/android/src/main/java/com/divyanshushekhar/flutter_shortcuts/MethodCallImplementation.java
+++ b/android/src/main/java/com/divyanshushekhar/flutter_shortcuts/MethodCallImplementation.java
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Base64;
import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.loader.FlutterLoader;
@@ -394,6 +395,9 @@ private void setIconCompat(int iconType,String icon,ShortcutInfoCompat.Builder s
case 1:
setIconFromFlutterCompat(shortcutBuilderCompat, icon);
break;
+ case 2:
+ setIconFromBase64StringCompat(shortcutBuilderCompat, icon);
+ break;
default:
break;
}
@@ -414,10 +418,17 @@ private void setIconFromFlutterCompat(ShortcutInfoCompat.Builder shortcutBuilder
}
}
+ private void setIconFromBase64StringCompat(ShortcutInfoCompat.Builder shortcutBuilder, String icon) {
+ if( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ shortcutBuilder.setIcon(IconCompat.createFromIcon(context, getIconFromMemoryAsset(context, icon)));
+ }
+ }
+
/* *********************** Person ******************* */
private void setIconCompat(int iconType,String icon,Person.Builder personBuilderCompat) {
// 0 - ShortcutIconType.androidAsset
// 1 - ShortcutIconType.flutterAsset
+ // 2 - ShortcutIconType.memoryAsset
switch (iconType) {
case 0:
setIconFromNativeCompat(personBuilderCompat, icon);
@@ -425,6 +436,9 @@ private void setIconCompat(int iconType,String icon,Person.Builder personBuilder
case 1:
setIconFromFlutterCompat(personBuilderCompat, icon);
break;
+ case 2:
+ setIconFromBase64StringCompat(personBuilderCompat, icon);
+ break;
default:
break;
}
@@ -445,6 +459,12 @@ private void setIconFromFlutterCompat(Person.Builder personBuilder, String icon)
}
}
+ private void setIconFromBase64StringCompat(Person.Builder personBuilder, String icon) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ personBuilder.setIcon(IconCompat.createFromIcon(context,getIconFromMemoryAsset(context,icon)));
+ }
+ }
+
@RequiresApi(api = Build.VERSION_CODES.O)
private Icon getIconFromFlutterAsset(Context context, String path) {
AssetManager assetManager = context.getAssets();
@@ -466,6 +486,19 @@ private Icon getIconFromFlutterAsset(Context context, String path) {
return Icon.createWithAdaptiveBitmap(image);
}
+ @RequiresApi(api = Build.VERSION_CODES.O)
+ private Icon getIconFromMemoryAsset(Context context, String base64Jpeg) {
+ try {
+ byte[] bytes = Base64.getDecoder().decode(base64Jpeg);
+ Bitmap image = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
+
+ return Icon.createWithAdaptiveBitmap(image);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
private int loadResourceId(Context context, String icon) {
if (icon == null) {
return 0;
diff --git a/example/pubspec.lock b/example/pubspec.lock
index 5ea1c17..ba60d38 100644
--- a/example/pubspec.lock
+++ b/example/pubspec.lock
@@ -5,58 +5,58 @@ packages:
dependency: transitive
description:
name: async
- url: "https://pub.dartlang.org"
+ sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
+ url: "https://pub.dev"
source: hosted
- version: "2.8.1"
+ version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
- url: "https://pub.dartlang.org"
+ sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
- url: "https://pub.dartlang.org"
+ sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
- charcode:
- dependency: transitive
- description:
- name: charcode
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.1"
+ version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
- url: "https://pub.dartlang.org"
+ sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
- url: "https://pub.dartlang.org"
+ sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
+ url: "https://pub.dev"
source: hosted
- version: "1.15.0"
+ version: "1.17.1"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
- url: "https://pub.dartlang.org"
+ sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
+ url: "https://pub.dev"
source: hosted
- version: "1.0.3"
+ version: "1.0.5"
fake_async:
dependency: transitive
description:
name: fake_async
- url: "https://pub.dartlang.org"
+ sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
@@ -68,40 +68,60 @@ packages:
path: ".."
relative: true
source: path
- version: "1.3.0"
+ version: "1.4.0"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
+ js:
+ dependency: transitive
+ description:
+ name: js
+ sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.6.7"
matcher:
dependency: transitive
description:
name: matcher
- url: "https://pub.dartlang.org"
+ sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
+ url: "https://pub.dev"
source: hosted
- version: "0.12.10"
+ version: "0.12.15"
+ material_color_utilities:
+ dependency: transitive
+ description:
+ name: material_color_utilities
+ sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
- url: "https://pub.dartlang.org"
+ sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
+ url: "https://pub.dev"
source: hosted
- version: "1.7.0"
+ version: "1.9.1"
path:
dependency: transitive
description:
name: path
- url: "https://pub.dartlang.org"
+ sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
+ url: "https://pub.dev"
source: hosted
- version: "1.8.0"
+ version: "1.8.3"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
- url: "https://pub.dartlang.org"
+ sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc"
+ url: "https://pub.dev"
source: hosted
- version: "2.0.0"
+ version: "2.1.4"
sky_engine:
dependency: transitive
description: flutter
@@ -111,58 +131,58 @@ packages:
dependency: transitive
description:
name: source_span
- url: "https://pub.dartlang.org"
+ sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
+ url: "https://pub.dev"
source: hosted
- version: "1.8.1"
+ version: "1.9.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
- url: "https://pub.dartlang.org"
+ sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
+ url: "https://pub.dev"
source: hosted
- version: "1.10.0"
+ version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
- url: "https://pub.dartlang.org"
+ sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
- url: "https://pub.dartlang.org"
+ sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
- url: "https://pub.dartlang.org"
+ sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
- url: "https://pub.dartlang.org"
+ sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
+ url: "https://pub.dev"
source: hosted
- version: "0.4.2"
- typed_data:
- dependency: transitive
- description:
- name: typed_data
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
+ version: "0.5.1"
vector_math:
dependency: transitive
description:
name: vector_math
- url: "https://pub.dartlang.org"
+ sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.4"
sdks:
- dart: ">=2.12.0 <3.0.0"
+ dart: ">=3.0.0-0 <4.0.0"
flutter: ">=1.20.0"
diff --git a/lib/src/helper/enums/shortcut_icon_asset.dart b/lib/src/helper/enums/shortcut_icon_asset.dart
index 495957a..4200b86 100644
--- a/lib/src/helper/enums/shortcut_icon_asset.dart
+++ b/lib/src/helper/enums/shortcut_icon_asset.dart
@@ -14,4 +14,15 @@ enum ShortcutIconAsset {
/// Creates Icon from the flutter resources `assets/icons/flutter.png`.
flutterAsset,
+
+ /// Creates Icon from base64 **JPEG** image.
+ ///
+ /// You can use helper function like so:
+ /// ```dart
+ /// Uint8List bytes = ...;
+ ///
+ /// // Pass this string to [icon]
+ /// ShortcutMemoryIcon(bytes).toString()
+ /// ```
+ memoryAsset,
}
diff --git a/lib/src/helper/helper.dart b/lib/src/helper/helper.dart
index aefc7a2..bea9c1a 100644
--- a/lib/src/helper/helper.dart
+++ b/lib/src/helper/helper.dart
@@ -10,4 +10,5 @@ for more details.
export 'action/shortcut_action.dart';
export 'model/shortcut_item.dart';
+export 'model/shortcut_memory_icon.dart';
export 'enums/shortcut_icon_asset.dart';
diff --git a/lib/src/helper/model/shortcut_memory_icon.dart b/lib/src/helper/model/shortcut_memory_icon.dart
new file mode 100644
index 0000000..19573eb
--- /dev/null
+++ b/lib/src/helper/model/shortcut_memory_icon.dart
@@ -0,0 +1,12 @@
+import 'dart:convert';
+import 'dart:typed_data';
+
+class ShortcutMemoryIcon {
+ final Uint8List jpegImage;
+
+ const ShortcutMemoryIcon({required this.jpegImage});
+
+ String toString() {
+ return base64Encode(jpegImage);
+ }
+}
diff --git a/pubspec.lock b/pubspec.lock
index 6cb8fde..0f0177d 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -5,51 +5,50 @@ packages:
dependency: transitive
description:
name: async
- url: "https://pub.dartlang.org"
+ sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
+ url: "https://pub.dev"
source: hosted
- version: "2.8.1"
+ version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
- url: "https://pub.dartlang.org"
+ sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
characters:
dependency: transitive
description:
name: characters
- url: "https://pub.dartlang.org"
+ sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
- charcode:
- dependency: transitive
- description:
- name: charcode
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.1"
+ version: "1.3.0"
clock:
dependency: transitive
description:
name: clock
- url: "https://pub.dartlang.org"
+ sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
- url: "https://pub.dartlang.org"
+ sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
+ url: "https://pub.dev"
source: hosted
- version: "1.15.0"
+ version: "1.17.1"
fake_async:
dependency: transitive
description:
name: fake_async
- url: "https://pub.dartlang.org"
+ sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
@@ -60,41 +59,62 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
+ js:
+ dependency: transitive
+ description:
+ name: js
+ sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.6.7"
matcher:
dependency: transitive
description:
name: matcher
- url: "https://pub.dartlang.org"
+ sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
+ url: "https://pub.dev"
source: hosted
- version: "0.12.10"
+ version: "0.12.15"
+ material_color_utilities:
+ dependency: transitive
+ description:
+ name: material_color_utilities
+ sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
+ url: "https://pub.dev"
+ source: hosted
+ version: "0.2.0"
meta:
dependency: transitive
description:
name: meta
- url: "https://pub.dartlang.org"
+ sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
+ url: "https://pub.dev"
source: hosted
- version: "1.7.0"
+ version: "1.9.1"
path:
dependency: transitive
description:
name: path
- url: "https://pub.dartlang.org"
+ sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
+ url: "https://pub.dev"
source: hosted
- version: "1.8.0"
+ version: "1.8.3"
pedantic:
dependency: "direct dev"
description:
name: pedantic
- url: "https://pub.dartlang.org"
+ sha256: "67fc27ed9639506c856c840ccce7594d0bdcd91bc8d53d6e52359449a1d50602"
+ url: "https://pub.dev"
source: hosted
- version: "1.11.0"
+ version: "1.11.1"
plugin_platform_interface:
dependency: "direct main"
description:
name: plugin_platform_interface
- url: "https://pub.dartlang.org"
+ sha256: "6a2128648c854906c53fa8e33986fc0247a1116122f9534dd20e3ab9e16a32bc"
+ url: "https://pub.dev"
source: hosted
- version: "2.0.0"
+ version: "2.1.4"
sky_engine:
dependency: transitive
description: flutter
@@ -104,58 +124,58 @@ packages:
dependency: transitive
description:
name: source_span
- url: "https://pub.dartlang.org"
+ sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
+ url: "https://pub.dev"
source: hosted
- version: "1.8.1"
+ version: "1.9.1"
stack_trace:
dependency: transitive
description:
name: stack_trace
- url: "https://pub.dartlang.org"
+ sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
+ url: "https://pub.dev"
source: hosted
- version: "1.10.0"
+ version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
- url: "https://pub.dartlang.org"
+ sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
- url: "https://pub.dartlang.org"
+ sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
+ url: "https://pub.dev"
source: hosted
- version: "1.1.0"
+ version: "1.2.0"
term_glyph:
dependency: transitive
description:
name: term_glyph
- url: "https://pub.dartlang.org"
+ sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
+ url: "https://pub.dev"
source: hosted
- version: "1.2.0"
+ version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
- url: "https://pub.dartlang.org"
+ sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
+ url: "https://pub.dev"
source: hosted
- version: "0.4.2"
- typed_data:
- dependency: transitive
- description:
- name: typed_data
- url: "https://pub.dartlang.org"
- source: hosted
- version: "1.3.0"
+ version: "0.5.1"
vector_math:
dependency: transitive
description:
name: vector_math
- url: "https://pub.dartlang.org"
+ sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
+ url: "https://pub.dev"
source: hosted
- version: "2.1.0"
+ version: "2.1.4"
sdks:
- dart: ">=2.12.0 <3.0.0"
+ dart: ">=3.0.0-0 <4.0.0"
flutter: ">=1.20.0"
diff --git a/pubspec.yaml b/pubspec.yaml
index dc57c07..b948139 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
name: flutter_shortcuts
description: Flutter plugin for creating static & dynamic app/conversation shortcuts on home screen.
-version: 1.3.0
+version: 1.4.0
repository: https://github.com/DevsOnFlutter/flutter_shortcuts
documentation: https://github.com/DevsOnFlutter/flutter_shortcuts/blob/main/README.md