我必须从floatingbutton将参数传递给未来的异步函数
我的密码是

FloatingActionButton(
                     onPressed: getImageFromCam,
                      tooltip: 'Pick Image',
                      child: Icon(Icons.add_a_photo),
                     ),


     Future getImageFromCam() async { // for camera
        var image = await ImagePicker.pickImage(source: ImageSource.camera);
        setState(() {
          _image = image;
        });
}

它是多按钮的,所以我必须将索引传递给异步函数。
有人能帮忙解决这个问题吗?
提前谢谢
萨提什

最佳答案

FloatingActionButton(
  onPressed: () => getImageFromCam(index),
  tooltip: 'Pick Image',
  child: Icon(Icons.add_a_photo),
);

...

Future getImageFromCam(int index) async {
  var image = await ImagePicker.pickImage(source: ImageSource.camera);
  setState(() {
    _image = image;
  });
}

10-06 14:05