0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Flutter/ Dart】外部アプリを起動して画像をシェアする方法

Last updated at Posted at 2020-08-24

概要

共有(シェア)機能を実装するために試行錯誤した結果、採用した方法を記します。

結論

esys_flutter_share を使って簡単に実装できました。

ちなみに他に試したのは下記です。

  • Platform Channelsを使ってネイティブのコードに処理を委譲(外部アプリを起動)する。
  • shareプラグイン(画像のシェアができず断念)

設定

pubspec.yaml
dependencies:
  esys_flutter_share: [version]

flutter pub getを忘れずに

コード

impportして

.dart
import 'package:esys_flutter_share/esys_flutter_share.dart';

この2行だけで終わり!

.dart
final ByteData bytes = await rootBundle.load('assets/image.png');
      await Share.file('タイトル', 'ファイル名', bytes.buffer.asUint8List(), 'image/png', text: '本文');

複数ファイルのシェアやHTTP経由で取得した画像のシェアも簡単にできるようです。

参考

pub.dev

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?