将颤振升级到最新版本之后。我正面临这个问题,对于具有较早版本的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();
})
),
);
}
}
这是错误:
════════ 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种同类错误。
答案 0 :(得分:3)
只要您将替代的非菲亚特容器的高度设置为非零,错误就会消失。
我不知道这到底是为什么还是故意,但是列表似乎有零高度元素的问题。
我建议您实际上对数据使用过滤机制,并且事后考虑不要通过在视图中将其设置为零高度来解决该问题。
答案 1 :(得分:0)
升级Flutter框架后,我也遇到同样的问题。
对我来说,问题的描述是:
问题:当您在ListVIew中使用没有子级或没有height属性的Container或Widget时 解决方案:只需为ListView内的Widget提供height属性。
这是我的代码,对我有用
.......
body: ListView(
shrinkWrap: true,
children: <Widget>[
Auth ? Container(height: 1): signUpWidget() , // Add height property to Container
.....
......
]
)
答案 2 :(得分:0)
最小高度应大于0。可以将其设置为0.1。可能是一个错误,但是可以。
ListView(
shrinkWrap: true,
children: <Widget>[
SizedBox(height: 0.1,);
]