esys_flutter_share 0.0.2 esys_flutter_share: ^0.0.2 copied to clipboard
A Flutter plugin for sharing images & text with other applications.
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
// for details.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart';
void main() => runApp(MaterialApp(
home: MaterialApp(
home: MyHomePage(),
),
));
class MyHomePage extends StatefulWidget {
MyHomePage();
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Esys Share Plugin Sample'),
),
body: Container(
padding: const EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
MaterialButton(
child: Text('Share text'),
onPressed: () async => await _shareText(),
),
MaterialButton(
child: Text('Share image'),
onPressed: () async => await _shareImage(),
),
],
)));
}
Future _shareText() async {
try {
await EsysFlutterShare.shareText(
'This is my text to share with other applications.', 'my text title');
} catch (e) {
print('error: $e');
}
}
Future _shareImage() async {
try {
final ByteData bytes = await rootBundle.load('assets/image.png');
await EsysFlutterShare.shareImage(
'myImageTest.png', bytes, 'my image title');
} catch (e) {
print('error: $e');
}
}
}