Skip to content

Add feature to change z-order of slivers (paint order, hit-test order) #145592

@jellynoone

Description

@jellynoone

Steps to reproduce

  1. Run the example
  2. Switch the page from mainAxisPage to pageThroughSlivers
    2.1. hot reload
    2.2. observe no changes
  3. Switch the page from pageThroughSlivers to pageThroughList
    3.1. hot reload
    3.2. observe a different display

Expected results

I expect all of these examples to produce the same result, but they don't.
The blue box rendered by mainAxisPage and pageThroughSlivers should be above the brown one like it is for pageThroughList.

Actual results

The actual result is that the brown box is rendered above the blue one for mainAxisPage and pageThroughSlivers.

It seems, when using slivers that wrap box widgets, the slivers are painted in reverse order.

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) {
    const mainAxisPage = MainAxisGroupPage();
    const pageThroughSlivers = PageThroughSlivers();
    const pageThroughList = PageThroughList();

    return const MaterialApp(
      home: mainAxisPage,
    );
  }
}

const _brown = ColoredBox(
  color: Colors.brown,
  child: SizedBox(height: 100),
);
final _blue = Transform.translate(
  offset: const Offset(0, -50),
  child: const ColoredBox(
    color: Color(0xcc0000ff),
    child: SizedBox(height: 100),
  ),
);

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(slivers: [
        SliverMainAxisGroup(slivers: [
          const SliverToBoxAdapter(child: _brown),
          SliverToBoxAdapter(child: _blue),
        ]),
      ]),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(slivers: [
        const SliverToBoxAdapter(child: _brown),
        SliverToBoxAdapter(child: _blue),
      ]),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(slivers: [
        SliverList.list(children: [
          _brown,
          _blue,
        ]),
      ]),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.19.3, on macOS 14.4 23E214 darwin-arm64, locale en-SI)
    • Flutter version 3.19.3 on channel stable at /Users/.../Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ba39319843 (2 weeks ago), 2024-03-07 15:22:21 -0600
    • Engine revision 2e4ba9c6fb
    • Dart version 3.3.1
    • DevTools version 2.31.1

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/.../Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15E204a
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • 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 17.0.7+0-17.0.7b1000.6-10550314)

[✓] VS Code (version 1.88.0-insider)
    • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents
    • Flutter extension version 3.84.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.4 23E214 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 123.0.6312.58

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

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityd: api docsIssues with https://api.flutter.dev/f: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.team-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