Flutter number picker doesn't update on bottom sheet
669
I don't understand what's your goal but I hope this helps :
showModalBottomSheet<int>(
context: context,
builder: (BuildContext context){
return StatefulBuilder(
builder: (BuildContext context, StateSetter setModalState) {
return Container(
height: 350.0,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0)
)
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
NumberPicker.integer(
initialValue: _currentValue,
minValue: 0,
maxValue: 1000,
onChanged: (value) {
setModalState(() {
_currentValue = value;
});
}
),
],
),
)
),
);
}
);
}
).then((int value) {
if(value != null) {
setState(() => _currentValue = value);
}
});
Author by
idrisyagci
He was born in 1988. He has been dealing with software technologies since 2011.Technologies that I generally care about are open source technologies and I never adopt closed source technologies. Accordingly, I am closely interested in technologies such as php, html / css, javascript, android, ios, flutter and python, especially java.
Updated on December 02, 2022Comments
-
idrisyagci over 1 year
I want to use flutter number picker inside of bottom sheet dialog. But the number picker doesn't update when i changed the value by swiping. My codes are below.
GestureDetector( onTap: (){ showModalBottomSheet<int>( context: context, builder: (BuildContext context){ return new Container( height: 350.0, color: HexColor('FF737373'), child: new Container( decoration: new BoxDecoration( color: Colors.white, borderRadius: new BorderRadius.only( topLeft: const Radius.circular(20.0), topRight: const Radius.circular(20.0))), child: new Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ NumberPicker.integer( initialValue: _currentValue, minValue: 0, maxValue: 1000, ), ], ), )), ); } ).then((int value) { if (value != null) { setState(() => _currentValue = value); } }); }, child: Container( //container ), ),