我有里面有SliverFixedExtentList和SliverList的CustomScrollView。我在SliverFixedExtentList的委托中放了一个PageView。问题是,在滚动到底部并打开一个详细信息页面并返回后,它给了我一个我不太理解的异常:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (25339): The following assertion was thrown while finalizing the widget tree:
I/flutter (25339): 'package:flutter/src/widgets/scroll_position.dart': Failed assertion: line 661 pos 12: 'pixels !=
I/flutter (25339): null': is not true.你知道发生了什么事吗?下面是产生这个问题的要点:https://gist.github.com/figengungor/e03704744d0ef786a15ecb783060f730 (
发布于 2018-10-19 22:31:38
在使用选项卡部件时,这似乎是一个反复出现的错误。在github上有一个开放的问题,它似乎解决了与您密切相关的其他案例。
就您的情况而言,这似乎是在PageView小部件失去屏幕焦点时发生的。虽然这不是一个好的解决方案(但确实解决了错误),但它应该会对您有所帮助:
声明一个ScrollController:
class HomePageState extends State<HomePage> {
ScrollController _scrollController = new ScrollController();
...将其分配给CustomScrollView
CustomScrollView(
controller: _scrollController,
...在转到另一个页面之前,向上滚动列表以使PageView小部件可见:
_openSecondPage(BuildContext context) {
_scrollController.animateTo(0.0, duration: Duration(milliseconds: 1), curve: Curves.bounceInOut);
Navigator.of(context).push(MaterialPageRoute(builder: (_) => SecondPage()));
...您应该保存滚动位置,以便滚动到单击项目时的位置。
PS:在flutter github上打开一个问题,以便更好地了解这一点。
https://stackoverflow.com/questions/52893367
复制相似问题