share_it 0.1.0+1 copy "share_it: ^0.1.0+1" to clipboard
share_it: ^0.1.0+1 copied to clipboard

outdated

A plugin to share text, images and files.

example/lib/main.dart

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

import 'package:share_it/share_it.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:path_provider/path_provider.dart' show getApplicationDocumentsDirectory;
import 'package:path/path.dart' show join;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: <Widget>[
            Image.asset('assets/avatar.png'),
            FlatButton(
              child: const Text("Share text"),
              onPressed: () {
                ShareIt.text(content: 'Hello!!!', androidSheetTitle: 'Title here!!');
              },
            ),
            FlatButton(
              child: Text('Share image'),
              onPressed: () async {
                ShareIt.file(path: await _imageBundlePath, type: ShareItFileType.image);
              },
            )
          ],
        ),
      ),
    );
  }

  Future<String> get _imageBundlePath async {
    final directory = await getApplicationDocumentsDirectory();
    final filePath = join(directory.path, "avatar.png");
    final bundleData = await rootBundle.load('assets/avatar.png');
    List<int> bytes = bundleData.buffer.asUint8List(bundleData.offsetInBytes, bundleData.lengthInBytes);
    final imageFile = await File(filePath).writeAsBytes(bytes);
    return imageFile.path;
  }
}
27
likes
0
points
43
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin to share text, images and files.

Homepage
Repository (GitLab)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on share_it

Packages that implement share_it