I would like to update _scrollController's initial offset after i receive new state from bloc. Basically, this is a timeline which has to adjust to new time coming from player.
This is what I do in a stateful widget
void initState() {
_scrollController =
ScrollController(initialScrollOffset: 100); //
super.initState(); }
This is CustomScrollView
BlocBuilder<Timer, TimestampState>(builder: (context, state) {
calculatedScrollOffset = state.time.pixels;
_scrollController = ScrollController(initialScrollOffset: calculatedScrollOffset);
return CustomScrollView(
controller: _scrollController,
reverse: false,
scrollDirection: Axis.horizontal,
slivers: timeLinePieces,
),
);
Unfortunatelly there is no public setter to do something like _scrollController.offset= 200. When I debug this code there is detailed information in debug, but once new state is coming from bloc I see 'no clients' for ScrollController.
What's the best way to achieve this? I've tried to render new Timeline widget every time I receive new TimestampState but this also brings no effect. Ideally I would like to use setState to bind a new value for offset and render widget again to see effects.
if (_scrollController.hasClients) { Future.delayed(Duration(milliseconds: 1), () { _scrollController.jumpTo(_scrollController.position.pixels + 0.1); }); }