Skip to content

AnimatedList does not take SafeArea into account when building the list  #129539

@jiahaog

Description

@jiahaog

Internal bug: b/288213176

Is there an existing issue for this?

Steps to reproduce

Please see the code sample

Expected results

This is how it works for a ListView, and we would expect the same for a AnimatedList

A flutter app with a ListView, which leaves a space for the safearea

Actual results

This is what it actually looks like. A flutter app with an animated list, which does not leave a space for the safearea

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  void initState() {
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
    SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle(
        statusBarColor: Colors.transparent,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarColor: Colors.transparent,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true,
      appBar: AppBar(
        title: Text(widget.title, style: TextStyle(fontFamily: 'ProductSans')),
      ),
      body: _buildBody(context),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }

  Widget _buildBody(BuildContext context) {
    // AnimatedList does not take into account SafeArea.
    return AnimatedList(
      initialItemCount: 100,
      itemBuilder: (_, index, __) => Text('$index'),
    );
  }
}

Flutter Doctor output

Reproducible on the master channel, on 5a7ab5a147f6b50ba7dc8c82d3ea0040fc0f081f

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listcustomer: money (g3)f: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions