share_and_open_url

share_and_open_url provides functionality for sharing text and opening URLs. It allows users to easily share content and quickly access web links.

Table of contents

Platforms

✅ Android (Kotlin)

✅ iOS (Swift)

Installation

dependencies:
  share_and_open_url: ^0.0.6    

Usage

final class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  final ShareAndOpenUrl _shareAndOpenUrlPlugin = ShareAndOpenUrl();

  Future<void> _shareText() async {
    try {
      await _shareAndOpenUrlPlugin.shareText("Hello from Flutter!");
    } on PlatformException catch (e) {
      throw PlatformException(code: e.code, message: "Failed to share text: '${e.message}'.");
    }
  }

  Future<void> _openUrl() async {
    try {
      await _shareAndOpenUrlPlugin.openUrl("https://flutter.dev/");
    } on PlatformException catch (e) {
      throw PlatformException(code: e.code, message: "Failed to open url: '${e.message}'.");
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ElevatedButton(
                onPressed: _shareText,
                child: const Text('Share Text'),
              ),
              ElevatedButton(
                onPressed: _openUrl,
                child: const Text('Open URL'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Screenshots

License

MIT