我有一个名为showdialog的函数,由于某种原因,numberPicker不会在showdialog中更新其值。我知道您可以使用NumberPickerDialog,但在这种情况下我想知道如何解决。当我在showdialog之外使用numberPicker时,它可以正常工作
List intList = [0,0,0,0,0,0];
Scaffold(
appBar: AppBar(),
body: Center(child: ListView.builder(
itemCount: list.length,
itemBuilder: (context, index){
return Container(child: IconButton(
icon: Icon(Icons.alarm),
onPressed: (){
_showdialog(index: index);
},
));
} ),
));
}
_showdialog({int index, int value}){
showDialog<int>(
barrierColor: Colors.black54,
context: context,
builder: (BuildContext context){
return AlertDialog(
content:
FutureBuilder(
future: future,
builder: (context, snapshot) =>
NumberPicker.integer(
initialValue: intList[index],
minValue: 00,
maxValue: 23,
onChanged: (value){
setState(() {
intList[index] = value;
});
},
)));
}
);
}