18

I have some problems with NestedScrollView. I have implemented PageView with BottomNavigationBar and sometimes, when I am switch between two screens, I got this error:

'package:flutter/src/widgets/nested_scroll_view.dart': Failed assertion: line 501 pos 14: 'position.minScrollExtent != null && position.pixels != null': is not true.

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),
    )

Has someone any ideas?

Shreeya Chhatrala
  • 1,441
  • 18
  • 33
Kamzik
  • 181
  • 1
  • 3

4 Answers4

2

I was using extendBody : true, inside scaffold and was getting the same error. On removing it the error got resolved.

Shatanik Mahanty
  • 342
  • 1
  • 8
  • 15
  • extendBody: true is required for my case. Is there any other solution? Let me know . Thanks. – Rashmi Bhandari Aug 02 '21 at 11:29
  • I don't have any other solution as of now, but will update here If I find anything. Also if you can give me a reproducible sample for your code I will be able to test easily – Shatanik Mahanty Aug 18 '21 at 03:23
2

Just add key: UniqueKey() to NestedScrollView.

your code will be

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),
)
bara batta
  • 1,002
  • 8
  • 8
0

There is no problem in that, just a hot-restart is good to fix the problem. This is because hot-reload doesn't change the state of the app and you did an action that draws from state that isn't there(It assumes it's there)..

If all else fail, try cleaning your app and that should be good

emanuel sanga
  • 815
  • 13
  • 17
0

I have TabView with 4 tabs. In 2 of them I had ScrollController for ListView but 2 other didn't have ScrollController but had Grid. What helped me was adding ScrollController to those Grids. Maybe this advice will help someone just add ScrollController where they are missing.