...
/Uploading Files to Firebase Storage
Uploading Files to Firebase Storage
Learn how to upload images to Firebase Storage.
Before we go on to create functions to select and upload images in our app, we need to import the Firebase Storage and image_picker
packages by adding the following line to our pubspec.yaml
file in the dependencies section:
dependencies:
flutter:
sdk: flutter
image_picker: ^0.8.4+3
firebase_storage: ^11.2.5
Next, we import the packages into the dart file we’re using:
import 'package:image_picker/image_picker.dart';
import 'package:firebase_storage/firebase_storage.dart';
Controller
Finally, we are ready to create the function to select and upload the file in five simple steps:
Create a Getxcontroller
class
This step is as simple as it sounds. We create a controller class and add an uploadimage()
function.
class Upload extends GetxController {
void uploadimage(){
}
}
Pick image
The next step is to pick the image from our gallery.
ImagePicker imagePicker = ImagePicker();//Choose source of the imageXFile? file = await imagePicker.pickImage(source: ImageSource.camera);
Line 1: The
ImagePicker
class allows us to access the device’s camera or gallery to pick an image.Line 3: The result of
pickImage
is anXFile
, which represents the picked image file. The question mark (?
) denotes that the variable can ...