fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.56k stars 939 forks source link

[Bug]: Type of value changed in params map #2214

Open gdelataillade opened 11 months ago

gdelataillade commented 11 months ago

Platform

Android 11

Plugin

android_alarm_manager_plus

Version

3.0.2

Flutter SDK

3.13.5

Steps to reproduce

  1. Call AndroidAlarmManager.oneShotAt with as params a map with a value of type double.
  2. Receive my params map in my isolate method but my value of type double became an integer.

Code Sample

final res = await AndroidAlarmManager.oneShotAt(
      settings.dateTime,
      id,
      AndroidAlarm.playAlarm,
[...]
      params: {
[...]
        'fadeDuration': settings.fadeDuration as double,
      },
    );

Logs

`fadeDuration is: int`

this is the print:
print("fadeDuration is: ${fadeDuration.runtimeType}");

Flutter Doctor

[✓] Flutter (Channel stable, 3.13.5, on macOS 14.0 23A344 darwin-arm64, locale en-US)
    • Flutter version 3.13.5 on channel stable at /Users/gdelataillade/Downloads/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 12fccda598 (2 weeks ago), 2023-09-19 13:56:11 -0700
    • Engine revision bd986c5ed2
    • Dart version 3.1.2
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/gdelataillade/Library/Android/sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.82.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.74.0

[✓] Connected device (4 available)
    • BE2011 (mobile)         • 40c7ac09                  • android-arm64  • Android 11 (API 30)
    • iPhone Gautier (mobile) • 00008120-001C51A41A63C01E • ios            • iOS 17.0 21A329
    • macOS (desktop)         • macos                     • darwin-arm64   • macOS 14.0 23A344 darwin-arm64
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 117.0.5938.132

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Checklist before submitting a bug

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

gdelataillade commented 8 months ago

Any update on this ?

github-actions[bot] commented 5 months ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

miquelbeltran commented 5 months ago

Internally, the plugin will convert the params sent from JSONObject to a serialized String to schedule the alarm.

It is during this serialization, when the params get added to the Android Intent extras that the type gets lost.

e.g. scheduling an alarm with:

params: {
  'a': 0.toDouble(),
  'b': 1.3,
},

inspecting the extras using a debugger:

image

The deserialize action doesn't know if 0 is a double, so it defaults to int, which is what gets sent back to the Flutter layer.

I am not sure if an easy fix is possible here, as the conversion from 0.0 to 0 happens in the JSONObject serialization and we cannot control.

My recommendation would be to either do the recast/parsing back on the Flutter layer, or send all numbers as Strings, to avoid losing the type information due to the serialization/deseralization that happens internally.

If anyone has a better solution, feel free to submit a PR.