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

A secure Scoped Storage downloads saver plugin supporting modern Android MediaStore Scoped Storage and iOS documents folder.

example/lib/main.dart

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:better_download_saver/better_download_saver.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _statusMessage = 'Press the button to save a test PDF';
  final _scopedDownloadsSaverPlugin = BetterDownloadSaver();

  Future<void> _saveTestFile() async {
    setState(() {
      _statusMessage = 'Saving file...';
    });

    try {
      // Mock PDF bytes (100 bytes of mock data)
      final Uint8List testBytes = Uint8List.fromList(List.generate(100, (i) => i));
      
      final result = await _scopedDownloadsSaverPlugin.saveToDownloads(
        fileName: 'test_file_save.pdf',
        bytes: testBytes,
      );

      setState(() {
        if (result != null) {
          _statusMessage = 'File saved successfully at:\n$result';
        } else {
          _statusMessage = 'Failed to save file.';
        }
      });
    } catch (e) {
      setState(() {
        _statusMessage = 'Error saving file: $e';
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Better Download Saver Example'),
        ),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  _statusMessage,
                  textAlign: TextAlign.center,
                  style: const TextStyle(fontSize: 16),
                ),
                const SizedBox(height: 24),
                ElevatedButton(
                  onPressed: _saveTestFile,
                  child: const Text('Save Test PDF'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
1
likes
150
points
34
downloads

Documentation

API reference

Publisher

verified publisherjhonaiquel.com

Weekly Downloads

A secure Scoped Storage downloads saver plugin supporting modern Android MediaStore Scoped Storage and iOS documents folder.

Homepage

License

BSD-2-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on better_download_saver

Packages that implement better_download_saver