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

outdated

A plugin to share text, images and files. Written in Kotlin and Swift for both Android and iOS. It uses official APIs and the Dart interface provides specific methods for each platform but also genera [...]

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;
  }
}
26
likes
0
pub points
83%
popularity

Publisher

unverified uploader

A plugin to share text, images and files. Written in Kotlin and Swift for both Android and iOS. It uses official APIs and the Dart interface provides specific methods for each platform but also general methods that are platform independant.

Homepage
Repository (GitLab)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on share_it