Home > OS >  In Flutter How to pass image from one class to other?
In Flutter How to pass image from one class to other?

Time:12-17

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

CodePudding user response:

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});
  }
  • Related