When I run this code, the ListView will have an unexpected top padding. (See screenshot) Why is that and is there a way to avoid this?
I already tried SliverOverlapAbsorber, SafeArea and MediaQuery to fix the padding, but so far nothing seems to work.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar(
pinned: true,
title: Text('Title'),
),
],
body: ListView.builder(
itemCount: 24,
itemBuilder: (context, index) => Container(
height: 40,
alignment: Alignment.center,
color: Colors.yellow,
margin: EdgeInsets.only(top: index != 0 ? 8 : 0),
child: Text('Body $index'),
),
),
),
);
}
}
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 11.5.1 20G80 darwin-x64, locale de-DE)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] IntelliJ IDEA Community Edition (version 2021.1.1)
[✓] VS Code (version 1.59.0)
[✓] Connected device (2 available)