MarcinusX / NumberPicker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NumberPicker scrolls back to top

SilkeNL opened this issue · comments

I have a numberPicker to pick the number of products that you want in your shopping cart.
Every time I want to scroll to the last number the picker goes back all the way to the top, setting that number back to zero.
My code:

`
class ScrollingNumberPicker extends StatelessWidget {
final int maxNumber;
final int minNumber;
final int value;
final Function(int) callBack;

    ScrollingNumberPicker(
        {@required this.maxNumber,
        @required this.minNumber,
          @required this.value,
        @required this.callBack});
  
    @override
    Widget build(BuildContext context) {
      return NumberPicker(
          minValue: minNumber,
          maxValue: maxNumber,
          value: minNumber,
          onChanged: callBack,
        selectedTextStyle: TextStyle(color: Colors.black, fontSize: 24),
      );
    }
  }

`

Would you like to share a bit more code than this? :)

This is the code of the widget I call the numberpicker on.
FYI I test on an IOS 14 simulator.

ExpansionTile( backgroundColor: Colors.white, collapsedBackgroundColor: Colors.white, title: Padding( padding: EdgeInsets.symmetric(vertical: 8), child: Row(children: [ TextButton( child: Text(selectedProduct.product.title, style: TextStyle(color: Colors.black, fontSize: 18)), onPressed: () { Navigator.push(); }, ), ]), ), trailing: Text('€19,99', style: TextStyle(color: Colors.black)), children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( children: [ Row(children: [ Padding( padding: EdgeInsets.all(8), child: OctoImage( width: 128, image: CachedNetworkImageProvider(url), progressIndicatorBuilder: OctoProgressIndicator .circularProgressIndicator(), errorBuilder: OctoError.icon(color: Colors.red), ), ), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [], ), ]), ], ), Column( crossAxisAlignment: CrossAxisAlignment.end, children: [ ScrollingNumberPicker( maxNumber: 3, minNumber: 0, value: numberOf, //This is a int variable mostly set to 1. But because the numberpicker scrolls to top its always set to 0. callBack: (int) { numberOfChanged(context, int); //set the numberOf in the state }), ], ) ], ), ], onExpansionChanged: (opened) { setState(() { open = opened; }); }, )

I need an actual example that I can reproduce, I don't know what am I supposed to do with that... :(

As I was trying to make an example for you, the numberPicker did work properly, only thing happening was that it scrolls to the top or bottom which is known to happen in IOS simulators. Seems my code is at fault, my apologies.