Skip to content

CupertinoPicker should report item change only on scroll end #170201

Closed

Description

@alex-medinsh

This is a continuation of #169606

Steps to reproduce

Scroll the picker over multiple items.

Expected results

Native picker only reports the change when the scroll settles.

Actual results

onSelectedItemChanged is called every time a new item is scrolled over.

Code sample

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

/// Flutter code sample for [CupertinoPicker].

const double _kItemExtent = 32.0;
const List<String> _fruitNames = <String>[
  'Apple',
  'Mango',
  'Banana',
  'Orange',
  'Pineapple',
  'Strawberry',
];

void main() => runApp(const CupertinoPickerApp());

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

  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(
      theme: CupertinoThemeData(brightness: Brightness.light),
      home: CupertinoPickerExample(),
    );
  }
}

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

  @override
  State<CupertinoPickerExample> createState() => _CupertinoPickerExampleState();
}

class _CupertinoPickerExampleState extends State<CupertinoPickerExample> {
  int _selectedFruit = 0;

  // This shows a CupertinoModalPopup with a reasonable fixed height which hosts CupertinoPicker.
  void _showDialog(Widget child) {
    showCupertinoModalPopup<void>(
      context: context,
      builder:
          (BuildContext context) => Container(
            height: 216,
            padding: const EdgeInsets.only(top: 6.0),
            // The Bottom margin is provided to align the popup above the system navigation bar.
            margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
            // Provide a background color for the popup.
            color: CupertinoColors.systemBackground.resolveFrom(context),
            // Use a SafeArea widget to avoid system overlaps.
            child: SafeArea(top: false, child: child),
          ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      navigationBar: const CupertinoNavigationBar(middle: Text('CupertinoPicker Sample')),
      child: DefaultTextStyle(
        style: TextStyle(color: CupertinoColors.label.resolveFrom(context), fontSize: 22.0),
        child: Center(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text('Selected fruit: '),
              CupertinoButton(
                padding: EdgeInsets.zero,
                // Display a CupertinoPicker with list of fruits.
                onPressed:
                    () => _showDialog(
                      CupertinoPicker(
                        magnification: 1.22,
                        squeeze: 1.2,
                        useMagnifier: true,
                        itemExtent: _kItemExtent,
                        // This sets the initial item.
                        scrollController: FixedExtentScrollController(initialItem: _selectedFruit),
                        // This is called when selected item is changed.
                        onSelectedItemChanged: (int selectedItem) {
                          setState(() {
                            _selectedFruit = selectedItem;
                          });
                        },
                        children: List<Widget>.generate(_fruitNames.length, (int index) {
                          return Center(child: Text(_fruitNames[index]));
                        }),
                      ),
                    ),
                // This displays the selected fruit name.
                child: Text(_fruitNames[_selectedFruit], style: const TextStyle(fontSize: 22.0)),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[!] Flutter (Channel [user-branch], 3.33.0-1.0.pre.417, on macOS 15.5 24F74 darwin-arm64, locale en-GB) [8.3s]
    ! Flutter version 3.33.0-1.0.pre.417 on channel [user-branch] at /Users/alex/workspace/flutter_fork
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
    ! Upstream repository https://github.com/flutter/flutter.git/ is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to https://github.com/flutter/flutter.git/ to dismiss this error.
    • Framework revision e9e989bef3 (5 hours ago), 2025-06-07 07:45:31 -0400
    • Engine revision e9e989bef3
    • Dart version 3.9.0 (build 3.9.0-211.0.dev)
    • DevTools version 2.48.0-dev.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and
      upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.1s]
    • Android SDK at /Users/alex/Library/Android/sdk
    • Emulator version 35.2.10.0 (build_id 12414864) (CL:N/A)
    • Platform android-36, build-tools 35.0.0
    • ANDROID_HOME = /Users/alex/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 16.4) [1,360ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    ! CocoaPods 1.13.0 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) [13ms]
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2024.2) [12ms]
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.100.3) [10ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.112.0

[✓] Connected device (3 available) [7.0s]
    • Alex’s iPhone (wireless) (mobile) • 00008130-001A310C0491401C            • ios          • iOS 18.5 22F76
    • iPhone 16 Pro (mobile)            • CA350618-1F12-428B-ABB3-9D688B09D1F4 • ios          • com.apple.CoreSimulator.SimRuntime.iOS-18-5 (simulator)
    • macOS (desktop)                   • macos                                • darwin-arm64 • macOS 15.5 24F74 darwin-arm64

[✓] Network resources [856ms]
    • All expected network resources are available.

! Doctor found issues in 3 categories.

Activity

  1. danagbemava-nc commented on Jun 9, 2025

    @danagbemava-nc
    Member

    Reproducible (as noted in the #169606).

    flutter doctor -v
    [✓] Flutter (Channel stable, 3.32.2, on macOS 15.5 24F74 darwin-arm64, locale en-US) [449ms]
        • Flutter version 3.32.2 on channel stable at /Users/deanli/dev/stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 8defaa71a7 (5 days ago), 2025-06-04 11:02:51 -0700
        • Engine revision 1091508939
        • Dart version 3.8.1
        • DevTools version 2.45.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,451ms]
        • Android SDK at /Users/deanli/Library/Android/sdk
        • Platform android-36, build-tools 36.0.0
        • Java binary at: /Users/deanli/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,008ms]
        • Xcode at /Applications/Xcode-16.4.0-Beta.app/Contents/Developer
        • Build 16F1t
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [8ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2025.1) [8ms]
        • Android Studio at /Users/deanli/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)
    
    [✓] VS Code (version 1.100.0) [7ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.110.0
    
    [✓] Connected device (5 available) [6.5s]
        • Dean’s iPad (wireless) (mobile)       • 00008103-000825C811E3401E • ios            • iOS 18.5 22F76
        • iPhone 16 Pro Max (wireless) (mobile) • 00008140-00194CC23A68801C • ios            • iOS 18.5 22F76
        • Nexus (wireless) (mobile)             • 00008020-001875E83A38002E • ios            • iOS 18.5 22F76
        • macOS (desktop)                       • macos                     • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
        • Chrome (web)                          • chrome                    • web-javascript • Google Chrome 137.0.7151.69
        ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [1,601ms]
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.33.0-1.0.pre.417, on macOS 15.5 24F74 darwin-arm64, locale en-US) [3.0s]
        • Flutter version 3.33.0-1.0.pre.417 on channel master at /Users/deanli/dev/master
        ! Warning: `flutter` on your path resolves to /Users/deanli/dev/stable/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/deanli/dev/stable/bin/dart, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision e9e989bef3 (2 days ago), 2025-06-07 07:45:31 -0400
        • Engine revision e9e989bef3
        • Dart version 3.9.0 (build 3.9.0-211.0.dev)
        • DevTools version 2.48.0-dev.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,418ms]
        • Android SDK at /Users/deanli/Library/Android/sdk
        • Emulator version 35.6.9.0 (build_id 13473012) (CL:N/A)
        • Platform android-36, build-tools 36.0.0
        • Java binary at: /Users/deanli/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,017ms]
        • Xcode at /Applications/Xcode-16.4.0-Beta.app/Contents/Developer
        • Build 16F1t
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [8ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2025.1) [8ms]
        • Android Studio at /Users/deanli/Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 21.0.6+-13391695-b895.109)
    
    [✓] VS Code (version 1.100.0) [7ms]
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.110.0
    
    [✓] Connected device (5 available) [6.3s]
        • Dean’s iPad (wireless) (mobile)       • 00008103-000825C811E3401E • ios            • iOS 18.5 22F76
        • iPhone 16 Pro Max (wireless) (mobile) • 00008140-00194CC23A68801C • ios            • iOS 18.5 22F76
        • Nexus (wireless) (mobile)             • 00008020-001875E83A38002E • ios            • iOS 18.5 22F76
        • macOS (desktop)                       • macos                     • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
        • Chrome (web)                          • chrome                    • web-javascript • Google Chrome 137.0.7151.69
        ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [940ms]
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: cupertino_uicupertino_ui package in flutter/packages
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Jun 9, 2025
  3. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Jun 11, 2025
  4. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 18, 2025
  5. github-actions commented on Jul 2, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Jul 2, 2025
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 listfound in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagesr: 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