flutter_file_upload 0.0.1 copy "flutter_file_upload: ^0.0.1" to clipboard
flutter_file_upload: ^0.0.1 copied to clipboard

Advanced cross-platform file upload with progress, chunking, and resume.

example/lib/main.dart

import 'dart:io' show File;
import 'package:flutter/material.dart';
import 'package:flutter_file_upload/flutter_file_upload.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('flutter_file_upload example')),
        body: const Center(child: UploadDemo()),
      ),
    );
  }
}

class UploadDemo extends StatefulWidget {
  const UploadDemo({super.key});

  @override
  State<UploadDemo> createState() => _UploadDemoState();
}

class _UploadDemoState extends State<UploadDemo> {
  double _progress = 0;

  Future<void> _startUpload() async {
    final file = File('path/to/big.file');
    if (!await file.exists()) return;

    final total = await file.length();
    final uploader = FileUploader(createPlatformUploader());

    await uploader.upload(
      Uri.parse('https://example.com/upload'),
      byteStream: file.openRead(),
      totalByteLength: total,
      chunkSizeBytes: 256 * 1024,
      onProgress: (sent, total) => setState(() {
        _progress = total == null || total == 0 ? 0 : sent / total;
      }),
      shouldResumeFrom: (start) async => true,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        LinearProgressIndicator(value: _progress == 0 ? null : _progress),
        const SizedBox(height: 16),
        ElevatedButton(
          onPressed: _startUpload,
          child: const Text('Start Upload'),
        ),
      ],
    );
  }
}
1
likes
160
points
21
downloads

Publisher

verified publisherbechattaoui.dev

Weekly Downloads

Advanced cross-platform file upload with progress, chunking, and resume.

Repository (GitHub)
View/report issues

Topics

#upload #http #file #progress #resumable

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_web_plugins, http, meta, plugin_platform_interface, web

More

Packages that depend on flutter_file_upload