Beginning FlutterFire

Aug 30 2022 · Dart 2.16, Flutter 3.0, Visual Studio Code 1.69

Part 4: Save Pictures to Cloud Storage

19. Upload Data to Cloud Storage

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 18. Add Pictures in the Screen Next episode: 20. Download Data from Cloud Storage

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

For each Activity, users will be able to upload an image from the device gallery. For that, you’ll use the ImagePicker plugin.

Image? activityImage; 
XFile? galleryImage; 
Future choosePicture() async { 
    final _picker = ImagePicker(); 
    final image = await _picker.pickImage(source: ImageSource.gallery); 
    setState(() { 
      galleryImage = image; 
    }); 
  } 
  Future uploadPicture() async { 
    if (galleryImage != null) { 
      final file = File(galleryImage!.path); 
      helper.uploadImage(file); 
    } 
  } 
    if (widget.activity.imagePath != null && widget.activity.imagePath != '') { 
      helper.getImage(widget.activity.imagePath!).then((dynamic value) { 
        activityImage = Image.network(value.toString()); 
        setState(() {}); 
      }); 
    } 
if (galleryImage == null && activityImage == null) { 
      activityImage = Image.asset('assets/running.png'); 
    } else if (galleryImage != null && activityImage == null) { 
      activityImage = Image.file(File(galleryImage!.path)); 
    } 
SizedBox( 
    height: 100, 
    child: activityImage, 
  ), 
SizedBox( 
  width: 100, 
  height: 100, 
  child: IconButton( 
    icon: const Icon(Icons.image), 
    onPressed: choosePicture, 
  ), 
), 
onPressed: () { 
  saveUser(); 
  uploadPicture();