Skip to content
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

HomeWidget.updateWidget support Long type add Int to error message #270

Closed
wants to merge 9 commits into from

Conversation

bannzai
Copy link

@bannzai bannzai commented Jul 9, 2024

resolved: #269

@ABausG
Copy link
Owner

ABausG commented Jul 10, 2024

I will merge the beta branch today to handle the size error.

Could you already add a test case to the android integration test to ensure that Long is supported properly? Thanks!!

@ABausG
Copy link
Owner

ABausG commented Jul 13, 2024

Hey @bannzai would you have time to merge back the latest changes from main and add an android integration test for this?

@bannzai
Copy link
Author

bannzai commented Jul 14, 2024

Okay! I'll try it soon.

@@ -73,7 +80,12 @@ class HomeWidgetPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
val value = prefs.all[id] ?: defaultValue

if(value is Long) {
result.success(java.lang.Double.longBitsToDouble(value))
// The reason for falling back to Double is that it was supported before Long.
when (prefs.getString(ACTUAL_WIDGET_DATA_TYPE, "Double")) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Key was added because there is no way to distinguish between Double and Long.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the old logic should have already covered the logic. Looking at the code I also think that there is no benefit in this extra logic.
home_widget already handled this behavior by storing handling doubles always as long. so in that way we trade 2 bytes per number for the behavior.

So can you please revert your changes to the initial fix (adding is Long to the setWidgetData call)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use longBitsToDouble to convert a Long to a Double? Also, if I want a Long (int in Dart) to be returned, is that ok?

@bannzai
Copy link
Author

bannzai commented Jul 14, 2024

Test Passed on my local mac ✅

@ABausG Please review it.

Copy link
Owner

@ABausG ABausG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand the necessity for the changes you made in the last commit. Could you revert those/explain a bit more why those changes would be necessary?

Apart from that can you potentially also adjust the iOS integration test to include the Long case?

I will let the pipeline run once the comments are addressed

@@ -10,6 +10,7 @@ void main() {
'intKey': 12,
'boolKey': true,
'floatingNumberKey': 12.1,
'longKey': 8640000000000000,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should rather be double.maxFinite

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What difference does this make to the double test case?

Comment on lines +220 to +222
// For example, both Double and Long are saved in SharedPreferences with putLong,
// and this Key is used to distinguish between them when retrieving.
private const val ACTUAL_WIDGET_DATA_TYPE = "actualWidgetDataType"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would never work when Users wanted to store both double and long as this would always override

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, Okay. I'll figure out another way.

@@ -73,7 +80,12 @@ class HomeWidgetPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
val value = prefs.all[id] ?: defaultValue

if(value is Long) {
result.success(java.lang.Double.longBitsToDouble(value))
// The reason for falling back to Double is that it was supported before Long.
when (prefs.getString(ACTUAL_WIDGET_DATA_TYPE, "Double")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the old logic should have already covered the logic. Looking at the code I also think that there is no benefit in this extra logic.
home_widget already handled this behavior by storing handling doubles always as long. so in that way we trade 2 bytes per number for the behavior.

So can you please revert your changes to the initial fix (adding is Long to the setWidgetData call)

@bannzai
Copy link
Author

bannzai commented Jul 15, 2024

Dart double is not Kotlin Long. Dart int can be a Kotlin Long. e.g) Dart.now.millisecondsSinceEpoch.

@ABausG ABausG mentioned this pull request Jul 16, 2024
5 tasks
@ABausG
Copy link
Owner

ABausG commented Jul 16, 2024

Thanks for the Explanation! I have looked further into this and possible solutions and considered it quicker to open the fix for this in #280 and will close this PR for this.

Thanks though for Investigating and Proposing this first Fix!!

@ABausG ABausG closed this Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HomeWidget.updateWidget invalid type error message for Long
2 participants