将flutter升级到最新版本后。我正面临这个问题,我为另一个具有早期版本 flutter 的应用程序使用了相同的代码,并且它工作正常。
使用新的 ListView 添加两个或更多子项。
向下滚动列表到第一个孩子完全离开屏幕的点。
一直向上滚动到初始位置。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();
})
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
???????? 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)
Run Code Online (Sandbox Code Playgroud)
这只是错误的一部分,它会产生近10种相同的错误。
一旦您将替代的非菲亚特容器的高度设置为非零,该错误就会消失。
我不知道这是为什么,或者是否是故意的,但该列表似乎存在零高度元素的问题。
我建议您实际上对数据使用过滤机制,而不是事后将视图中的高度设为零来解决该部分。
| 归档时间: |
|
| 查看次数: |
1263 次 |
| 最近记录: |