rydmike / flex_color_picker

A highly customizable Flutter color picker.
BSD 3-Clause "New" or "Revised" License
200 stars 42 forks source link

The argument type 'double?' can't be assigned to the parameter type 'double' because 'double?' is nullable and 'double' isn't. iconSize: effectiveIconTheme.size, #40

Closed Sunsiha closed 2 years ago

Sunsiha commented 2 years ago

When I try to run the application getting this error.

../tools/flutter/.pub-cache/hosted/pub.dartlang.org/flex_color_picker-2.3.0/lib/src/widgets/color_picker_toolbar.dart:113:44: Error: The argument type 'double?' can't be assigned to the parameter type 'double' because 'double?' is nullable and 'double' isn't.
              iconSize: effectiveIconTheme.size,

Directly am not using this plugin. But one of the plugin(https://pub.dev/packages/html_editor_enhanced) is using this library. So not able to figure it out how to fix it.

rydmike commented 2 years ago

Hi @Sunsiha, thanks for the report. I'm looking at it. If you have a longer stack trace it might help.

Even better if you have a reproduction sample I can use to investigate the issue with.

All I can say for now is that, "that's odd, it should not be able to happen". But as soon as we can find the cause I'll make a fix of course.

I will also have to look at how the html_editor_enhanced package is using the picker, but however it is, it should not be possible to cause this error, but apparently it it is somehow.

rydmike commented 2 years ago

I am unable to reproduce the issue using the config used in https://github.com/tneotia/html-editor-enhanced/issues/225

as used here: https://github.com/tneotia/html-editor-enhanced/blob/31406a4c0d6df0e9e8833057828dd8bf116df355/lib/src/widgets/toolbar_widget.dart#L1115

I saw the issue mention here too https://github.com/tneotia/html-editor-enhanced/issues/225 tagging it for reference.

--

Continuing to look into the issue, but a full stack trace and repro sample would be nice. Please also add flutter doctor -v output of your from your project where the error occurs.

rydmike commented 2 years ago

The error message is a bit odd, because in all 5 references that exist in flex_color_picker, with the line:

iconSize: effectiveIconTheme.size,

Where the error message for line 113 is one of them:

./tools/flutter/.pub-cache/hosted/pub.dartlang.org/flex_color_picker-2.3.0
/lib/src/widgets/color_picker_toolbar.dart:**113**:44: 
Error: The argument type 'double?' can't be assigned to the parameter type 'double' 
because 'double?' is nullable and 'double' isn't.

           `iconSize: effectiveIconTheme.size,`

The message is odd, since iconSize as part of Flutter SDK, in used IconButton certainly is nullable:

image

Strange, I must be missing something, but it looks like Flutter source for the Flutter IconButton you use would be from a very old version that is not the null safe version and it is thus missing ? :

  /// The size of the icon inside the button.
  ///
  /// If null, uses [IconThemeData.size]. If it is also null, the default size
  /// is 24.0.
  ///
  /// The size given here is passed down to the widget in the [icon] property
  /// via an [IconTheme]. Setting the size here instead of in, for example, the
  /// [Icon.size] property allows the [IconButton] to size the splash area to
  /// fit the [Icon]. If you were to set the size of the [Icon] using
  /// [Icon.size] instead, then the [IconButton] would default to 24.0 and then
  /// the [Icon] itself would likely get clipped.
  final double? iconSize;

Still that sounds weird, but I'm almost inclined to suggest you should try to do this:

flutter clean
flutter upgrade
flutter pub get
flutter pub upgrade

First and see if it helps. Plus to make sure your IDE is using and pointing to the Flutter version you have installed and that actually gets upgraded when you run flutter upgrade. Or if you are using fvm in your IDE setup, to make sure it is pointed to a fvm installed flutter version that is up to date too.

Maybe I'm fishing here and missing something, but I just can replicate your issue in my Flutter environment setup.

vietlinhtspt commented 2 years ago

Meet the same problem.

rydmike commented 2 years ago

@vietlinhtspt thanks for letting me know, can you send a link to a minimum repo setup that replicates the issue?

I would love to see the issue too, but I have been unable to replicate it. Before I apply a fix for it I would like to see and understand what condition creates the issue, because it should not really happen at all based on the analysis I've made of it, but maybe I missed something. Also I need to be able to replicate the issue to make sure it has been fixed with applied fix.

vietlinhtspt commented 2 years ago

@Sunsiha I meet this problem in Flutter 2.8.1, after upgrading to Flutter 2.10.2 it works properly.

rydmike commented 2 years ago

Hi @vietlinhtspt, thanks for that info. That is quite interesting though, because there is nothing in the reported error message that would indicate it should not work exactly the in 2.8.1 and I have not been able to reproduce the issue. But OK I think my tests were all with 2.10.x, I can certainly try my own test case with a downgrade to 2.8.1 one too. Using fvm it is easy enough to switch versions.

If I'm interpreting the very brief error report correctly, a situation that would cause this error should only happen if for some reason Flutter SDK was at version before 2.0.0 and Dart SDK below 2.12.0 which were none null safe version. Those versions are however not even supported by the package constraints since Dart SDK >= 2.12.0 is required and first Flutter version with it is 2.0.0,

This is the reason why I think the reported error is a bit surprising. You can read more about that in submitted PR here https://github.com/rydmike/flex_color_picker/pull/41. There is a simple fix in the PR too, but it is kind of work around, for a problem that as far as I can see should not even exist, and as said I have not seen the issue in my tests

But OK I will try I with 2.8.1 and see if I can get the error then too, even if I don't I can merge the PR and do the edits to make it pass the CI/CD Dartfmt style checks too. It is just that if I can't repeat the error I cannot really test if the fix works. So if somebody has a code repo for a minimum reproduction sample, that would help, since then I can first verify that I can repeat the error and that it is gone after the fix. Without that I'm just applying a fix, for a problem that should no exist, but somehow does, that I cannot repeat, and I put the fix in but can't know that it works, only that in theory it certainly looks like it should, if the problem happens that should not be able to happen in the first place. 😃 lol

rydmike commented 2 years ago

Thanks @vietlinhtspt, the info that there was an issue in Flutter 2.8.1 but not in 2.10.x builds helped. Interstingly iconSize is nullable in 2.10.x but not in e.g. 2.8.1. Weird, I tried to track down how long that has been the case, since it should have been an issue long before for me too

In any case, I merged the fix, made minor dartfmt update to be able to get it trough its dartfmt CI/CD verification. Tested and verified that the fix, works OK in both 2.8.1 and 2.10.x. Fixed version is available on pub.dev now https://pub.dev/packages/flex_color_picker/changelog

Thank you all for your help and feedback. Issue closed via https://github.com/rydmike/flex_color_picker/pull/41