I'm trying to use CupertinoPicker on a AlertDialog widget but the values are do not change. The same code work when it's not the AlertDialog widget. What's happening?
Button to press to show AlertDialog:
ElevatedButton(
onPressed: () {
showDialog(
context: context, builder: (context) => AlertDialog(
content:Builder(builder: (context) {
return SizedBox(
child: Column(
children: [
....
]
)
)
}
)
)
}
)
One of the children is the CupertinoWidget and this is the code:
In the class widget int selectedValue = 0;
CupertinoButton.filled(child: Text('$selectedValue'),
onPressed: () =>showCupertinoModalPopup(context:context,builder: (_) =>
SizedBox(width:screenWidth *0.3,height:screenHeight *0.25,
child:CupertinoPicker(backgroundColor:Colors.white,
itemExtent:30,
scrollController:FixedExtentScrollController(initialItem: 1),
children: const [Text('0'),
Text('1'),
Text('2'),
Text('3'),
Text('4'),
Text('5'),
Text('6'),
Text('7'),
],
onSelectedItemChanged:(intvalue) {
setState(() {selectedValue =value;
});
},
),
),
),
),
With this the value in Text('$selectedValue')
do not change. But when I write the same code on a new Scaffold screen it works perfectly. Any reason?