gpt4 book ai didi

flutter - 失败的断言 : line 556 pos 15: 'scrollOffsetCorrection != 0.0' : is not true

转载 作者:行者123 更新时间:2023-12-03 02:40:27 28 4
gpt4 key购买 nike

将flutter升级到最新版本后。我正面临这个问题,我为另一个具有早期版本 flutter 的应用程序使用了相同的代码,并且它工作正常。
使用新的 ListView 添加两个或更多子项。
向下滚动列表到第一个 child 完全离开屏幕的点。
一直向上滚动到初始位置。 ListView 在屏幕上不显示任何内容(只有空白区域)。
附加最小的可重现代码:

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();
})

),
);
}
}

这是错误:
════════ 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)
这只是错误的一部分,它会产生近10种相同的错误。

最佳答案

一旦您将替代的非菲亚特容器的高度设置为非零,错误就会消失。
我不知道究竟为什么会这样,或者它是否是故意的,但该列表似乎在零高度元素方面存在问题。
我建议你实际使用过滤机制 关于您的数据 并且不通过在 View 中将其设为零高度来解决该部分作为事后的想法。

关于flutter - 失败的断言 : line 556 pos 15: 'scrollOffsetCorrection != 0.0' : is not true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63352010/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com