Home > Blockchain >  I am getting error when using slider in flutter
I am getting error when using slider in flutter

Time:10-10

I am getting this error when building my flutter app :

The return type 'Future*' isn't a 'void', as required by the closure's context

I am getting this error on some slider class

My code is like this:

Code:

Slider(
                value: position!.inMilliseconds.toDouble(),
                onChanged: (double value) {
                  return audioPlayer!.seek((value / 1000).roundToDouble());
                },
                min: 0.0,
                max: duration!.inMilliseconds.toDouble(),
              ),

CodePudding user response:

I guess the problem is at this line

onChanged: (double value) {
    return audioPlayer!.seek((value / 1000).roundToDouble());
},

Is audioPlayer!.seek returns a Future ? if so, that's what the error message is telling you, the function expected a void as a return type but you returned a Future. So change it to this:

onChanged: (double value) async {
    return await audioPlayer!.seek((value / 1000).roundToDouble());
},
  • Related