flutterflutter-testimagepicker

In Flutter How to pass image from one class to other?


How to pass image picked from file from one activity to other in flutter...

I am using this code to picked image from gallery.

File? image;



Future pickImage() async {
    try {
      final image = await ImagePicker().pickImage(source: ImageSource.gallery);
      if (image == null) return;
      final imageTemp = File(image.path);
      setState(() => this.image = imageTemp);
    } on PlatformException catch (e) {
      print('Failed to pick image: $e');
    }
  }

I want to pass the variable named image to other class. on button click


Solution

  • set your class as below on which you want to pass image variable,

     class ClassOther extends StatefulWidget {
      @override
      stateClassOther createState() => stateClassOther();
      File image;
      ClassOther({required this.image});
      }