flutter / flutter/flutter

ListView in Material app scrolls to beginning when navigating: iPad only!

Open
#183,003 2 comments 0 reactions 0 assignees View on GitHub
f: scrolling framework has reproducible steps P2 platform-ios team-framework triaged-framework
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Steps to reproduce

Use code below:
A MaterialApp() with ListView() using emulator for iPad.

### Expected results

When returning for navigation, the scrollbar should "stay put".

### Actual results

On iPad it sporadic scrolls to the top after returning for navigation and some times on setState().

This does not appear on iPhone or Android emulators.

### Code sample

After publishing this bug, I found a video regarding the "primary" flag for ListView:
https://www.youtube.com/watch?v=33_0ABjFJUU

In iPad tapping the appBar = scroll to top
In iPhone tapping the appBar = no action

Setting primary = false will make this bug (feature?) go away.
This also disabled the push to scroll to top on iOS completely (since it will not find the scrollcontroller).

Code sample

```dart
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
State createState() => _MyAppState();
}

class _MyAppState extends State {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pagestorage iPad bug',
theme: ThemeData(colorScheme: .fromSeed(seedColor: Colors.deepPurple)),
home: Scaffold(
appBar: AppBar(title: Text("Pagestorage iPad bug")),
extendBody: true,
body: Column(
children: [
OutlinedButton(
onPressed: () => setState(() {}),
child: Text("Reload"),
),
Expanded(
child: Center(
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: 600),
child: ListView.builder(
// primary: false,
restorationId: "list",
itemCount: 200,
itemBuilder: (context, i) {
return Card(
child: ListTile(
title: Text(
"Item $i",
style: Theme.of(context).textTheme.titleLarge,
),
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(title: Text("Item $i")),
body: const Placeholder(),
),
),
);
},
),
);
},
),
),
),
),
],
),
),
);
}
}
```

### Screenshots or Video

Screenshots / Video demonstration

See video in iPad (resets to 0 scrollposition some times):

See video on iPhone (works as expected):

### Logs

Logs

```console
No logs for this
```

### Flutter Doctor output

Doctor output

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.41.2, on macOS 26.3 25D125 darwin-arm64, locale nb-NO)
[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0)
[✓] Xcode - develop for iOS and macOS (Xcode 26.2)
[✓] Chrome - develop for the web
[✓] Connected device (4 available)
[✓] Network resources
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.