Skip to content

PageView.onPageChanged not called for first Page #37656

Closed

Description

@feinstein

The PageView.onPageChanged has the following documentation:

Called whenever the page in the center of the viewport changes.

On my tests I can see that it does notify every time the page changes... BUT it doesn't notify when the first page is loaded for the first time. As I understand it, it should notify also when the first page loads for the first time, as it qualifies as a "page in the center of the viewport change".

Activity

  1. karabaralex commented on Sep 7, 2019

    @karabaralex

    very annoying issue, any updates on that?

  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Sep 19, 2019
  3. VladyslavBondarenko commented on Jul 31, 2020

    @VladyslavBondarenko

    Persists with current master 1.21.0-6.0.pre.129

    code sample
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: Scaffold(
            body: PageViewDemo(),
          ),
        );
      }
    }
    
    class PageViewDemo extends StatefulWidget {
      @override
      _PageViewDemoState createState() => _PageViewDemoState();
    }
    
    class _PageViewDemoState extends State<PageViewDemo> {
    
      PageController _controller = PageController(
        initialPage: 0,
      );
    
      @override
      void dispose() {
        _controller.dispose();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return PageView(
          controller: _controller,
          onPageChanged: (index) {
            print('Current page - $index');
          },
          children: List.generate(3, (index) => Center(child: Text(index.toString()))),
        );
      }
    }
    
    flutter doctor -v
    [✓] Flutter (Channel master, 1.21.0-6.0.pre.129, on Mac OS X 10.15.6 19G73, locale en-GB)
        • Flutter version 1.21.0-6.0.pre.129 at /Users/nevercode/dev/flutter
        • Framework revision 30aef0a3b9 (14 hours ago), 2020-07-30 14:20:21 -0700
        • Engine revision a9910e409c
        • Dart version 2.10.0 (build 2.10.0-1.0.dev 24c7666def)
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
        • Android SDK at /Users/nevercode/Library/Android/sdk
        • Platform android-29, build-tools 29.0.3
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 11.6)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 11.6, Build version 11E708
        • CocoaPods version 1.9.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 47.1.2
        • Dart plugin version 193.7361
        • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    
    [✓] VS Code (version 1.47.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.12.2
    
    [✓] Connected device (6 available)
        • Redmi Note 7 (mobile)       • 6345c469                                 • android-arm64  • Android 9 (API 28)
        • Nevercode’s iPhone (mobile) • b668e524315069f3db3661ac11ff1f66afafebdb • ios            • iOS 13.6
        • iPhone 11 Pro Max (mobile)  • 55C8466B-5367-492B-8EFE-EC45D980571F     • ios            • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
        • macOS (desktop)             • macos                                    • darwin-x64     • Mac OS X 10.15.6 19G73
        • Web Server (web)            • web-server                               • web-javascript • Flutter Tools
        • Chrome (web)                • chrome                                   • web-javascript • Google Chrome 84.0.4147.105
    
    • No issues found!
    
  4. maheshj01 commented on Jun 30, 2022

    @maheshj01
    Member

    Hi @feinstein, I can no longer reproduce it, With the above code sample when I swipe left I see onPageChanged gets triggered (on the first swipe).

    flutter doctor -v (mac)
    [✓] Flutter (Channel stable, 3.0.3, on macOS 12.4 21F79 darwin-arm, locale en-IN)
        • Flutter version 3.0.3 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 676cefaaff (5 days ago), 2022-06-22 11:34:49 -0700
        • Engine revision ffe7b86a1e
        • Dart version 2.17.5
        • DevTools version 2.12.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-32, build-tools 33.0.0-rc4
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2021.2)
        • 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 11.0.12+0-b1504.28-7817840)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.67.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.43.20220621
    
    [✓] Connected device (3 available)
        • sdk gphone arm64 (mobile) • emulator-5554 • android-arm64  • Android 11 (API 30) (emulator)
        • macOS (desktop)           • macos         • darwin-arm64   • macOS 12.4 21F79 darwin-arm
        • Chrome (web)              • chrome        • web-javascript • Google Chrome 103.0.5060.53
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
  5. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 30, 2022
  6. github-actions commented on Jul 21, 2022

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.
    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.
    Thanks for your contribution.

  7. added
    r: timeoutIssue is closed due to author not providing the requested details in time
    and removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 1, 2022
  8. github-actions commented on Aug 15, 2022

    @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.

  9. locked as resolved and limited conversation to collaborators on Aug 15, 2022
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

    found in release: 1.21Found to occur in 1.21frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: timeoutIssue is closed due to author not providing the requested details in time

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions