Reputation: 327
I implemented some NestedScrollView
as below.
It causes an error "must be called with a context that contains a NestedScrollView".
But I used Builder
to build the widget, and that is in the manual of flutter docs. What should I do?
return NestedScrollView(
headerSliverBuilder: (context, isInScroll) {
/* something*/
},
body: Hero(
tag: widget.folderInfo.title + 'body',
child: Container(
padding: EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 16.0),
child: Builder(
builder: (context) {
print("built body builder");
// below line causes error "must be called with a context that contains a NestedScrollView"
var handle =
NestedScrollView.sliverOverlapAbsorberHandleFor(context);
);
},
),
),
),
);
Upvotes: 2
Views: 7049
Reputation: 11634
The Builder
function expects a return statement which seems to be missing from code you provided.
Below code works and prints test
on screen:
return NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar()
];
},
body: Hero(
tag: 'test',
child: Container(
padding: EdgeInsets.fromLTRB(16.0, 20.0, 16.0, 16.0),
child: Builder(builder: (context) {
var handle = NestedScrollView.sliverOverlapAbsorberHandleFor(context);
print('test');
return Container( . // whatever you want to return here
child: Text('test'),
);
print('test');
})
),
),
);
Upvotes: 1