Skip to content

CupertinoSlider with null onChanged doesn't display as disabled #106691

Closed
flutter/packages
#13419

Description

@guidezpl

https://api.flutter.dev/flutter/cupertino/CupertinoSlider/onChanged.html claims that a CupertinoSlider with null onChanged will be displayed as disabled. That doesn't seem to be the case visually, even though interaction is disabled.

Activity

  1. added
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: cupertino_uicupertino_ui package in flutter/packages
    and removed
    in triagePresently being triaged by the triage team
    on Jun 28, 2022
  2. self-assigned this
    on Jun 28, 2022
  3. TahaTesser commented on Jun 28, 2022

    @TahaTesser
    Contributor

    @guidezpl
    Great catch! Here is a quick comparison between Flutter and iOS Storyboard (both disabled).

    Flutter iOS
    code sample
    import 'package:flutter/cupertino.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatefulWidget {
      const MyApp({super.key});
    
      @override
      State<MyApp> createState() => _MyAppState();
    }
    
    class _MyAppState extends State<MyApp> {
      double sliderValue = 50.0;
      bool enabled = true;
    
      @override
      Widget build(BuildContext context) {
        return CupertinoApp(
          title: 'Cupertino App',
          theme: const CupertinoThemeData(brightness: Brightness.light),
          home: CupertinoPageScaffold(
            navigationBar: const CupertinoNavigationBar(
              middle: Text('CupertinoSlider'),
            ),
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  CupertinoSlider(
                    value: sliderValue,
                    max: 100.0,
                    onChanged: enabled ? (double value) {
                      setState(() {
                        sliderValue = value;
                      });
                    } : null,
                  ),
                  const SizedBox(height: 100),
                  CupertinoButton.filled(
                    onPressed: () {
                      setState(() {
                        enabled = !enabled;
                      });
                    },
                    child:
                        Text('${enabled ? 'disable' : 'enable'} CupertinoSlider'),
                  )
                ],
              ),
            ),
          ),
        );
      }
    }
    
  4. removed their assignment
    on Oct 4, 2022
  5. added
    P2Important issues not at the top of the work list
    on Oct 20, 2022
  6. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 18, 2026
  7. LahaLuhem commented on Oct 28, 2026

    @LahaLuhem

    Screen readers miss it too. A disabled CupertinoSlider has no enabled state, so VoiceOver never says "dimmed", as it does for a disabled UISlider. flutter/packages#13419 dims it and flutter/packages#12710 keeps its value, but neither sets the enabled state.

    Widget test
    import 'package:cupertino_ui/cupertino_ui.dart';
    import 'package:flutter_test/flutter_test.dart';
    
    void main() {
      testWidgets('a disabled CupertinoSlider tells screen readers it is disabled', (tester) async {
        final semantics = tester.ensureSemantics();
        await tester.pumpWidget(
          const CupertinoApp(home: Center(child: CupertinoSlider(value: 0.5, onChanged: null))),
        );
    
        expect(
          tester.getSemantics(find.byType(CupertinoSlider)),
          // Fails: no enabled state.
          containsSemantics(isSlider: true, hasEnabledState: true, isEnabled: false),
        );
        semantics.dispose();
      });
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: cupertino_uicupertino_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-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