Skip to content

Instantly share code, notes, and snippets.

@Anirudhk07
Created June 24, 2020 12:47
Show Gist options
  • Save Anirudhk07/7098562bad53ecbdb27b566cd54d1810 to your computer and use it in GitHub Desktop.
Save Anirudhk07/7098562bad53ecbdb27b566cd54d1810 to your computer and use it in GitHub Desktop.
Widget build(BuildContext context) {
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
print('Image Path $_image');
});
}
Future uploadPic(BuildContext context) async{
String fileName = basename(_image.path);
StorageReference firebaseStorageRef = FirebaseStorage.instance.ref().child(fileName);
StorageUploadTask uploadTask = firebaseStorageRef.putFile(_image);
StorageTaskSnapshot taskSnapshot=await uploadTask.onComplete;
setState(() {
print("Profile Picture uploaded");
Scaffold.of(context).showSnackBar(SnackBar(content: Text('Profile Picture Uploaded')));
});
}
@Joesta
Copy link

Joesta commented Nov 11, 2020

Can you please share the basename function. Thank you.

@kewlfrogz
Copy link

I had the same issue, they failed to tell you to use the following import package:
import 'package:path/path.dart';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment