Advertisement
jevixlugya

download indicator

Sep 9th, 2024
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.98 KB | None | 0 0
  1.   PlatformFile? pickedFile;
  2.  
  3.   UploadTask? uploadTask;
  4.   Future selectFile()async{
  5.     //final File fileForFirebase = File("${pickedFile!.path}");
  6.     final result= await FilePicker.platform.pickFiles();
  7.     if (result==null) return;
  8.     setState(() {
  9.       pickedFile=result.files.first;
  10.     });
  11.  
  12.     try {
  13.       final path = 'postfiles/${pickedFile!.name}';
  14.       final file = File(pickedFile!.path!);
  15.       final ref = FirebaseStorage.instance.ref().child(path);
  16.       uploadTask = ref.putFile(file);
  17.       final imageUrl = await uploadTask!.whenComplete(() {});
  18.       final urlDownload = await imageUrl.ref.getDownloadURL();
  19.       print('firebase File =$urlDownload');
  20.  
  21.  
  22.  
  23.       setState(() {
  24.         postfileController.text = urlDownload;
  25.       });
  26.     } catch (e) {
  27.       ScaffoldMessenger.of(context).showSnackBar(
  28.         const SnackBar(
  29.           content: Text(
  30.             'check your details /network, and try again',
  31.           ),
  32.         ),
  33.       );
  34.     }
  35.  
  36.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement