fp_resumable_uploads 0.0.3+native-patch
fp_resumable_uploads: ^0.0.3+native-patch copied to clipboard
The FlutterResumableUploads package provides functionality for uploading large video files in chunks, allowing for pausing and resuming uploads as needed.
example/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:fp_resumable_uploads/flutter_resumable_uploads.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Resumable Uploads Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const UploadPage(),
);
}
}
class UploadPage extends StatefulWidget {
const UploadPage({super.key});
@override
_UploadPageState createState() => _UploadPageState();
}
class _UploadPageState extends State<UploadPage> {
// Variables to hold progress and error information
String _status = '';
int _currentChunkIndex = 0;
int _totalChunks = 0;
double _uploadPercentage = 0.0;
String _errorMessage = '';
@override
void initState() {
super.initState();
// Listen for progress updates
}
void _startUpload() async {
try {
final File file =
File('path/to/your/video.mp4'); // Replace with your file path
const String signedUrl =
'https://example.com/upload'; // Replace with your signed URL
await FlutterResumableUploads.uploadVideo(
file: file,
signedUrl: signedUrl,
chunkSize: 10, // Optional: set chunk size in MB
onProgress: (progress) {
setState(() {
_status = progress.status;
_currentChunkIndex = progress.currentChunkIndex;
_totalChunks = progress.totalChunks;
_uploadPercentage = progress.uploadPercentage;
});
},
onError: (error) {
setState(() {
_errorMessage = error.message;
});
},
);
} catch (e) {
// Handle any exceptions that might occur during upload
setState(() {
_errorMessage = 'An unexpected error occurred: ${e.toString()}';
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Upload Video'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
// Button to start the upload
ElevatedButton(
onPressed: _startUpload,
child: const Text('Start Upload'),
),
const SizedBox(height: 20),
// Display the progress
if (_status.isNotEmpty) ...[
Text('Status: $_status'),
Text('Chunk $_currentChunkIndex of $_totalChunks'),
Text('Upload Progress: ${_uploadPercentage.toStringAsFixed(2)}%'),
],
const SizedBox(height: 20),
// Display the error message
if (_errorMessage.isNotEmpty) ...[
Text('Error: $_errorMessage',
style: const TextStyle(color: Colors.red)),
],
],
),
),
);
}
}