share_binary 0.2.4 copy "share_binary: ^0.2.4" to clipboard
share_binary: ^0.2.4 copied to clipboard

This library provides the ability to use OS sharing features while handling binary files in dart code.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:share_binary/share_binary.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.light(),
      darkTheme: ThemeData.dark(),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Plugin example app'),
      ),
      body: ListView(
        padding: const EdgeInsets.all(16),
        children: [
          OutlinedButton(
            onPressed: () async {
              final byteData = await rootBundle.load('assets/image.png');
              final bytes = _converter(byteData);
              await const ShareBinary().shareBinary(
                bytes: bytes,
                filename: 'image.png',
                chooserTitle: 'Share binary',
              );
            },
            child: const Text('Share Image'),
          ),
          OutlinedButton(
            onPressed: () async {
              final byteData = await rootBundle.load('assets/pdf.pdf');
              final bytes = _converter(byteData);
              await const ShareBinary().shareBinary(
                bytes: bytes,
                filename: 'pdf.pdf',
                chooserTitle: 'Share pdf',
              );
            },
            child: const Text('Share PDF'),
          ),
          OutlinedButton(
            onPressed: () async {
              final byteData = await rootBundle.load('assets/word.doc');
              final bytes = _converter(byteData);
              await const ShareBinary().shareBinary(
                bytes: bytes,
                filename: 'word.doc',
                chooserTitle: 'Share word(doc)',
              );
            },
            child: const Text('Share Word(doc)'),
          ),
          OutlinedButton(
            onPressed: () async {
              final byteData = await rootBundle.load('assets/word.docx');
              final bytes = _converter(byteData);
              await const ShareBinary().shareBinary(
                bytes: bytes,
                filename: 'word.docx',
                chooserTitle: 'Share word(docx)',
              );
            },
            child: const Text('Share Word(docx)'),
          ),
          OutlinedButton(
            onPressed: () async {
              await const ShareBinary().shareUri(
                uri: Uri.parse("https://www.google.com/"),
                chooserTitle: 'Share URI',
              );
            },
            child: const Text('Share URI'),
          ),
        ],
      ),
    );
  }

  Uint8List _converter(ByteData data) =>
      data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
}
2
likes
160
points
219
downloads

Publisher

unverified uploader

Weekly Downloads

This library provides the ability to use OS sharing features while handling binary files in dart code.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on share_binary