Skip to content

In reverse mode, the localToGlobal method of SliverMainAxisGroup's children returned incorrect positions. #159787

@yiiim

Description

@yiiim

Steps to reproduce

import 'package:flutter/material.dart';

GlobalKey key = GlobalKey();
void main() {
  runApp(
    MaterialApp(
      home: Scaffold(
        body: Align(
          alignment: Alignment.topLeft,
          child: SizedBox(
            height: 400,
            child: CustomScrollView(
              reverse: true,
              slivers: [
                SliverMainAxisGroup(
                  slivers: [
                    SliverToBoxAdapter(child: Container(height: 70, color: Colors.red)),
                    SliverToBoxAdapter(
                      child: SizedBox(
                        height: 20,
                        child: Text("1", key: key),
                      ),
                    ),
                    SliverToBoxAdapter(child: Container(height: 700, color: Colors.blue)),
                  ],
                ),
              ],
            ),
          ),
        ),
        floatingActionButton: IconButton(
          onPressed: () {
            RenderBox rb = key.currentContext!.findRenderObject() as RenderBox;
            print(rb.localToGlobal(Offset.zero));
          },
          icon: const Icon(Icons.add),
        ),
      ),
    ),
  );
}

Run the code above and click the button.

Expected results

Output: Offset(0.0, 310.0).

Actual results

Output: Offset(0.0, 70.0).

Screenshots or Video

image

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.27.0-1.0.pre.699, on macOS 15.1 24B83 darwin-arm64, locale zh-Hans-CN)
    ! Flutter version 3.27.0-1.0.pre.699 on channel [user-branch] at /Users/10906/source/repo/github/flutter
      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.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 16.1)
    ! CocoaPods 1.15.2 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
[✓] Android Studio (version 2024.1)
[✓] VS Code (version 1.95.3)
[✓] VS Code (version 1.94.2)
[!] Proxy Configuration
    ! NO_PROXY is not set
[✓] Connected device (5 available)
[✓] Network resources

! Doctor found issues in 3 categories.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.found in release: 3.24Found to occur in 3.24found in release: 3.27Found to occur in 3.27frameworkflutter/packages/flutter repository. See also f: labels.has partial patchThere is a PR awaiting someone to take it across the finish linehas reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions