我正在使用以下代码从用户的图库中选取图像。
Future getImageFromGallery(BuildContext context) async {
await ImagePicker.platform()
.pickImage(source: ImageSource.gallery)
.then((image) {
if (image != null) {
_cropImage(image, context);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我收到以下警告。
The member 'platform' can only be used within 'package:image_picker/image_picker.dart' or a test.
Run Code Online (Sandbox Code Playgroud)
我不确定这个警告是什么意思。我尝试查找它,但无法找到解决此警告的解决方案。
升级 Flutter 后,我按照迁移代码的所有步骤进行操作,现在出现此错误,无法使用 .Copy。
class ImageInput extends StatefulWidget {
final Function onSelectImage;
ImageInput(this.onSelectImage);
@override
_ImageInputState createState() => _ImageInputState();
}
class _ImageInputState extends State<ImageInput> {
File _storedImage;
final picker = ImagePicker();
Future getImage() async {
final pickedFile =
await picker.getImage(source: ImageSource.camera, maxWidth: 600);
setState(() {
if (pickedFile != null) {
_storedImage = File(pickedFile.path);
} else {
print('No image selected.');
}
});
final appDir = await syspaths.getApplicationDocumentsDirectory();
final fileName = path.basename(pickedFile.path);
final savedImage = await pickedFile.copy('${appDir.path}/$fileName');
widget.onSelectImage(savedImage);
}
Run Code Online (Sandbox Code Playgroud)
我的地图也出现问题,当我在没有 imageInput 类 onPressed …
我正在使用 expo-image-picker 来允许用户选择并拍照。从库中选择图像可以按预期工作,但是在使用相机时,拍照后应用程序崩溃。这是我的代码:
const take = async () => {
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 1,
});
console.log(result.uri);
if (!result.cancelled) {
setImageUri(result.uri);
}
};
Run Code Online (Sandbox Code Playgroud)
我认为我拥有所有必需的权限,并且问题似乎只发生在内存有限的旧版 Android 设备上。有任何想法吗?
我遇到了有关我的 Flutter 应用程序的问题,我一直在关注 Youtube 上的教程,了解如何在 Flutter 中使用从图库中选择图片以及相机,但无法使图像选择器功能正常工作。它总是返回错误
“无法使用静态访问来访问实例成员‘pickimage’。
谁能帮忙解决这个问题,因为我有点困惑。先感谢您。
class _LandingScreenState extends State<LandingScreen>{
late File imageFile;
_openGallery() async{
var picture = await ImagePicker.pickImage(source:
ImageSource.gallery);
this.setState(() {
imageFile = picture as File;
});
}
Run Code Online (Sandbox Code Playgroud) 我正在使用图像选择器插件来选择图像。我想在选取图像后立即导航到新屏幕,但它不起作用。我收到一条错误,指出当前小部件树中不存在上下文。
下面是我的代码。
pickImage(BuildContext context) async {
File pickedImage = await ImagePicker.pickImage(source: ImageSource.camera);
if (pickedImage != null) {
print(pickedImage.path);
if (this.mounted) {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ViewStory(
localImagePath: pickedImage.path,
),
),
);
}
}
}
Run Code Online (Sandbox Code Playgroud)
像这样调用该函数:
IconButton(
onPressed: () => pickImage(context),
icon: Icon(
Icons.camera_alt,
color: CustomColors.primary,
size: 100,
),
),
Run Code Online (Sandbox Code Playgroud)
以下是我收到的错误:
FlutterError(查找已停用的小部件的祖先是不安全的。此时小部件的元素树的状态不再稳定。要在其 dispose() 方法中安全地引用小部件的祖先,请通过调用inheritFromWidgetOfExactType(保存对祖先的引用) )在小部件的 didChangeDependency() 方法中。)
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-telerik-imagepicker"
version="2.2.4">
<name>ImagePicker</name>
<description>
This plugin allows selection of multiple images from the camera roll / gallery in a phonegap app
</description>
<license>MIT</license>
<engines>
<engine name="cordova" version=">=3.5.0" />
</engines>
<js-module src="www/imagepicker.js" name="ImagePicker">
<clobbers target="plugins.imagePicker" />
</js-module>
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="ImagePicker">
<param name="ios-package" value="SOSPicker"/>
</feature>
</config-file>
<preference name="PHOTO_LIBRARY_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string>$PHOTO_LIBRARY_USAGE_DESCRIPTION</string>
</config-file>
<header-file src="src/ios/SOSPicker.h" />
<source-file src="src/ios/SOSPicker.m" />
<header-file src="src/ios/GMImagePicker/UIImage+fixOrientation.h" />
<source-file src="src/ios/GMImagePicker/UIImage+fixOrientation.m" />
<header-file …Run Code Online (Sandbox Code Playgroud)我正在使用image_picker 0.6.7+17库以便使用手机摄像头拍摄图像。
我使用的是 android 设备而不是 ios 设备。
似乎getImage没有定义该方法,我从文档中获取了这个确切的代码:
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
lib/pickers/image_picker.dart:17:37: Error: The method 'getImage' isn't defined for the class
'ImagePicker'.
- 'ImagePicker' is from 'package:chat_app/pickers/image_picker.dart'
('lib/pickers/image_picker.dart').
Try correcting the name to the name of an existing method, or defining a method named 'getImage'.
final pickedFile = await picker.getImage(source: ImageSource.camera);
^^^^^^^^
Run Code Online (Sandbox Code Playgroud)
到目前为止我做了什么:
dependencies:
flutter:
sdk: flutter …Run Code Online (Sandbox Code Playgroud) 我正在使用图像选择器插件从我的 flutter 应用程序中的图库中选择视频。我想将所选视频的最大持续时间设置为 30 秒。即使设置了最大持续时间,以下代码也不起作用。如果用户选择更大的视频,是否有任何方法可以显示错误或自动修剪前 30 秒。
pickVideo(ImageSource src) async {
Navigator.pop(context);
final video = await ImagePicker().getVideo(
source: src,
maxDuration: Duration(seconds: 30),
);
Run Code Online (Sandbox Code Playgroud) 当我在 flutter web 中使用 image_picker 时出现问题“错误:不支持的操作:Object.throw 处的命名空间[as throw] (http://localhost:56308/dart_sdk.js:5334:11) at Function.get _namespace [as _namespace] (http://localhost:56308/dart_sdk.js:55299:17) 在 io._File.new.lengthSync (http://localhost:56308/dart_sdk.js:53158:59)'
这在 android 中工作正常,在打开的图像选择窗口中并且图像已成功预览,但在 flutter web 中不起作用在网络案例中图像选择窗口打开但图像未获取。
这是我的图像选择器代码...
最终选择器= ImagePicker(); var imag =等待picker.getImage(来源:oursource);
var imageFile = File(imag.path);
Run Code Online (Sandbox Code Playgroud) 我只是想选择一个图像并将其显示在我的应用程序中。为此,我使用Flutter Image Picker。我添加了所有依赖项,我可以选择图像,但无法显示它......
这是我尝试过的:
class _AddMemoryPageState extends State<AddMemoryPage> {
final picker = ImagePicker();
late Future<PickedFile?> pickedFile;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.secondary,
body: SafeArea(
child: Column(
children: [
Row(
children: [
Padding(
padding: EdgeInsets.only(
top: 15,
left: 25,
),
child: IconButtonWithExpandedTouchTarget(
onTapped: () {
Navigator.pop(context);
},
svgPath: 'assets/icons/down.svg',
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButtonWithExpandedTouchTarget(
onTapped: () async {
pickedFile = picker
.getImage(
source: ImageSource.camera,
)
.whenComplete(() => {setState(() {})});
},
svgPath: …Run Code Online (Sandbox Code Playgroud) image-gallery dart flutter imagepicker flutter-futurebuilder
我发现了很多关于该主题的问题,但没有一个有完整的工作示例。
我的情况很简单:
我当前的代码(未压缩):
分段:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
RC_PICK_IMAGE ->
if (resultCode == Activity.RESULT_OK)
data?.data?.let { viewModel.updateUserPicture(it) }
}
}
Run Code Online (Sandbox Code Playgroud)
视图模型:
fun updatePhotoUrl(photoUrl: Uri?): Task<Void> =
Storage.uploadFile("/$PS_USERS/$uid", photoUrl)
.continueWithTask { ... }
Run Code Online (Sandbox Code Playgroud)
存储:(包装 Firebase 交互的对象)
fun uploadFile(path: String, uri: Uri): Task<Uri> {
val imageRef = storageRef.child(path)
val uploadTask = imageRef.putFile(uri)
// Return the task getting the download URL
return uploadTask.continueWithTask { task ->
if …Run Code Online (Sandbox Code Playgroud) imagepicker ×11
flutter ×8
dart ×5
android ×2
copy ×1
expo ×1
flutter-web ×1
kotlin ×1
methods ×1
react-native ×1