flutter_windows_notification icon indicating copy to clipboard operation
flutter_windows_notification copied to clipboard

Compilation error in flutter_windows_notification plugin on Windows

Open Ergul opened this issue 1 year ago • 8 comments

I encountered a compilation error while building my Flutter application for Windows using the version 1.2.0. The error occurs when using the flutter_windows_notification plugin. Below are the details of the error messages:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt\winrt/base.h(6508,17): error C2220: the following warning is treated as an error [C:\Users\eric\git\prostoreapp\build\windows\x64\plugins\windows_notification\windows_notification_plugin.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt\winrt/base.h(6508,17): warning C5205: deleting an abstract class 'winrt::impl::implements_delegate<winrt::Windows::UI::Core::DispatchedHandler,H>' which has a non-virtual destructor results in undefined behavior [C:\Users\eric\git\prostoreapp\build\windows\x64\plugins\windows_notification\windows_notification_plugin.vcxproj]
C:\Users\eric\git\prostoreapp\windows\flutter\ephemeral\.plugin_symlinks\windows_notification\windows\windows_notification_plugin.cpp(279,42): error C2039: 'UserInput' is not a member of 'winrt::Windows::UI::Notifications::ToastActivatedEventArgs' [C:\Users\eric\git\prostoreapp\build\windows\x64\plugins\windows_notification\windows_notification_plugin.vcxproj]
Error: Build process failed.

Steps to Reproduce

Add the flutter_windows_notification plugin to the pubspec.yaml file.

Build the Flutter application for Windows using flutter build windows.

My configuration

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.1, on Microsoft Windows [version 10.0.17763.4974], locale fr-CH)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.36)
[√] Android Studio (version 2023.1)
[√] Connected device (3 available)
[√] Network resources

It appears that there are issues related to the winrt base header and the ToastActivatedEventArgs class, which may have changes or deprecated members.

Please provide guidance on how to resolve these compilation errors.

Thank you.

Ergul avatar Jun 03 '24 10:06 Ergul

I encountered a compilation error while building my Flutter application for Windows using the version 1.2.0. The error occurs when using the flutter_windows_notification plugin. Below are the details of the error messages:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt\winrt/base.h(6508,17): error C2220: the following warning is treated as an error [C:\Users\eric\git\prostoreapp\build\windows\x64\plugins\windows_notification\windows_notification_plugin.vcxproj]
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\cppwinrt\winrt/base.h(6508,17): warning C5205: deleting an abstract class 'winrt::impl::implements_delegate<winrt::Windows::UI::Core::DispatchedHandler,H>' which has a non-virtual destructor results in undefined behavior [C:\Users\eric\git\prostoreapp\build\windows\x64\plugins\windows_notification\windows_notification_plugin.vcxproj]
C:\Users\eric\git\prostoreapp\windows\flutter\ephemeral\.plugin_symlinks\windows_notification\windows\windows_notification_plugin.cpp(279,42): error C2039: 'UserInput' is not a member of 'winrt::Windows::UI::Notifications::ToastActivatedEventArgs' [C:\Users\eric\git\prostoreapp\build\windows\x64\plugins\windows_notification\windows_notification_plugin.vcxproj]
Error: Build process failed.

Steps to Reproduce

Add the flutter_windows_notification plugin to the pubspec.yaml file.

Build the Flutter application for Windows using flutter build windows.

My configuration

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.1, on Microsoft Windows [version 10.0.17763.4974], locale fr-CH)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.36)
[√] Android Studio (version 2023.1)
[√] Connected device (3 available)
[√] Network resources

It appears that there are issues related to the winrt base header and the ToastActivatedEventArgs class, which may have changes or deprecated members.

Please provide guidance on how to resolve these compilation errors.

Thank you.

Hi, i cant checked now, i don't have any windows machine

mrtnetwork avatar Jun 05 '24 10:06 mrtnetwork

Hi, I'm having the same issue. The plugin does not compile on Windows on versions 1.2, 1.1, or 1.0.

@mrtnetwork Any ideas? I'm looking to use this package but not compiling is a pretty big deal. If you have any leads on what's happening I can try to debug on my end and submit a PR but I am very unfamiliar with these APIs and would need guidance.

Levi-Lesches avatar Jun 21 '24 21:06 Levi-Lesches

Hi, I'm having the same issue. The plugin does not compile on Windows on versions 1.2, 1.1, or 1.0.

@mrtnetwork Any ideas? I'm looking to use this package but not compiling is a pretty big deal. If you have any leads on what's happening I can try to debug on my end and submit a PR but I am very unfamiliar with these APIs and would need guidance.

Hi, I can't check without a windows machine. Do you see this? Maybe it's related

mrtnetwork avatar Jun 23 '24 19:06 mrtnetwork

Hm, I'm taking a look instead at bringing full Windows support to package:flutter_local_notifications, as that's looking pretty promising right now.

Levi-Lesches avatar Jun 26 '24 15:06 Levi-Lesches

Go to the file: C:\Users\{user}\AppData\Local\Pub\Cache\hosted\pub.dev\windows_notification-1.2.0\windows\include\windows_notification and edit windows_notification_plugin.h. For me name of the file was windows_notification_plugin_c_api.h.

Add #pragma comment(lib, "windowsapp") at the top of the file. And you are done!

image

Do run flutter pub get after making changes to the file.

Malay1121 avatar Jul 15 '24 12:07 Malay1121

Not to detract from the work done in this plugin, but my work on flutter_local_notifications is complete and the PR should be merged shortly. In the meantime you can set a dependency override to my branch:

# pubspec_overrides.yaml

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

Only posting this because cross platforms apps with notifications will need support for other platforms besides Windows, so having one solution is preferable.

Levi-Lesches avatar Jul 15 '24 16:07 Levi-Lesches

Not to detract from the work done in this plugin, but my work on flutter_local_notifications is complete and the PR should be merged shortly. In the meantime you can set a dependency override to my branch:

# pubspec_overrides.yaml

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

Only posting this because cross platforms apps with notifications will need support for other platforms besides Windows, so having one solution is preferable.

Is there any documentation on how to use flutter_local_notifications for windows?

Malay1121 avatar Jul 15 '24 16:07 Malay1121

The readme still has to be documented, but that branch has WindowsDetails with a whole bunch of options -- progress bars, images, buttons -- and those have thorough documentation. Those docs aren't published to pub yet, but your IDE's autocomplete should help, and you can look directly at the code for WindowsDetails to see everything it accepts and the docs on there.

Main notes in general:

  • no extra setup in your Windows config is needed
  • repeat notifications aren't supported at all on windows, but you can schedule as many notifications in advance as you'd like
  • if you want to cancel a notification by ID, or lookup active notifications, your app must be packaged as an msix. See the msix package on pub.dev for details
  • other than that, use flutter local notifications as you would for the other platforms

If you encounter any issues, be sure to open an issue on my fork and I'll fix it asap

Levi-Lesches avatar Jul 15 '24 16:07 Levi-Lesches