flutter_share_plus 0.0.3 copy "flutter_share_plus: ^0.0.3" to clipboard
flutter_share_plus: ^0.0.3 copied to clipboard

outdated

Flutter plugin to share text and images

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_share_plus/flutter_share_plus.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
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}


class _HomePageState extends State<HomePage> {

  String _platformVersion = 'Unknown';
  static const _channel = MethodChannel("flutter_share_plus");

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion =
          await FlutterSharePlus.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> share_text(String message) async {
    await _channel.invokeMethod('share_text',<String, String>{
      'message':message
    });
  }

  Future<void> share_multiline_text(String title, String description) async {
    await _channel.invokeMethod('share_multiline_text',<String, String>{
      'title':title,'description':description
    });
  }
  
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
          body: Container(
            alignment: Alignment.center,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[

                Container(
                  margin: EdgeInsets.all(16),
                  child: Text("Platform Version: ${_platformVersion}",
                  style: TextStyle(fontSize: 20,color: Colors.red),),
                ),

                ElevatedButton(
                    onPressed: (){
                      initPlatformState();
                    },
                    child: Text("Click me to get version")
                ),

                ElevatedButton(
                    onPressed: (){
                      share_text("message111");
                    },
                    child: Text("Click me to share single text")
                ),

                ElevatedButton(
                    onPressed: (){
                      share_multiline_text("title111","description111");
                    },
                    child: Text("Click me to share multiple text")
                )


              ],
            ),
          ),
        )
    );
  }
}
4
likes
0
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin to share text and images

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flutter_share_plus

Packages that implement flutter_share_plus