Skip to content

ListView crashing when scrolling #63286

@korkis

Description

@korkis
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: MyStatefulWidget(),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

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

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Sample Code'),
      ),
      body: ListView(
        children: [
          Container(),//<-- Error occurs when scrolling
          for(int i=0; i<30; i++)
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text('Hello'),
          )
        ],
      ),
    );
  }
}


════════ Exception caught by rendering library ═════════════════════════════════
The method '-' was called on null.
Receiver: null
Tried calling: -(0.0)
The relevant error-causing widget was
    ListView 
lib\main.dart:31
════════════════════════════════════════════════════════════════════════════════

HI
If I put an invisible widget or Container in the first of the ListView, an error occurs when scrolling.
My flutter version is 1.20.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions