Skip to content

Add latest changes from MaikuB repo #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
60a47a6
Updates readme for iOS Setup (#1776)
som-R91 Nov 13, 2022
35cf591
[flutter_local_notifications] fix Kotlin version used in example app …
MaikuB Nov 16, 2022
d65e618
[flutter_local_notifications] fixes parsing of callback handles for n…
MaikuB Nov 21, 2022
06d7906
[flutter_local_notifications] Upgraded Android Gradle Plugin to fix A…
Rexios80 Nov 24, 2022
f1f9afb
Recommend WindowManager to fix Android 12L+ bugs (#1803)
12people Nov 24, 2022
f3bb689
Add note about keeping `@mipmap/ic_launcher` resource (#1804)
DanielArndt Nov 24, 2022
1d8b9d8
updated example app to not request the ability to display critical al…
MaikuB Nov 24, 2022
9e02bb5
[flutter_local_notifications] re-add imports needed for Flutter 3.0 a…
MaikuB Nov 26, 2022
a923fc6
bump linux plugin's Flutter version requirement to 3.0.0 and add expl…
MaikuB Nov 26, 2022
2380680
Implement options to hide or crop attachments in the thumbnail on iOS…
noinskit Nov 29, 2022
cb05fb7
[flutter_local_notifications] Fixes #1486 :Adds ability to count down…
ebelevics Dec 3, 2022
d8d07a7
Google Java Format
Dec 3, 2022
ff4abbd
replaced placeholder.com with dummyimage.com in example app due to Cl…
MaikuB Dec 3, 2022
1ebd70d
enable usePubspecOverrides with melos (#1822)
MaikuB Dec 9, 2022
4b723e7
[flutter_local_notifications] update docs on initialize method to des…
MaikuB Dec 19, 2022
7d4f073
[flutter_local_notifications] Support Android inexact notifications (…
kaptnkoala Jan 10, 2023
f1ff831
Reference newer flutter_timezone package in readme (#1860)
EnduringBeta Jan 10, 2023
88d0491
updated cirrus.yml to use M1 macOS VMs (#1866)
MaikuB Jan 10, 2023
d0cf654
Revert "[flutter_local_notifications] Support Android inexact notific…
MaikuB Jan 10, 2023
1066d26
[flutter_local_notifications] Android inexact notifications (#1881)
kaptnkoala Feb 5, 2023
7d26b32
updated readme that was reference old iOS classes instead of the new …
MaikuB Feb 5, 2023
21a787d
updated details for 14.0.0-dev.1 (pre)release
MaikuB Feb 5, 2023
3712f7d
Added to the example the fix for app crash on android 13 (#1887)
guyluz11 Feb 12, 2023
cd2e430
Update readme code snippet to accept null values in notificationAppLa…
jithuraj Feb 12, 2023
d5e8528
Bump xdg_directories in /flutter_local_notifications_linux (#1895)
dependabot[bot] Feb 14, 2023
f6d3fe1
added details for flutter_local_notifications 3.0.0+1 release
MaikuB Feb 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement options to hide or crop attachments in the thumbnail on iOS (
  • Loading branch information
noinskit authored Nov 29, 2022
commit 238068076ae0859be6e3961bec9a5e3d948757e2
56 changes: 52 additions & 4 deletions flutter_local_notifications/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,26 @@ class _HomePageState extends State<HomePage> {
},
),
PaddedElevatedButton(
buttonText: 'Show notification with attachment',
buttonText:
'Show notification with attachment (with thumbnail)',
onPressed: () async {
await _showNotificationWithAttachment();
await _showNotificationWithAttachment(
hideThumbnail: false);
},
),
PaddedElevatedButton(
buttonText:
'Show notification with attachment (no thumbnail)',
onPressed: () async {
await _showNotificationWithAttachment(
hideThumbnail: true);
},
),
PaddedElevatedButton(
buttonText:
'Show notification with attachment (clipped thumbnail)',
onPressed: () async {
await _showNotificationWithClippedThumbnailAttachment();
},
),
PaddedElevatedButton(
Expand Down Expand Up @@ -2163,12 +2180,43 @@ class _HomePageState extends State<HomePage> {
payload: 'item x');
}

Future<void> _showNotificationWithAttachment() async {
Future<void> _showNotificationWithAttachment({
required bool hideThumbnail,
}) async {
final String bigPicturePath = await _downloadAndSaveFile(
'https://via.placeholder.com/600x200', 'bigPicture.jpg');
final DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(attachments: <DarwinNotificationAttachment>[
DarwinNotificationAttachment(
bigPicturePath,
hideThumbnail: hideThumbnail,
)
]);
final NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
await flutterLocalNotificationsPlugin.show(
id++,
'notification with attachment title',
'notification with attachment body',
notificationDetails);
}

Future<void> _showNotificationWithClippedThumbnailAttachment() async {
final String bigPicturePath = await _downloadAndSaveFile(
'https://via.placeholder.com/600x200', 'bigPicture.jpg');
final DarwinNotificationDetails darwinNotificationDetails =
DarwinNotificationDetails(attachments: <DarwinNotificationAttachment>[
DarwinNotificationAttachment(bigPicturePath)
DarwinNotificationAttachment(
bigPicturePath,
thumbnailClippingRect:
// lower right quadrant of the attachment
const DarwinNotificationAttachmentThumbnailClippingRect(
x: 0.5,
y: 0.5,
height: 0.5,
width: 0.5,
),
)
]);
final NotificationDetails notificationDetails = NotificationDetails(
iOS: darwinNotificationDetails, macOS: darwinNotificationDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ @implementation FlutterLocalNotificationsPlugin {
NSString *const ATTACHMENTS = @"attachments";
NSString *const ATTACHMENT_IDENTIFIER = @"identifier";
NSString *const ATTACHMENT_FILE_PATH = @"filePath";
NSString *const ATTACHMENT_HIDE_THUMBNAIL = @"hideThumbnail";
NSString *const ATTACHMENT_THUMBNAIL_CLIPPING_RECT = @"thumbnailClippingRect";
NSString *const INTERRUPTION_LEVEL = @"interruptionLevel";
NSString *const THREAD_IDENTIFIER = @"threadIdentifier";
NSString *const PRESENT_ALERT = @"presentAlert";
Expand Down Expand Up @@ -912,14 +914,40 @@ - (void)cancelAll:(FlutterResult _Nonnull)result {
[NSMutableArray arrayWithCapacity:attachments.count];
for (NSDictionary *attachment in attachments) {
NSError *error;

NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
if ([self containsKey:ATTACHMENT_HIDE_THUMBNAIL
forDictionary:attachment]) {
NSNumber *hideThumbnail = attachment[ATTACHMENT_HIDE_THUMBNAIL];
[options
setObject:hideThumbnail
forKey:UNNotificationAttachmentOptionsThumbnailHiddenKey];
}
if ([self containsKey:ATTACHMENT_THUMBNAIL_CLIPPING_RECT
forDictionary:attachment]) {
NSDictionary *thumbnailClippingRect =
attachment[ATTACHMENT_THUMBNAIL_CLIPPING_RECT];
CGRect rect =
CGRectMake([thumbnailClippingRect[@"x"] doubleValue],
[thumbnailClippingRect[@"y"] doubleValue],
[thumbnailClippingRect[@"width"] doubleValue],
[thumbnailClippingRect[@"height"] doubleValue]);
NSDictionary *rectDict =
CFBridgingRelease(CGRectCreateDictionaryRepresentation(rect));
[options
setObject:rectDict
forKey:
UNNotificationAttachmentOptionsThumbnailClippingRectKey];
}

UNNotificationAttachment *notificationAttachment =
[UNNotificationAttachment
attachmentWithIdentifier:attachment[ATTACHMENT_IDENTIFIER]
URL:[NSURL
fileURLWithPath:
attachment
[ATTACHMENT_FILE_PATH]]
options:nil
options:options
error:&error];
if (error) {
result(getFlutterError(error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,21 @@ extension DarwinInitializationSettingsMapper on DarwinInitializationSettings {
};
}

extension DarwinNotificationAttachmentMapper on DarwinNotificationAttachment {
extension on DarwinNotificationAttachmentThumbnailClippingRect {
Map<String, Object> toMap() => <String, Object>{
'x': x,
'y': y,
'width': width,
'height': height,
};
}

extension DarwinNotificationAttachmentMapper on DarwinNotificationAttachment {
Map<String, Object?> toMap() => <String, Object?>{
'identifier': identifier ?? '',
'filePath': filePath,
'hideThumbnail': hideThumbnail,
'thumbnailClippingRect': thumbnailClippingRect?.toMap(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class DarwinNotificationAttachment {
const DarwinNotificationAttachment(
this.filePath, {
this.identifier,
this.hideThumbnail,
this.thumbnailClippingRect,
});

/// The local file path to the attachment.
Expand All @@ -18,4 +20,43 @@ class DarwinNotificationAttachment {
/// When left empty, the platform's native APIs will generate a unique
/// identifier
final String? identifier;

/// Should the attachment be considered for the notification thumbnail?
final bool? hideThumbnail;

/// The clipping rectangle for the thumbnail image.
final DarwinNotificationAttachmentThumbnailClippingRect?
thumbnailClippingRect;
}

/// Represents the clipping rectangle used for the thumbnail image.
class DarwinNotificationAttachmentThumbnailClippingRect {
/// Constructs an instance of
/// [DarwinNotificationAttachmentThumbnailClippingRect].
const DarwinNotificationAttachmentThumbnailClippingRect({
required this.x,
required this.y,
required this.width,
required this.height,
});

/// Horizontal offset of the rectangle as proportion of the original image.
///
/// Value in the range from 0.0 to 1.0.
final double x;

/// Vertical offset of the rectangle as proportion of the original image.
///
/// Value in the range from 0.0 to 1.0.
final double y;

/// Width of the rectangle as proportion of the original image.
///
/// Value in the range from 0.0 to 1.0.
final double width;

/// Height of the rectangle as proportion of the original image.
///
/// Value in the range from 0.0 to 1.0.
final double height;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class FlutterLocalNotificationsPlugin: NSObject, FlutterPlugin, UNUserNot
static let attachments = "attachments"
static let identifier = "identifier"
static let filePath = "filePath"
static let hideThumbnail = "hideThumbnail"
static let attachmentThumbnailClippingRect = "thumbnailClippingRect"
static let threadIdentifier = "threadIdentifier"
static let interruptionLevel = "interruptionLevel"
static let actionId = "actionId"
Expand Down Expand Up @@ -517,7 +519,19 @@ public class FlutterLocalNotificationsPlugin: NSObject, FlutterPlugin, UNUserNot
for attachment in attachments {
let identifier = attachment[MethodCallArguments.identifier] as! String
let filePath = attachment[MethodCallArguments.filePath] as! String
let notificationAttachment = try UNNotificationAttachment.init(identifier: identifier, url: URL.init(fileURLWithPath: filePath))
var options: [String: Any] = [:]
if let hideThumbnail = attachment[MethodCallArguments.hideThumbnail] as? NSNumber {
options[UNNotificationAttachmentOptionsThumbnailHiddenKey] = hideThumbnail
}
if let thumbnailClippingRect = attachment[MethodCallArguments.attachmentThumbnailClippingRect] as? [String: Any] {
let rect = CGRect(x: thumbnailClippingRect["x"] as! Double, y: thumbnailClippingRect["y"] as! Double, width: thumbnailClippingRect["width"] as! Double, height: thumbnailClippingRect["height"] as! Double)
options[UNNotificationAttachmentOptionsThumbnailClippingRectKey] = rect.dictionaryRepresentation
}
let notificationAttachment = try UNNotificationAttachment.init(
identifier: identifier,
url: URL.init(fileURLWithPath: filePath),
options: options
)
content.attachments.append(notificationAttachment)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': 'category1',
Expand Down Expand Up @@ -309,10 +311,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down Expand Up @@ -379,10 +383,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down Expand Up @@ -445,10 +451,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down Expand Up @@ -512,10 +520,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': 'thread',
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': 'category1',
Expand Down Expand Up @@ -219,10 +221,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down Expand Up @@ -288,10 +292,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down Expand Up @@ -357,10 +363,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down Expand Up @@ -429,10 +437,12 @@ void main() {
'sound': 'sound.mp3',
'badgeNumber': 1,
'threadIdentifier': null,
'attachments': <Map<String, Object>>[
<String, Object>{
'attachments': <Map<String, Object?>>[
<String, Object?>{
'filePath': 'video.mp4',
'identifier': '2b3f705f-a680-4c9f-8075-a46a70e28373',
'hideThumbnail': null,
'thumbnailClippingRect': null,
}
],
'categoryIdentifier': null,
Expand Down