Skip to content

[Material 3] Using NestedScrollView with SliverAppBar makes content go behind it, even though it fits on the screen. #104440

@doiraduc

Description

@doiraduc

Part of #104363.

When using the new variants SliverAppBar.medium and SliverAppBar.large in a NestedScrollView without using SliverOverlapAbsorber and SliverOverlapInjector, content goes behind the SliverAppBar even though it fits on the screen. This behavior does not occur when using SliverAppBar in a CustomScrollView.

Expected result:

  • The SliverList children should not go under the SliverAppBar when they all fit on the screen (when scrolling, only the expanded title should collapse, the SliverList children should not go under the collapsed SliverAppBar).

Actual result:

  • The SliverList children go under the SliverAppBar when collapsing instead of remaining on the screen, though they fit the current layout.
nestedscrollview.1.mp4
Code sample:
import 'package:flutter/material.dart';

void main() {
  runApp(const TestApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.from(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: Scaffold(
        body: NestedScrollView(
          headerSliverBuilder: (context, innerBoxIsScrolled) => [
            SliverAppBar.large(
              title: const Text('Example App'),
              forceElevated: innerBoxIsScrolled,
            ),
          ],
          body: CustomScrollView(
            slivers: [
              SliverList(
                delegate: SliverChildBuilderDelegate(
                  (context, index) {
                    return ListTile(
                      title: Text('Item ${index.toString()}'),
                    );
                  },
                  childCount: 5,
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions