Skip to content

SliverAppBar in CustomScrollView with shrinkWrap: true Scrolls Wrongly #52976

@feinstein

Description

@feinstein

As you can see on this video, CustomScrollView with shrinkWrap: true has it's scroll all weird, SliverAppBar goes up instead on down, the slivers bellow the SliverAppBar pass on top of it, this is a reproducible code:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<String> items = List.generate(10, (v) => v.toString());
    return Scaffold(
      body: CustomScrollView(
        shrinkWrap: true,
        physics: BouncingScrollPhysics(),
        slivers: <Widget>[
          SliverAppBar(pinned: true, title: Text('Test')),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                return ListItem(items[index]);
              },
              childCount: items.length,
            ),
          ),
        ],
      ),
    );
  }
}

class ListItem extends StatelessWidget {
  ListItem(this.value);

  final String value;

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: const EdgeInsets.all(16),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(8),
        side: BorderSide(
          color: Colors.red,
          width: 2,
        ),
      ),
      elevation: 0,
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Center(child: Text(value)),
      ),
    );
  }
}

My real code needs shrinkWrap: true otherwise I get rendering errors, so I am really stuck on this one.

This was the expected behavior.

I think #51078, #51077 and #36002 are related to this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.found in release: 1.22Found to occur in 1.22found in release: 1.26Found to occur in 1.26frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions