Skip to content

NestedScrollView + ListView in iOS13 scroll bug #43086

Closed
@epoll-j

Description

@epoll-j

Hello guys,
I wrote a very basic page that has a NestedScrollView and a SliverAppBar and some listview wrapped inside tab.
Whenever I scrolling the page, it will often reset position to the top in iOS13, but it's normal in Android.

It look like this:
avatar

my code:

import 'package:flutter/material.dart';

class TestPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _TestPageState();

}

class _TestPageState extends State<TestPage> with TickerProviderStateMixin {
  ScrollController _scrollViewController =
  ScrollController(initialScrollOffset: 0.0);

  TabController _tabController;

  @override
  Widget build(BuildContext context) {
    _tabController = TabController(length: 4, vsync: this);
    return Scaffold(
      appBar: AppBar(
        title: const Text("title"),
      ),
      body: _buildBody(context),
    );
  }

  Widget _buildBody(BuildContext context) {
    List<String> _tabList = ["1", "2", "3", "4"];

    return NestedScrollView(
      controller: _scrollViewController,
      headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
        return <Widget>[
          SliverAppBar(
            pinned: true,
            floating: true,
            forceElevated: boxIsScrolled,
            backgroundColor: Colors.white,
            flexibleSpace: FlexibleSpaceBar(
              collapseMode: CollapseMode.pin,
              background: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Center(
                    child: Container(
                      height: 100,
                      width: 200,
                      color: Colors.blue,
                    ),
                  ),
                  Center(
                    child: Container(
                      height: 100,
                      width: 200,
                      color: Colors.red,
                    ),
                  ),
                  Center(
                    child: Container(
                      height: 100,
                      width: 200,
                      color: Colors.green,
                    ),
                  ),
                  Center(
                    child: Container(
                      height: 100,
                      width: 200,
                      color: Colors.yellow,
                    ),
                  )
                ],
              ),
            ),
            expandedHeight: 470,
            bottom: PreferredSize(
                child: TabBar(
                    controller: _tabController,
                    tabs: _tabList.map((item) {
                      return Tab(
                        child: Text(item, style: TextStyle(color: Colors.green),),
                      );
                    }).toList()),
                preferredSize: Size(double.infinity, 60)),
          )
        ];
      },
      body: TabBarView(
        controller: _tabController,
        children: _tabList.map((_) {
          return Center(
            child: ListView.builder(
              itemBuilder: (content, index) {
                return Center(
                  child: Text("$index"),
                );
              },
              itemCount: 100,
            ),
          );
        }).toList(),
      ),
    );
  }
}

fultter doctor:

[✓] Flutter (Channel stable, v1.9.1+hotfix.5, on Mac OS X 10.15 19A583, locale zh-Hans-CN)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 11.1)
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2019.1.4)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.39.2)
[✓] Connected device (1 available)

Activity

added
f: scrollingViewports, list views, slivers, etc.
frameworkflutter/packages/flutter repository. See also f: labels.
platform-iosiOS applications specifically
on Oct 21, 2019
iapicca

iapicca commented on Oct 21, 2019

@iapicca
Contributor

Hi @dubhe-jk
you might want to use a SliverList instead of a ListView.builder
Here's some documentation [1, 2]that can help your case

added
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Oct 21, 2019
epoll-j

epoll-j commented on Oct 21, 2019

@epoll-j
Author

Thank you for your answer @iapicca
but how to use SliverList with TabBarView

removed
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Oct 21, 2019
epoll-j

epoll-j commented on Oct 21, 2019

@epoll-j
Author

Hi @iapicca
I try to useSliverList wrapped insideCustomScrollView inTabBarView , this problem still exists.

wangfengnan

wangfengnan commented on Oct 25, 2019

@wangfengnan

same problem!

Tecode

Tecode commented on Jan 9, 2020

@Tecode

try NestedScrollView set physics ClampingScrollPhysics
NestedScrollView( physics: ClampingScrollPhysics(), body:Text(''), )

iapicca

iapicca commented on Mar 16, 2020

@iapicca
Contributor

Hi all
if @Tecode solution
doesn't work for you and you are experiencing the issue
with the latest stable version of flutter
can you please provide your update flutter doctor -v ,
your flutter run --verbose
and a reproducible minimal code sample.
Thank you

added
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Mar 16, 2020
xiechunyan

xiechunyan commented on Mar 27, 2020

@xiechunyan

There is still a problem on the iphone after adding physics. Is there a solution?

RockinPaul

RockinPaul commented on Mar 27, 2020

@RockinPaul

There is still a problem on the iphone after adding physics. Is there a solution?

Hello! Regarding @Tecode solution which doesn't work for me either - try to set ClampingScrollPhysics to a nested ListView, but not NestedScrollView itself. This is the only workaround I found for now.

xiechunyan

xiechunyan commented on Mar 27, 2020

@xiechunyan

I've tried to do this before, but if you use it in the nested ListView, the iphone's sliding feature is gone.Is there any other solution?

removed
waiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds
on Mar 27, 2020
VladyslavBondarenko

VladyslavBondarenko commented on May 6, 2020

@VladyslavBondarenko

Hi @RockinPaul
Does the issue persist?
I can't reproduce it with iOS 13.4.5 on dev 1.18.0-10.0.pre

RockinPaul

RockinPaul commented on May 21, 2020

@RockinPaul

Hi @VladyslavBondarenko,
It seems to be fixed, I can't reproduce it as well.

VladyslavBondarenko

VladyslavBondarenko commented on May 21, 2020

@VladyslavBondarenko

oh, I accidentally tagged not the author)
Closing. If somebody still experiences the issue - feel free to comment or file a new issue

rafdls

rafdls commented on Jun 11, 2020

@rafdls

Hi @RockinPaul
Does the issue persist?
I can't reproduce it with iOS 13.4.5 on dev 1.18.0-10.0.pre

This problem still exists in the stable version though: Flutter v1.17.3

iapicca

iapicca commented on Jul 20, 2020

@iapicca
Contributor

Could everyone who still has this problem please file a new issue with the exact description of 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 related issues.

AcmeField

AcmeField commented on Jul 29, 2020

@AcmeField

添加物理后,iphone上仍然存在问题。有解决方案吗?

你好!关于对我也不起作用的@Tecode解决方案-尝试将ClampingScrollPhysics设置为嵌套的ListView,而不是NestedScrollView本身。这是我目前发现的唯一解决方法。

nice , got it

lyz15

lyz15 commented on Aug 10, 2020

@lyz15

这个问题还没修复吗?可不可以贴一个终极解决方法的代码?

github-actions

github-actions commented on Aug 17, 2021

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

locked as resolved and limited conversation to collaborators on Aug 17, 2021
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

    e: OS-version specificAffects only some versions of the relevant operating systemf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.platform-iosiOS applications specifically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @RockinPaul@rafdls@wangfengnan@janmoppel@VladyslavBondarenko

        Issue actions

          NestedScrollView + ListView in iOS13 scroll bug · Issue #43086 · flutter/flutter