share_text 0.0.6 copy "share_text: ^0.0.6" to clipboard
share_text: ^0.0.6 copied to clipboard

simple share text plugin for ios and android

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:share_text/share_text.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance
        .addPostFrameCallback((_) {
      final renderBox = context.findRenderObject() as RenderBox?;
      initPlatformState(renderBox);
        });
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState(RenderBox? renderBox) async {
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      if(Platform.isAndroid || Platform.isIOS) {
        await ShareText.shareText('Text for share');
      }
      if(Platform.isMacOS){
        await ShareText.macShareText('Text for share', renderBox);
      }
    } on PlatformException {
      print("Platform exception");
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: const Center(
          child: Text('Sharing...'),
        ),
      ),
    );
  }
}
0
likes
145
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

simple share text plugin for ios and android

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on share_text

Packages that implement share_text