FlutterSlider range onDragging Missing parameter type

Issue

I am trying to use FlutterSlider (another_xlider). The following code in the IDE is flagging both lowerValue and upperValue with Missing parameter type. I am prompted to try adding an explicit type, or remove implicit-dynamic from your analysis options file. The latter I am loathe to do. I have tried the former, but am apparently getting it wrong.

Here is my current code.

                            values: const [1000, 4000],
                            rangeSlider: true,
                            max: 10000,
                            min: 500,
                            onDragging: (handlerIndex, lowerValue, upperValue) {
                              _lowerValue = lowerValue is int ? lowerValue : 0;
                              _upperValue = upperValue is int ? upperValue : 0;
                              setState(() {});
                            },
                          )

If I try setting an explicit type as below, I get The argument type ‘Null Function(int, int, int)’ can’t be assigned to the parameter type ‘dynamic Function(int*, dynamic, dynamic)

                              _lowerValue = lowerValue;
                              _upperValue = upperValue;
                              setState(() {});
                            },
                          )

The function signature is dynamic Function(int*, dynamic, dynamic)*. I need to research what those asterisks mean – having only used them with yield statements – so I presume that is part of the issue.

FWIW – This is nearly identical to the example in the another_xlider documentation at https://pub.dev/packages/another_xlider/example (sample below).

  values: [30, 420],
  rangeSlider: true,
  max: 500,
  min: 0,
  onDragging: (handlerIndex, lowerValue, upperValue) {
    _lowerValue = lowerValue;
    _upperValue = upperValue;
    setState(() {});
  },
)

Googling has not helped thus far. What am I missing?

UPDATE
I created my project using Very Good Cli (see https://verygood.ventures/blog/flutter-starter-app-very-good-core-cli). While trying to debug, I pulled down the another_xlider project and the problem was not presenting. I created a brand new project using Very Good Cli, copied over the MyApp class, and the problem was presenting again. So, I copied over all the dependencies in the Very Good project to my non-VGC project and updated. No problem. It appears there is something fundamental about the way a VGC project is created that is causing the problem. However, as time is of the essence and in the meantime having found the built-in Flutter RangeSlider fills my needs, I am no longer concerned about this. That said, I would like to know what it is with Very Good Cli that caused this problem. Next time there might not be an easy alternative.

Solution

I just took a look at it looks like the onDragging callback indicates lowerValue and upperValue are of type dynamic (https://github.com/loonix/another_xlider/blob/7fa4c15a4362d25ecf8e2552e27e5799024c715f/lib/another_xlider.dart#L27). As a result, you need to both specify the dynamic type explicitly to avoid the implicit_dynamic issue and also cast the value as a double (if you are sure it should be a double). The following code reports no analysis errors with the latest version of very_good_cli:

onDragging: (
  handlerIndex,
  dynamic lowerValue,
  dynamic upperValue,
) {
  setState(() {
    _lowerValue = lowerValue as double;
    _upperValue = upperValue as double;
  });
},

Answered By – Felix Angelov

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *