Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed assertion: line 556 pos 15: 'scrollOffsetCorrection != 0.0': is not true

Tags:

flutter

dart

After Upgrading the flutter to the latest version. I'm facing this issue, I've the same code for another application having earlier version of flutter and it is working fine.

With the new ListView add two or more children.

Scroll down the list to the point where the first child is entirely off the screen.

Scroll all the way back up to the initial position. The ListView shows nothing on screen (just white empty space).

Attaching minimal reproducible code:

import 'dart:async';

import 'package:flutter/material.dart';


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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MYYApp(),
    );
  }
}

class MYYApp extends StatefulWidget {
  @override
  _MYYAppState createState() => _MYYAppState();
}

class _MYYAppState extends State<MYYApp> {

  final list = [
    'BMW',
    'Fiat',
    'Toyota',
    'Fiat',
    'Testa',
    'Fiat',
    'Ford',
    'Fiat',
    'BMW',
    'Fiat',
    'Toyota',
    'Fiat',
    'Testa',
    'Fiat',
    'Ford',
    'Fiat'
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:  SafeArea(
        child: ListView.builder(
          itemCount: list.length,
            itemBuilder: (context,index){
          return list[index]=='Fiat'?               //list[index] == 'Fiat' (this condition check is responsible for the issue and earlier it was not an issue)
            Container(
            height: 300,
            child: Center(child: Text(list[index])), 
          ):Container();
        })

      ),
    );
  }
}

Here's the error:

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The method '-' was called on null.
Receiver: null
Tried calling: -(223.60756587000844)
The relevant error-causing widget was: 
  ListView file:///C:/Users/prave/AndroidStudioProjects/for_stackoverflow/lib/main.dart:49:25
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by rendering library ═════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/sliver.dart': Failed assertion: line 556 pos 15: 'scrollOffsetCorrection != 0.0': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=BUG.md

The relevant error-causing widget was: 
  ListView file:///C:/Users/prave/AndroidStudioProjects/for_stackoverflow/lib/main.dart:49:25
When the exception was thrown, this was the stack: 
#2      new SliverGeometry (package:flutter/src/rendering/sliver.dart:556:15)
#3      RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:180:20)
#4      RenderObject.layout (package:flutter/src/rendering/object.dart:1769:7)
#5      RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:137:11)
#6      RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:377:11)

This is only a part of error,it produces nearly 10 same kind of errors.

like image 249
dartKnightRises Avatar asked Aug 11 '20 05:08

dartKnightRises


1 Answers

The error vanishes as soon as you give your alternative non-Fiat container a height of non-zero.

I don't know exactly why that is or if it's on purpose, but the list seems to have problems with zero-height elements.

I suggest you actually use a filtering mechanism on your data and not work around that part by making it zero height in the view as an afterthought.

like image 64
nvoigt Avatar answered Nov 11 '22 10:11

nvoigt