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

Method onChange is called when widget initializes #24

Closed
zjamshidi opened this issue Jun 19, 2020 · 4 comments
Closed

Method onChange is called when widget initializes #24

zjamshidi opened this issue Jun 19, 2020 · 4 comments

Comments

@zjamshidi
Copy link

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
Copy link
Author

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
Copy link
Owner

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

@ZantsuRocks
Copy link

For me either.

@matthewfx
Copy link
Owner

It has been fixed in v. 1.2

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

No branches or pull requests

3 participants