when multiple instances of widget are rendered and the getValue method is called flutter throws the error ScrollController attached to multiple scroll views. I'm assuming this is because they all are using the same controller but I don't know a way to fix this without creating a separate widget for each time it is used. Is there a better way to fix this?
class NumScroller extends StatelessWidget{
final int max,min;
final double height,width;
final TextAlign alignment;
static ScrollController controller;
NumScroller({this.height,this.width,this.alignment,this.min,this.max, initialOffset}){
controller = new ScrollController(initialScrollOffset: initialOffset);
}
getValue() => (controller.offset~/height) + min;
@override
Widget build(BuildContext context) {
return new Container(
width: width,
height: height,
child: ListView.builder(itemBuilder: (context, index) {
return new Container(height: height, child:Text((max - index).toString(),textAlign: alignment,));
},
itemCount: max - min+1,
controller: controller,
physics: PageScrollPhysics(),
itemExtent: height,
)
);
}
}