share_and_open_url 0.0.7
share_and_open_url: ^0.0.7 copied to clipboard
share_and_open_url_plugin provides functionality for sharing text and opening URLs. It allows users to easily share content and quickly access web links.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:share_and_open_url/share_and_open_url.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> {
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'),
),
],
),
),
),
);
}
}