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

Decimal picker crashes when trying to change decimal point #16

Closed
lapauk opened this issue May 31, 2018 · 5 comments
Closed

Decimal picker crashes when trying to change decimal point #16

lapauk opened this issue May 31, 2018 · 5 comments
Labels

Comments

@lapauk
Copy link

lapauk commented May 31, 2018

My picker:

return new NumberPickerDialog.decimal( minValue: 37, maxValue: 42, initialDoubleValue: 37.5, );

I did some debugging, looks like in _onDecimalNotification(Notification notification) the decimalValueInTheMiddle is too big (37 in my case). Upon closer looking I am actually confused what the purpose of that variable is.

The relevant problem happens towards the end:

double newValue = ((selectedIntValue + decimalPart).toDouble());

The decimal part in my case is 3.7 (gets formed from the 37 I mentioned above). If I understand that correctly, the decimal part should be between 0(inclusive) and 1(exclusive).

In my case the newValue becomes too big at some point which is why the number picker craps out with an assertion error from the constructor (min max selected check)

Exception:

I/flutter (12075): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (12075): The following assertion was thrown building NumberPickerDialog(dirty, state:
I/flutter (12075): _NumberPickerDialogControllerState#2927b):
I/flutter (12075): 'package:numberpicker/numberpicker.dart': Failed assertion: line 58 pos 16: 'initialValue >=
I/flutter (12075): minValue && initialValue <= maxValue': is not true.
I/flutter (12075):
I/flutter (12075): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (12075): more information in this error message to help you determine and fix the underlying cause.
I/flutter (12075): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (12075): https://github.com/flutter/flutter/issues/new
I/flutter (12075):
I/flutter (12075): When the exception was thrown, this was the stack:
I/flutter (12075): #2 new NumberPicker.decimal (package:numberpicker/numberpicker.dart)
I/flutter (12075): #3 _NumberPickerDialogControllerState._buildNumberPicker (package:numberpicker/numberpicker.dart:396:18)
I/flutter (12075): #4 _NumberPickerDialogControllerState.build (package:numberpicker/numberpicker.dart:417:16)
I/flutter (12075): #5 StatefulElement.build (package:flutter/src/widgets/framework.dart:3730:27)
I/flutter (12075): #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3642:15)
I/flutter (12075): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5)
I/flutter (12075): #8 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2242:33)
I/flutter (12075): #9 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:626:20)
I/flutter (12075): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter (12075): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (12075): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (12075): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (12075): #14 _invoke (dart:ui/hooks.dart:120:13)
I/flutter (12075): #15 _drawFrame (dart:ui/hooks.dart:109:3)
I/flutter (12075): (elided 2 frames from class _AssertionError)
I/flutter (12075): ════════════════════════════════════════════════════════════════════════════════════════════════════

@lapauk
Copy link
Author

lapauk commented May 31, 2018

Yeah, I think that _normalizeMiddleValue can't be applied to the decimalValueInTheMiddle. Gotta be between 0 and 1 not the absolute min and max of the picker.

@lapauk
Copy link
Author

lapauk commented May 31, 2018

Replacing line 272 (_onDecimalNotification()) with

int _max = math.pow(10, decimalPlaces) - 1; decimalValueInTheMiddle = math.max(math.min(decimalValueInTheMiddle, _max), 0);

fixes it...

@MarcinusX
Copy link
Owner

Hey, thanks for submitting this!
I didn't manage to get the crash but you're right that normalization didn't work properly for decimal numbers. Can you confirm it is now fixed on master?

@lapauk lapauk closed this as completed Jun 4, 2018
@lapauk
Copy link
Author

lapauk commented Jun 4, 2018

Fixed

@MarcinusX
Copy link
Owner

Published version 0.1.4 with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants