gpt4 book ai didi

flutter - 更新相机后无法使用相机资源 : ^0. 10.0 takepicture() 函数不起作用

转载 作者:行者123 更新时间:2023-12-05 02:27:22 24 4
gpt4 key购买 nike

在 pubspec.yaml 中将 CAMERA 版本从 0.5.8+17 更新到 0.10.0 后,我无法使用 cameraControllers.takePicture

我附上了最后的代码。不对的地方请指正

try {
final p = await getTemporaryDirectory();
final name = DateTime.now();
final path = "${p.path}/$name.png";


await cameraController.takePicture(path).then((value) {
if (valuetype == '1') {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => AddProfile(
imgPath: path,
fileName: "$name.png",
imagetype: "1",
)));
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyApp(
imgPath: path,
fileName: "$name.png",
))).then((erg) {
if (Navigator.canPop(context)) {
Navigator.pop(context);
} else {
SystemNavigator.pop();
}
});
}
print(imgPath + 'image path');
});



} catch (e) {
showCameraException(e);
}

最佳答案

  onCapture(context) async {
try {
File imageFile;
// final p = await getTemporaryDirectory();
XFile xFile = await cameraController.takePicture();
if (xFile != null) {
imageFile = File(xFile.path);
}
final name = DateTime.now();
// final path = "${imageFile.path}/$name.png";

if (imageFile != null && imageFile.existsSync()) {
if (valuetype == '1') {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => AddProfile(
imgPath: imageFile.path,
fileName: "$name.png",
imagetype: "1",
)));
} else {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyApp(
imgPath: imageFile.path,
fileName: "$name.png",
))).then((erg) {
if (Navigator.canPop(context)) {
Navigator.pop(context);
} else {
SystemNavigator.pop();
}
});
}
print(imgPath + 'image path');
} else {
print('Image file does not exist');
}
} catch (e) {
showCameraException(e);
}
}

这对我有用

关于flutter - 更新相机后无法使用相机资源 : ^0. 10.0 takepicture() 函数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73273867/

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