用户取消了 MultiImagePicker 上的选择
The User has Cancelled The Selection on MultiImagePicker
我有 flutter 项目,我想从相机或画廊拍摄图像。现在,我使用 multi_image_picker: ^4.8.1 。但是,在执行代码后,我收到错误 'The User has Cancelled the selection' 并弹出 'Permission denied'.
this is error what I get on device
这是我在相机功能中的代码
child:Column(
mainAxisAlignment:MainAxisAlignment.center,
children: <Widget>[
Center(child: Text('Error: $_error')),
ElevatedButton(
child: Icon(Icons.camera_alt),
onPressed: () async {
loadAssets();
}),
Expanded(
child: buildGridView(),
),
],
),
这是我的职能
Future<void> loadAssets() async {
List<Asset> resultList = <Asset>[];
String error = 'No Error Detected';
try {
if(await checkAndRequestCameraPermissions()) {
resultList = await MultiImagePicker.pickImages(
maxImages: 300,
enableCamera: true,
selectedAssets: images,
cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
materialOptions: MaterialOptions(
actionBarColor: "#abcdef",
actionBarTitle: "Example App",
allViewTitle: "All Photos",
useDetailsView: false,
selectCircleStrokeColor: "#000000",
),
);
}
} on Exception catch (e) {
error = e.toString();
}
if (!mounted) return;
setState(() {
images = resultList;
_error = error;
});
}
这是我的权限功能
Future<bool> checkAndRequestCameraPermissions() async {
// PermissionStatus permission = await Permission.camera.status;
if (await Permission.camera.request().isGranted) {
Map<Permission, PermissionStatus> statuses = await [
Permission.camera,
].request();
return statuses[Permission.camera] == PermissionStatus.granted;
} else {
return true;
}
}
这是查看图片的功能
Widget buildGridView() {
return GridView.count(
crossAxisCount: 3,
children: List.generate(images.length, (index) {
Asset asset = images[index];
return AssetThumb(
asset: asset,
width: 300,
height: 300,
);
}),
);}
这是我在日志中得到的错误
E/RecyclerView( 6058): No adapter attached; skipping layout
D/EGL_emulation( 6058): eglMakeCurrent: 0xafa856c0: ver 2 0 (tinfo 0x91312880)
D/EGL_emulation( 6058): eglMakeCurrent: 0xafa856c0: ver 2 0 (tinfo 0x91312880)
D/EGL_emulation( 6058): eglMakeCurrent: 0xa23cda20: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglCreateContext: 0x7a964a80: maj 2 min 0 rcv 2
D/EGL_emulation( 6058): eglMakeCurrent: 0x7a964a80: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglMakeCurrent: 0xa23cda20: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglMakeCurrent: 0xa23cda20: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglMakeCurrent: 0xafa856c0: ver 2 0 (tinfo 0x91312880)
我已经在搜索了。并且已经使用相机权限。但是,一如既往,我得到了同样的错误。有人认为我的代码有问题吗?
您使用的软件包似乎已停产。我建议使用 image_pickers
.
https://pub.dev/packages/image_pickers
我有 flutter 项目,我想从相机或画廊拍摄图像。现在,我使用 multi_image_picker: ^4.8.1 。但是,在执行代码后,我收到错误 'The User has Cancelled the selection' 并弹出 'Permission denied'.
this is error what I get on device
这是我在相机功能中的代码
child:Column(
mainAxisAlignment:MainAxisAlignment.center,
children: <Widget>[
Center(child: Text('Error: $_error')),
ElevatedButton(
child: Icon(Icons.camera_alt),
onPressed: () async {
loadAssets();
}),
Expanded(
child: buildGridView(),
),
],
),
这是我的职能
Future<void> loadAssets() async {
List<Asset> resultList = <Asset>[];
String error = 'No Error Detected';
try {
if(await checkAndRequestCameraPermissions()) {
resultList = await MultiImagePicker.pickImages(
maxImages: 300,
enableCamera: true,
selectedAssets: images,
cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
materialOptions: MaterialOptions(
actionBarColor: "#abcdef",
actionBarTitle: "Example App",
allViewTitle: "All Photos",
useDetailsView: false,
selectCircleStrokeColor: "#000000",
),
);
}
} on Exception catch (e) {
error = e.toString();
}
if (!mounted) return;
setState(() {
images = resultList;
_error = error;
});
}
这是我的权限功能
Future<bool> checkAndRequestCameraPermissions() async {
// PermissionStatus permission = await Permission.camera.status;
if (await Permission.camera.request().isGranted) {
Map<Permission, PermissionStatus> statuses = await [
Permission.camera,
].request();
return statuses[Permission.camera] == PermissionStatus.granted;
} else {
return true;
}
}
这是查看图片的功能
Widget buildGridView() {
return GridView.count(
crossAxisCount: 3,
children: List.generate(images.length, (index) {
Asset asset = images[index];
return AssetThumb(
asset: asset,
width: 300,
height: 300,
);
}),
);}
这是我在日志中得到的错误
E/RecyclerView( 6058): No adapter attached; skipping layout
D/EGL_emulation( 6058): eglMakeCurrent: 0xafa856c0: ver 2 0 (tinfo 0x91312880)
D/EGL_emulation( 6058): eglMakeCurrent: 0xafa856c0: ver 2 0 (tinfo 0x91312880)
D/EGL_emulation( 6058): eglMakeCurrent: 0xa23cda20: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglCreateContext: 0x7a964a80: maj 2 min 0 rcv 2
D/EGL_emulation( 6058): eglMakeCurrent: 0x7a964a80: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglMakeCurrent: 0xa23cda20: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglMakeCurrent: 0xa23cda20: ver 2 0 (tinfo 0x913126f0)
D/EGL_emulation( 6058): eglMakeCurrent: 0xafa856c0: ver 2 0 (tinfo 0x91312880)
我已经在搜索了。并且已经使用相机权限。但是,一如既往,我得到了同样的错误。有人认为我的代码有问题吗?
您使用的软件包似乎已停产。我建议使用 image_pickers
.
https://pub.dev/packages/image_pickers