Skip to content

Slider's onChanged callback is fired several times under certain condition #143524

@gidrokolbaska

Description

@gidrokolbaska

Steps to reproduce

  1. Run the provided code sample;
  2. Place the cursor/finger between the thumb and previous division (exactly between, as seen on the attached video)
  3. Drag the cursor/finger to the left with a fast swing in such a way that the value is changed by 1;
  4. Inspect the output in the debug console.

Expected results

Well, it's pretty straightforward. onChanged callback should only be fired once. That is a serious bug that has been there, idk, forever?

Actual results

onChanged callback fired twice under certain condition.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(
        body: Center(
          child: SliderBug(),
        ),
      ),
    );
  }
}

class SliderBug extends StatefulWidget {
  const SliderBug({super.key});

  @override
  State<SliderBug> createState() => _SliderBugState();
}

class _SliderBugState extends State<SliderBug> {
  double sliderValue = 10;
  final double minValue = 2;
  final double maxValue = 12;
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text('${sliderValue.round()}'),
        Slider(
          min: 2,
          max: 12,
          divisions: (maxValue - minValue).round(),
          value: sliderValue,
          onChanged: (value) {
            print('onChanged');
            setState(() {
              sliderValue = value;
            });
          },
        ),
      ],
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

Here is the video:

2024-02-15.18.45.52.mov

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.3, on macOS 14.1.2 23B92 darwin-arm64, locale ru-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc4)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.86.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: material designflutter/packages/flutter/material repository.found in release: 3.19Found to occur in 3.19found in release: 3.20Found to occur in 3.20frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions