简体   繁体   English

我正在使用图像选择器和图像裁剪器依赖项并尝试获取图像但它显示错误

[英]I am using Image picker and image cropper dependencies and trying to get image but it shows error

I am trying to upload image into the database.我正在尝试将图像上传到数据库中。 I have used image picker and image cropper dependencies but it still shows error in the code within the ** that it donot recognize such commands.我已经使用了图像选择器和图像裁剪器依赖项,但它仍然在 ** 内的代码中显示错误,它无法识别此类命令。 After the image picker it donot suggests pickimage .在图像选择器之后它不建议pickimage Kindly help me get through it.请帮助我度过难关。 class EmployeeRegistrationScreen extends StatefulWidget {类 EmployeeRegistrationScreen 扩展 StatefulWidget {

  static const id = 'employee_register';

  @override
  _EmployeeRegistrationScreenState createState() => _EmployeeRegistrationScreenState();
}

class _EmployeeRegistrationScreenState extends State<EmployeeRegistrationScreen> {

  bool showSpinner = false;
  final _auth = FirebaseAuth.instance;
  String email;
  String password;
  String confirmPassword;
  bool  _passwordVisible = false;
  bool _confirmPasswordVisible = false;
  String name;

  File _imageFile;

  /// Cropper plugin
  Future<void> _cropImage() async {
    File cropped = await ImageCropper.cropImage(
        sourcePath: _imageFile.path,
        // ratioX: 1.0,
        // ratioY: 1.0,
        // maxWidth: 512,
        // maxHeight: 512,
        **toolbarColor: Colors.purple,**
        **toolbarWidgetColor: Colors.white,**
        **toolbarTitle: 'Crop It'**
    );

    setState(() {
      _imageFile = cropped ?? _imageFile;
    });
  }

  /// Select an image via gallery or camera
  Future<void> _pickImage(ImageSource source) async {
    **XFile selected = await ImagePicker.pickImage(source: source);**

    setState(() {
      _imageFile = selected as File;
    });
  }

  /// Remove image
  void _clear() {
    setState(() => _imageFile = null);
  }


  @override
  void initState() {

    _passwordVisible = false;
    _confirmPasswordVisible = false;

  }
  final _formKey = GlobalKey<FormState>();
  @override
  Widget build(BuildContext context) {
    return Form(

Since pickImage is not a static method, the correct way to access the pickImage function is to create an instance of ImagePicker .由于pickImage不是静态方法,因此访问pickImage函数的正确方法是创建ImagePicker的实例。

final ImagePicker _picker = ImagePicker();
// Pick an image
final XFile? image = await _picker.pickImage(source: ImageSource.gallery); 

for Your case,对于你的情况,

Future<void> _pickImage(ImageSource source) async {
    // replace ImagePicker.pickImage with ImagePicker().pickImage()
    **XFile selected = await ImagePicker().pickImage(source: source);**

    setState(() {
      _imageFile = selected as File;
    });
  }

Pubsec.yaml: pubsec.yaml:

name: flash_chat
description: A new Flutter application.

version: 1.0.0+1

environment:
  sdk: ">=2.1.0<3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  firebase_storage: ^10.0.6
  image_cropper: ^1.4.1
  image_picker: ^0.8.4+4
  animated_text_kit: ^4.2.1
  firebase_core: ^1.5.0
  firebase_auth: ^3.0.2
  cloud_firestore: ^2.5.0
  modal_progress_hud: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

  assets:
  - images/

Imports :进口:

import 'dart:ui';
import 'package:flash_chat/constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flash_chat/components/RoundedButton.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flash_chat/screens/chat_screen.dart';
import 'package:modal_progress_hud/modal_progress_hud.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:flutter/widgets.dart';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在我的项目中使用图像裁剪器时出错 - I am having error using Image cropper in my project 将多图像选择器与图像裁剪器一起使用 - Use Multi Image Picker with Image Cropper 我正在使用 image_picker 从画廊和相机获取图像,但尺寸太小 - I am using image_picker to get image from gallery and camera but size is to small 我正在尝试使用 getx 获取 slider 图像但出现错误 - i am trying to fetch slider image using getx but having error 我用图像选择器和图像裁剪器包制作了一个简单的应用程序,在编写此代码时出现此错误,空值检查运算符用于空值 - I made a simple app with image picker and image cropper pakage and when writing this code i got this error, Null check operator used on a null value 在颤振中使用图像选择器和 web_image_picker 时出错 - Error while using image picker and web_image_picker in flutter 我无法使用 http 和 flutter web 的图像选择器将图像上传到后端 - I am unable to upload an image to the backend using http and image picker for flutter web 图像裁剪器在 GetxController 中不起作用 - Image cropper not working in GetxController 如何使用 image_cropper 包裁剪图像? - how to crop image in flutter using image_cropper package? Flutter 我试图将图像裁剪/调整为 1:1 比例,但在使用 image_cropper 时出现问题 package - Flutter i trying to crop/resize image into 1:1 ratio but i got a problem when i use image_cropper package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM