matthewfx / sleek_circular_slider

Sleek circular slider for Flutter
MIT License
524 stars 102 forks source link

Method `onChange` is called when widget initializes #24

Closed zjamshidi closed 4 years ago

zjamshidi commented 4 years ago

I'm using SleekCircularSlider in a StreamBuilder to show the audio player's progress. Also, users could use the slider to seek the player. The problem is that method onChange is called even when the user is not selecting the slider. Here is my code:

  Widget positionIndicator(MediaItem mediaItem, PlaybackState state,
      AudioProcessingState processingState) {
    if (processingState == AudioProcessingState.none) {
      return SleekCircularSlider(
          appearance: CircularSliderAppearance(
              spinnerMode: true,
              size: 225,
              customWidths: CustomSliderWidths(trackWidth: 4, progressBarWidth: 13)));
    }
    double seekPos;
    return StreamBuilder(
      stream: Rx.combineLatest2<double, double, double>(
          _dragPositionSubject.stream,
          Stream.periodic(Duration(milliseconds: 200)),
              (dragPosition, _) => dragPosition),
      builder: (context, snapshot) {
        double position =
            snapshot.data ?? state.currentPosition.inMilliseconds.toDouble();
        double duration = mediaItem?.duration?.inMilliseconds?.toDouble();
        print("positionIndicator $position/$duration ${state.processingState}");
        return Column(
          children: [
            if (duration != null &&
                !(position == 0 && state.processingState != AudioProcessingState.ready))
              SleekCircularSlider(
                appearance: CircularSliderAppearance(
                    size: 225,
                    startAngle: 270,
                    angleRange: 360,
                    customWidths:
                    CustomSliderWidths(trackWidth: 4, progressBarWidth: 13)),
                min: 0.0,
                max: duration,
                initialValue: seekPos ?? max(0.0, min(position, duration)),
                innerWidget: (double percentage) => Text(''),
                onChange: (double value) {
                  print('on change');
                  _dragPositionSubject.add(value);
                },
                onChangeEnd: (value) {
                  print('on change end');
                  AudioService.seekTo(Duration(milliseconds: value.toInt()));
                  seekPos = value;
                  _dragPositionSubject.add(null);
                },
              ),
            if (duration == null ||
                (position == 0 && state.processingState != AudioProcessingState.ready))
              SleekCircularSlider(
                  appearance: CircularSliderAppearance(
                      spinnerMode: true,
                      size: 225,
                      customWidths:
                      CustomSliderWidths(trackWidth: 4, progressBarWidth: 13))),
          ],
        );
      },
    );
  }
zjamshidi commented 4 years ago

despite the documentation mentioned:

onChangeOnChange(double value) ... Called during a drag when the user is selecting a new value for the slider by dragging.

matthewfx commented 4 years ago

Hmm, that's strange... I will look into when I finally find time to work on it again :)

ZantsuRocks commented 4 years ago

For me either.

matthewfx commented 4 years ago

It has been fixed in v. 1.2