gpt4 book ai didi

flutter - ImagePicker.platform 显示警告 - Flutter

转载 作者:行者123 更新时间:2023-12-05 01:27:14 26 4
gpt4 key购买 nike

我正在使用以下代码从用户图库中挑选一张图片。

Future getImageFromGallery(BuildContext context) async {
await ImagePicker.platform()
.pickImage(source: ImageSource.gallery)
.then((image) {
if (image != null) {
_cropImage(image, context);
}
});
}

我收到以下警告。

The member 'platform' can only be used within 'package:image_picker/image_picker.dart' or a test.

我不确定警告是什么意思。我尝试查找它,但无法找出解决此警告的解决方案。

最佳答案

试试下面的代码希望对你有帮助

声明文件类型形式dart.io

File? imagePicked;

创建拾取图像的函数

void gallaryImage() async {
final picker = ImagePicker();
final pickedImage = await picker.pickImage(
source: ImageSource.gallery,
);
final pickedImageFile = File(pickedImage!.path);
setState(() {
imagePicked = pickedImageFile;
});
}

创建您的小部件

TextButton(
onPressed: gallaryImage,
child: Text(
'Gallery',
style: TextStyle(
color: Colors.black,
),
),
),

关于flutter - ImagePicker.platform 显示警告 - Flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69570946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com