NestedScrollView问题,在两个屏幕之间切换时引发错误

时间:2019-10-11 10:54:32

标签: android flutter dart nestedscrollview

我在NestedScrollView中遇到一些问题。我已经用BottomNavigationBar实现了PageView,有时,当我在两个屏幕之间切换时,会出现此错误:

'package:flutter / src / widgets / nested_scroll_view.dart':失败的断言:第501行pos 14:'position.minScrollExtent!= null && position.pixels!= null':不正确。

enter image description here

child: NestedScrollView(
      controller: _controller,
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverAppBar(
            automaticallyImplyLeading: false,
            pinned: true,
            expandedHeight: 140.0,
            floating: false,
            centerTitle: true,
            flexibleSpace: FlexibleSpaceBar(
              centerTitle: true,
              background: new Container(
                child: FutureBuilder(
                  future: CoverImagesApi().getImageFile(1),
                  builder: (context, snapshot) {
                    if(snapshot.data != null) {
                      return Container(
                        child: Column(
                          children: <Widget>[
                            Expanded(
                              flex: 5,
                              child: Container(
                                alignment: Alignment.topCenter,
                              ),
                            ),
                            Expanded(
                              flex: 2,
                              child: new Container(
                                child: Center(
                                child: Text('Obecná tabuľa',
                                  style: TextStyle(
                                    fontSize: 26.0,
                                    fontWeight: FontWeight.bold
                                  ),
                                  textAlign: TextAlign.center,
                                ),
                                ),
                                decoration: BoxDecoration(
                                  color: Color.fromRGBO(255, 255, 255, 0.8)
                                ),
                                alignment: Alignment.bottomCenter, //variable above
                              )
                            ),
                          ],
                        ),
                        decoration: new BoxDecoration(
                          image: new DecorationImage(
                            fit: BoxFit.cover
                            image: snapshot.data.existsSync() ? Image.file(snapshot.data).image : AssetImage('assets/tabula.jpg'),
                          ),
                        ),
                      );
                    } else {
                      return Container(height: 0.0, width: 0.0);
                    }
                  }
                ),
              ),
            ),
          ),
        ];

      },
      body: DataFiller(scaffoldKey: _scaffoldKey),
    )

有人有什么想法吗?

4 个答案:

答案 0 :(得分:1)

我在脚手架内部使用extendBody:true,并得到相同的错误。删除该错误后,该错误得以解决。

答案 1 :(得分:0)

这没有问题,只需热重启即可解决问题。这是因为热重载不会更改应用程序的状态,并且您执行了draws from state不存在的操作(假定存在)。

如果其他所有方法都失败,请尝试清理您的应用,那应该很好

答案 2 :(得分:0)

我有TabView,带有4个标签。在其中2个中,我有ScrollController个用于ListView,但另外2个中没有ScrollController但有Grid。帮助我的是在这些ScrollController中添加了Grid。也许此建议会帮助某人仅在他们丢失的地方添加ScrollController

答案 3 :(得分:0)

只需将 key: UniqueKey() 添加到 NestedScrollView。

您的代码将是

child: NestedScrollView(
  key: UniqueKey()
  controller: _controller,
  headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
    return <Widget>[
      SliverAppBar(
        automaticallyImplyLeading: false,
        pinned: true,
        expandedHeight: 140.0,
        floating: false,
        centerTitle: true,
        flexibleSpace: FlexibleSpaceBar(
          centerTitle: true,
          background: new Container(
            child: FutureBuilder(
              future: CoverImagesApi().getImageFile(1),
              builder: (context, snapshot) {
                if(snapshot.data != null) {
                  return Container(
                    child: Column(
                      children: <Widget>[
                        Expanded(
                          flex: 5,
                          child: Container(
                            alignment: Alignment.topCenter,
                          ),
                        ),
                        Expanded(
                          flex: 2,
                          child: new Container(
                            child: Center(
                            child: Text('Obecná tabuľa',
                              style: TextStyle(
                                fontSize: 26.0,
                                fontWeight: FontWeight.bold
                              ),
                              textAlign: TextAlign.center,
                            ),
                            ),
                            decoration: BoxDecoration(
                              color: Color.fromRGBO(255, 255, 255, 0.8)
                            ),
                            alignment: Alignment.bottomCenter, //variable above
                          )
                        ),
                      ],
                    ),
                    decoration: new BoxDecoration(
                      image: new DecorationImage(
                        fit: BoxFit.cover
                        image: snapshot.data.existsSync() ? Image.file(snapshot.data).image : AssetImage('assets/tabula.jpg'),
                      ),
                    ),
                  );
                } else {
                  return Container(height: 0.0, width: 0.0);
                }
              }
            ),
          ),
        ),
      ),
    ];

  },
  body: DataFiller(scaffoldKey: _scaffoldKey),
)