Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PlatformFile? pickedFile;
- UploadTask? uploadTask;
- Future selectFile()async{
- //final File fileForFirebase = File("${pickedFile!.path}");
- final result= await FilePicker.platform.pickFiles();
- if (result==null) return;
- setState(() {
- pickedFile=result.files.first;
- });
- try {
- final path = 'postfiles/${pickedFile!.name}';
- final file = File(pickedFile!.path!);
- final ref = FirebaseStorage.instance.ref().child(path);
- uploadTask = ref.putFile(file);
- final imageUrl = await uploadTask!.whenComplete(() {});
- final urlDownload = await imageUrl.ref.getDownloadURL();
- print('firebase File =$urlDownload');
- setState(() {
- postfileController.text = urlDownload;
- });
- } catch (e) {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(
- content: Text(
- 'check your details /network, and try again',
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement