I have a flutter firebase app and i am trying to track progress of video upload from the moment it is selected from google drive
Through observation what i understand is that google drive first downloads the video to the device then uploads it to firebase storage but during the time it is downloading from drive on to device i am unable to track it here's the code i am using for file upload and progress tracking
Align(
alignment: const AlignmentDirectional(0.0, -1.0),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Align(
alignment: const AlignmentDirectional(0.0, 0.0),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Align(
alignment:
const AlignmentDirectional(0.0, -1.0),
child: Text(
FFLocalizations.of(context).getText(
'ayvkafvm' /* Upload Video */,
),
textAlign: TextAlign.center,
style: FlutterFlowTheme.of(context)
.bodyMedium
.override(
fontFamily:
FlutterFlowTheme.of(context)
.bodyMediumFamily,
letterSpacing: 0.0,
useGoogleFonts: GoogleFonts.asMap()
.containsKey(
FlutterFlowTheme.of(context)
.bodyMediumFamily),
),
),
),
Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
0.0, 0.0, 17.0, 0.0),
child: FlutterFlowIconButton(
borderColor: Colors.transparent,
borderRadius: 30.0,
borderWidth: 1.0,
buttonSize: 40.0,
icon: Icon(
Icons.video_call,
color:
FlutterFlowTheme.of(context).primary,
size: 24.0,
),
onPressed: () async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(
type: FileType.video,
allowMultiple: false,
);
if (result != null) {
File file =
File(result.files.single.path!);
String fileName =
result.files.single.name;
try {
final Reference storageRef =
FirebaseStorage.instance
.ref()
.child('videos/$fileName');
final UploadTask uploadTask =
storageRef.putFile(file);
// Show upload progress
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
content:
StreamBuilder<TaskSnapshot>(
stream:
uploadTask.snapshotEvents,
builder: (context, snapshot) {
if (snapshot.hasData) {
final progress = snapshot
.data!
.bytesTransferred /
snapshot
.data!.totalBytes;
return Column(
mainAxisSize:
MainAxisSize.min,
children: [
CircularProgressIndicator(
value: progress),
const SizedBox(
height: 10),
Text(
'${(progress * 100).toStringAsFixed(2)}%'),
const SizedBox(
height: 10),
Text(
'Uploading: ${fileName}'),
],
);
} else {
return const SizedBox();
}
},
),
);
},
);
// Wait for the upload to complete
await uploadTask;
// Get the download URL
String downloadURL =
await storageRef.getDownloadURL();
// Close the progress dialog
Navigator.of(context).pop();
// Update the model with the new URL
setState(() {
_model.uploadedFileUrl1 =
downloadURL;
});
// Clear cache after successful upload
await DefaultCacheManager()
.emptyCache();
ScaffoldMessenger.of(context)
.showSnackBar(
const SnackBar(
content: Text(
'Video uploaded successfully')),
);
} catch (e) {
print('Error uploading video: $e');
ScaffoldMessenger.of(context)
.showSnackBar(
const SnackBar(
content: Text(
'Failed to upload video')),
);
}
}
},
),
),
],
),
),
],
),
),
Source: View source