Taha Tesser
c8e42b47f5
Fix AnimatedList & AnimatedGrid doesn't apply MediaQuery padding (#129556)
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](a20db068dd/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`.

The fix applies `MediaQuery` padding to the inner `SliverPadding` in `AnimatedList` & `AnimatedGrid`.

### 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

### After

2023-06-26 16:19:02 +00:00
..
2023-04-07 15:51:05 +00:00
2023-06-09 08:04:07 +00:00
2023-02-02 19:33:57 +00:00
2023-02-02 19:33:57 +00:00
2023-01-31 17:51:49 +00:00
2023-06-26 16:19:02 +00:00
2022-12-20 14:09:55 -08:00
2023-06-26 16:19:02 +00:00
2022-12-20 14:09:55 -08:00
2023-05-15 11:07:30 +02:00
2023-03-02 23:24:02 +00:00
2023-03-14 16:48:07 +00:00
2023-06-08 22:57:19 +00:00
2023-05-09 15:47:16 +00:00
2023-05-02 08:03:02 +00:00
2023-01-20 22:09:06 +00:00
2023-02-02 19:33:57 +00:00
2023-04-06 18:17:56 +00:00
2023-06-15 13:09:43 -07:00
2023-03-09 19:05:32 +00:00
2023-05-15 11:07:30 +02:00
2023-04-07 19:38:52 +00:00
2023-04-07 19:38:52 +00:00
2023-04-07 19:38:52 +00:00
2023-06-08 22:57:19 +00:00
2022-12-20 16:03:21 -08:00
2023-03-22 21:12:22 +00:00
2022-12-20 16:03:21 -08:00
2023-02-02 19:33:57 +00:00
2022-11-01 22:17:08 +00:00
2023-03-13 21:50:24 +00:00
2022-10-28 12:40:09 -07:00
2023-03-13 21:50:24 +00:00
2022-12-20 19:07:15 +00:00
2023-04-12 19:07:08 +00:00
2023-04-05 22:19:30 -07:00
2023-06-20 23:35:42 +00:00
2023-06-09 17:00:14 +00:00
2023-01-05 17:04:15 +00:00
2022-10-31 23:09:09 +00:00
2023-03-22 21:12:22 +00:00
2023-03-14 16:48:07 +00:00
2023-05-22 16:14:35 -07:00
2023-02-02 19:33:57 +00:00
2023-06-08 20:07:23 +00:00
2023-05-23 18:21:10 +00:00
2023-02-07 11:52:51 -08:00
2023-05-26 10:49:37 -07:00
2023-03-08 19:45:49 +00:00
2023-06-13 16:51:22 +00:00
2022-12-14 21:53:20 +00:00
2023-01-20 22:09:06 +00:00
2023-03-27 20:31:49 +00:00
2023-02-02 19:33:57 +00:00
2023-05-15 11:07:30 +02:00
2023-03-22 21:12:22 +00:00
2023-02-28 23:55:58 +00:00
2023-06-09 08:04:07 +00:00
2023-03-29 23:00:24 +00:00
2023-06-07 03:02:55 +00:00
2023-01-20 22:09:06 +00:00
2023-02-13 21:38:27 +00:00
2023-01-31 11:13:59 -08:00
2022-12-20 14:09:55 -08:00
2023-06-16 16:16:36 +00:00
2023-06-15 18:00:25 +00:00
2023-06-01 15:43:18 +00:00
2023-03-01 19:24:18 -08:00
2022-12-20 16:03:21 -08:00
2023-02-23 19:43:21 +00:00
2023-06-09 21:20:50 +00:00
2023-04-15 22:04:20 +00:00
2023-05-16 16:14:23 +00:00
2023-02-02 19:33:57 +00:00
2023-04-04 11:22:22 -07:00
2023-01-20 22:09:06 +00:00
2023-02-23 01:09:51 +00:00
2023-01-25 22:22:00 +00:00
2023-05-26 10:45:56 -07:00
2022-12-20 16:03:21 -08:00
2023-04-07 15:51:05 +00:00
2022-11-04 10:55:28 -07:00
2023-01-20 22:09:06 +00:00
2023-01-20 22:09:06 +00:00
2023-02-02 19:33:57 +00:00
2022-10-31 23:09:09 +00:00
2023-01-20 22:09:06 +00:00
2023-01-25 22:22:00 +00:00
2023-06-12 15:20:11 +00:00
2022-12-20 14:09:55 -08:00
2022-12-20 16:03:21 -08:00
2023-04-05 22:19:30 -07:00
2023-03-27 20:31:49 +00:00
2023-05-03 09:05:16 +00:00
2023-01-24 01:57:00 +00:00
2023-01-31 11:13:59 -08:00
2023-02-02 19:33:57 +00:00
2023-02-01 22:44:00 +00:00
2023-05-19 00:32:26 +00:00
2023-06-05 21:14:22 +00:00
2023-05-05 00:34:04 +00:00
2022-12-20 14:09:55 -08:00
2022-12-20 16:03:21 -08:00
2023-01-31 11:13:59 -08:00
2023-06-21 02:40:48 +00:00
2023-05-15 11:07:30 +02:00
2023-02-21 18:05:07 +00:00
2023-03-22 21:12:22 +00:00
2023-06-15 13:09:43 -07:00
2022-10-31 23:09:09 +00:00
2022-12-20 14:09:55 -08:00
2023-05-24 22:34:06 +00:00
2023-02-02 19:33:57 +00:00
2023-02-02 19:33:57 +00:00
2023-01-31 11:13:59 -08:00
2023-03-07 03:38:59 +00:00
2023-06-16 13:53:05 +00:00
2023-05-09 15:47:16 +00:00
2022-12-09 20:59:11 +00:00
2023-04-19 10:31:36 -07:00
2022-12-20 14:09:55 -08:00
2023-03-15 00:34:34 +00:00
2022-11-16 02:07:50 +00:00
2023-05-15 19:17:11 +00:00
2022-10-31 23:09:09 +00:00
2023-02-02 19:33:57 +00:00
2023-05-19 21:27:24 +00:00
2023-04-24 18:33:24 +00:00
2023-04-24 18:33:24 +00:00
2023-04-24 18:33:24 +00:00
2023-05-19 00:32:26 +00:00
2023-02-02 19:33:57 +00:00
2023-03-27 20:31:49 +00:00
2023-02-02 19:33:57 +00:00
2023-01-25 21:21:28 -08:00
2023-05-15 11:07:30 +02:00
2022-10-24 23:03:50 +00:00
2023-05-16 22:24:03 +00:00
2023-04-10 19:34:51 +00:00
2023-03-15 00:34:34 +00:00
2023-02-28 17:38:29 +00:00
2022-10-31 23:09:09 +00:00
2023-01-03 21:34:08 +00:00
2023-03-09 19:05:32 +00:00
2023-06-14 22:47:06 +00:00
2023-04-18 00:08:07 +00:00
2023-04-17 23:19:11 +00:00
2023-02-28 17:38:29 +00:00
2022-10-28 23:00:22 +00:00
2023-05-15 11:07:30 +02:00
2023-06-05 21:15:32 +00:00
2023-06-15 18:17:09 +00:00
2023-06-23 16:47:47 +00:00
2023-06-15 13:09:43 -07:00
2023-04-19 19:48:12 +00:00
2023-04-07 15:51:05 +00:00
2023-04-07 15:51:05 +00:00
2023-01-20 22:09:06 +00:00
2023-02-28 23:55:58 +00:00
2023-02-02 19:33:57 +00:00
2023-05-15 11:07:30 +02:00
2023-05-31 20:15:52 +00:00
2023-04-12 19:07:08 +00:00
2022-12-20 16:03:21 -08:00
2023-03-09 19:05:32 +00:00
2023-04-12 19:07:08 +00:00
2022-12-20 16:03:21 -08:00
2022-12-20 16:03:21 -08:00
2023-05-09 15:47:16 +00:00
2022-10-28 23:00:22 +00:00
2022-12-20 19:07:15 +00:00
2023-04-24 23:17:36 +00:00
2023-05-31 22:01:06 +00:00
2022-12-20 14:09:55 -08:00
2022-12-20 14:09:55 -08:00
2023-06-08 15:54:09 -07:00
2023-01-03 22:33:55 +00:00
2023-04-07 15:51:05 +00:00
2023-02-28 23:55:58 +00:00
2023-01-03 21:34:08 +00:00
2023-04-07 15:51:05 +00:00
2023-05-16 22:28:54 +00:00
2023-03-14 18:19:17 +00:00
2023-02-02 19:33:57 +00:00
2023-04-05 14:43:56 -07:00
2023-03-29 19:58:58 +00:00
2023-02-02 19:33:57 +00:00
2023-03-30 22:26:51 +00:00
2023-06-23 00:10:32 +00:00
2023-01-31 11:13:59 -08:00
2023-01-20 22:09:06 +00:00
2023-06-15 13:09:43 -07:00
2023-04-21 22:38:06 +00:00
2023-05-26 23:47:33 +00:00
2023-02-02 19:33:57 +00:00
2023-02-02 19:33:57 +00:00
2022-12-07 01:15:22 +00:00
2023-05-26 22:22:21 +00:00
2023-06-06 16:28:31 +00:00
2023-06-12 23:28:15 +00:00
2023-04-06 19:53:50 +00:00
2023-01-25 18:58:23 +00:00
2023-04-07 15:51:05 +00:00
2023-01-17 08:44:08 -05:00
2023-03-27 20:31:49 +00:00
2023-06-16 19:39:54 +00:00
2023-03-09 19:05:32 +00:00