MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.47k stars 1.4k forks source link

Handling Image File Paths with Special Characters in Windows #2364

Closed DomingoMG closed 4 months ago

DomingoMG commented 4 months ago

Describe the bug When I try to display a local image from my PC as a notification, if the image name contains any special characters (such as accents), the image does not show up. On the other hand, images in Flutter load correctly with or without accents. However, in the notification, it seems there is no parser to handle these cases and manage special characters.

To Reproduce Set up a Flutter project with the flutter_local_notifications dependency in the specified version. Save an image in a local path that contains special characters in its name, for example, C:\Tommy Torres - Como Tú Decías.png. Attempt to display a notification using this image. Notice that the image does not appear in the notification.

Expected behavior The image should appear in the notification regardless of whether its name contains special characters.

Sample code to reproduce the problem

Future<void> showNotification() async {
  final String imagePath = 'C:\\Tommy Torres - Como Tú Decías.png'; // Change this to the path of your image
  Uri fileUri = Uri.file(imagePath);
  print('File URI: $fileUri');
  String encodedFilePath = fileUri.toFilePath(windows: Platform.isWindows);
  print('Encoded file path: $encodedFilePath');
  final imageFile = File(encodedFilePath);
  print('Image path: ${imageFile.path}');
  await _flutterLocalNotificationsPlugin.show(
    _notificationId++,
    'Test title',
    'Example body text',
    NotificationDetails(
      windows: WindowsNotificationDetails(
        audio: WindowsNotificationAudio.silent(),
        images: [
          WindowsImage.file(imageFile, altText: 'Test Image')
        ]
      ),
    ),
    payload: 'payload',
  );
}

Flutter doctor output:

Flutter 3.22.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 761747bfc5 (4 weeks ago) • 2024-06-05 22:15:13 +0200
Engine • revision edd8546116
Tools • Dart 3.4.3 • DevTools 2.34.3

Pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  flutter_local_notifications: ^17.2.1

dependency_overrides: 
  flutter_local_notifications: 
    git: 
      url: https://github.com/Levi-Lesches/flutter_local_notifications.git
      ref: windows-impl
      path: flutter_local_notifications
  flutter_local_notifications_platform_interface: 
    git: 
      url: https://github.com/Levi-Lesches/flutter_local_notifications.git
      ref: windows-impl
      path: flutter_local_notifications_platform_interface

I will attach an image to the post to help investigate the problem. Thank you. When downloading the photo please use this name to reproduce the error: Tommy Torres - Como Tu Decías.png

Tommy Torres - Como Tu Decías

Levi-Lesches commented 4 months ago

Interesting, thanks for reporting! Turns out, I was not supposed to rely on Uri's special character encoding, and just spit out the file name plain, even with special characters. I pushed the fix, so after doing flutter pub upgrade flutter_local_notifications, you can just do:


NotificationDetails(
    windows: WindowsNotificationDetails(
      images: <WindowsImage>[
        WindowsImage.file(
          File(r"C:\Tommy Torres - Como Tú Decías.png"),
          altText: 'A beautiful image',
        ),
      ],
    ),
  ),
MaikuB commented 4 months ago

On a related note, @Levi-Lesches are you able allow issues to be raised on your fork? Would issues specific to the fork to be raised there

Levi-Lesches commented 4 months ago

Just did! Didn't realize they were disabled by default, but yes, any Windows-specific issues can go there

MaikuB commented 4 months ago

Thanks. Going to close this one as well. For any further issues to do with the fork, please post on the repository for the fork