ListView in Material app scrolls to beginning when navigating: iPad only!
- Lenguaje dominante
- Dart
- Estrellas
- 179k
- Forks
- 31.1k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
### 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
```
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.