Skip to content

ListView doesn't always show all children when using object keys in its children #9185

@yyoon

Description

@yyoon

Steps to Reproduce

This happens in our email module, but here's a reduced down version of it which shows the same behavior.

  • Run the following flutter app
  • Scroll down a little bit, and touch one of the items near the bottom of the list (e.g. around Value: 27)
  • Scrolling up only gets you up to somewhere around Value: 16, and cannot go all the way up to Value: 0.

I think this happens only when the newly given children's keys don't match the ones from the previous children, but not sure.

import 'package:flutter/material.dart';

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

class Foo {
  final int value;
  Foo(this.value);
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(primarySwatch: Colors.blue),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  List<Foo> data;

  @override
  void initState() {
    super.initState();
    resetData();
  }

  void resetData() {
    data = <Foo>[];
    for (int i = 0; i < 30; ++i) {
      data.add(new Foo(i));
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text(config.title)),
      body: new Center(
        child: new ListView(
          children: data.map(_createListItemFromFoo).toList(),
        ),
      ),
    );
  }

  ListTile _createListItemFromFoo(Foo foo) {
    Key key = new ObjectKey(foo);  // Works fine without this object key.
    return new ListTile(
      key: key,
      title: new Text('Value: ${foo.value}'),
      onTap: () {
        setState(() {
          resetData();
        });
      },
    );
  }
}

Logs

Run your application with flutter run and attach all the log output.

Run flutter analyze and attach any output of that command also.

Flutter Doctor

[✓] Flutter (on Linux, channel unknown)
    • Flutter at /usr/local/google/home/youngseokyoon/Programming/fuchsia/lib/flutter
    • Framework revision 9095d76299 (30 hours ago), 2017-04-03 05:17:24
    • Engine revision 4c05830aaf
    • Tools Dart version 1.23.0-dev.10.0

[✓] Host Executable Compatibility
    • Downloaded executables execute on host

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.2)
    • Android SDK at /usr/local/google/home/youngseokyoon/Android/Sdk
    • Platform android-25, build-tools 25.0.2
    • ANDROID_HOME = /usr/local/google/home/youngseokyoon/Android/Sdk
    • Java binary at: /opt/android-studio-2.2/jre/bin/java
    • Java version: OpenJDK Runtime Environment (build 1.8.0_76-release-b03)

[✓] Android Studio (version 2.1)
    • Android Studio at /opt/android-studio-2.1
    • Gradle version 2.14.1
    • Unable to find bundled Java version.

[✓] Android Studio (version 2.2)
    • Android Studio at /opt/android-studio-2.2
    • Gradle version 2.14.1
    • Java version: OpenJDK Runtime Environment (build 1.8.0_76-release-b03)

[✓] IntelliJ IDEA Community Edition (version 2016.3)
    • Dart plugin version 163.13137
    • Flutter plugin version 0.1.11.2

[✓] Connected devices
    • Pixel C • 5C08000423 • android-arm • Android 7.0 (API 24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer: fuchsiaf: scrollingViewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions