代码之家  ›  专栏  ›  技术社区  ›  Figen Güngör

CustomScrollView和PageView问题

  •  0
  • Figen Güngör  · 技术社区  · 7 年前

    我有CustomScrollView,里面有SliverFixedExtentList和SliverList。我在SliverFixedExtentList的委托中放置了一个页面视图。事情是在滚动到底部并打开一个详细页面并返回之后,它给了我一个我不太理解的异常:

     ══╡ 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 (

    1 回复  |  直到 7 年前
        1
  •  1
  •   Zroq    7 年前

    这似乎是使用选项卡小部件时经常出现的错误。github上有一个公开问题,它似乎解决了与您密切相关的其他案例。

    在你的情况下,当你的 PageView 小部件失去屏幕焦点。 虽然这不是一个好的解决方案(但确实解决了错误),但它应该可以帮助您:

    声明a 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 以便更好地了解这一点。

    推荐文章