-
Taha Tesser authored
fixes [AnimatedList does not take SafeArea into account when building the list ](https://github.com/flutter/flutter/issues/129539) ### Description This PR fixes an issue for `AnimatedList` & `AnimatedGrid` where `MediaQuery` padding isn't applied. See the [source](https://github.com/flutter/flutter/blob/a20db068dd9f72e2e4a35a3ce64f22d47b3d20f7/packages/flutter/lib/src/widgets/scroll_view.dart#L803-L833). While the `ListView` or `GridView` applies `MediaQuery` padding to its inner `SliverPadding`. This is missing from `AnimatedList` & `AnimatedGrid`. ![Digram of ListView applying MediaQuery padding](https://github.com/flutter/flutter/assets/48603081/01917900-cd26-4ca1-8e51-b7dcd1241471) The fix applies `MediaQuery` padding to the inner `SliverPadding` in `AnimatedList` & `AnimatedGrid`. ![Digram of AnimatedList & AnimatedGrid applying MediaQuery padding](https://github.com/flutter/flutter/assets/48603081/75d0a0ad-539c-485e-b3c1-770ee187086b) ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(useMaterial3: true), home: const Example(), ); } } class Example extends StatelessWidget { const Example({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Sample'), ), body: Row( children: <Widget>[ Expanded( child: Column( children: <Widget>[ const Text('ListView'), Expanded( child: ListView.builder( itemCount: 50, itemBuilder: (_, int index) { return ColoredBox( color: Theme.of(context).colorScheme.primaryContainer, child: Center( child: Text('$index', textAlign: TextAlign.center), ), ); }, ), ), ], ), ), const VerticalDivider(width: 4), Expanded( child: Column( children: <Widget>[ const Text('AnimatedList'), Expanded( child: AnimatedList( initialItemCount: 50, itemBuilder: (_, int index, __) { return ColoredBox( color: Theme.of(context).colorScheme.primaryContainer, child: Center( child: Text('$index', textAlign: TextAlign.center), ), ); }, ), ), ], ), ), const VerticalDivider(width: 4), Expanded( child: Column( children: <Widget>[ const Text('AnimatedGrid'), Expanded( child: AnimatedGrid( initialItemCount: 50, gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( crossAxisCount: 2, ), itemBuilder: (_, int index, __) { return ColoredBox( color: Theme.of(context).colorScheme.primaryContainer, child: Center( child: Text('$index', textAlign: TextAlign.center), ), ); }, ), ), ], )) ], ), ); } } ``` </details> ### Before ![Before preview image](https://github.com/flutter/flutter/assets/48603081/73954a8a-9d1d-4b9e-b6a3-cae8071f3462) ### After ![After preview image](https://github.com/flutter/flutter/assets/48603081/9f1dc48a-622f-4402-8d5e-8e6e3e150165)
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
lib | ||
test | ||
test_fixes | ||
test_private | ||
test_profile | ||
test_release | ||
LICENSE | ||
README.md | ||
analysis_options.yaml | ||
build.yaml | ||
dart_test.yaml | ||
pubspec.yaml |