I'm trying to initialize a class variable of the ScrollController object given in the function of the panelBuilder. My code is like this:
class MapPageState extends State<MapPage> {
late final ScrollController _sc;
//build stuff that returns _slidingPanel
Widget _slidingPanel(BusDataState state) {
return SlidingUpPanel(
controller: _pc,
panelBuilder: (ScrollController sc) {
_sc = sc;
return viewAnimatedSwitcher(); //trying to avoid passing in here and passing into all child functions
//to get access to the controller
},
parallaxEnabled: true,
parallaxOffset: 0.5,
defaultPanelState: PanelState.CLOSED,
backdropEnabled: true,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(45),
topRight: Radius.circular(45),
),
body: _map(state),
);
}
But I get an error saying
LateInitializationError: Field '_sc@122271042' has already been initialized.
Is there a good way to do this so that I don't have to pass the scroll controller object through 3-4 functions just to get it to where it needs to be used?
I'm trying to initialize a class variable of the ScrollController object given in the function of the
panelBuilder
. My code is like this:But I get an error saying
Is there a good way to do this so that I don't have to pass the scroll controller object through 3-4 functions just to get it to where it needs to be used?