share 0.5.0 share: ^0.5.0 copied to clipboard
Flutter plugin for sharing content via the platform share UI, using the ACTION_SEND intent on Android and UIActivityViewController on iOS.
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:share/share.dart';
void main() {
runApp(new DemoApp());
}
class DemoApp extends StatefulWidget {
@override
DemoAppState createState() => new DemoAppState();
}
class DemoAppState extends State<DemoApp> {
String text = '';
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Share Plugin Demo',
home: new Scaffold(
appBar: new AppBar(
title: const Text('Share Plugin Demo'),
),
body: new Padding(
padding: const EdgeInsets.all(24.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new TextField(
decoration: const InputDecoration(
labelText: 'Share:',
hintText: 'Enter some text and/or link to share',
),
maxLines: 2,
onChanged: (String value) => setState(() {
text = value;
}),
),
const Padding(padding: const EdgeInsets.only(top: 24.0)),
new Builder(
builder: (BuildContext context) {
return new RaisedButton(
child: const Text('Share'),
onPressed: text.isEmpty
? null
: () {
// A builder is used to retrieve the context immediately
// surrounding the RaisedButton.
//
// The context's `findRenderObject` returns the first
// RenderObject in its descendent tree when it's not
// a RenderObjectWidget. The RaisedButton's RenderObject
// has its position and size after it's built.
final RenderBox box = context.findRenderObject();
Share.share(text,
sharePositionOrigin:
box.localToGlobal(Offset.zero) &
box.size);
},
);
},
),
],
),
)),
);
}
}