native_social_share 0.0.4
native_social_share: ^0.0.4 copied to clipboard
Native Social Share is a Flutter plugin that enables easy file sharing to popular social media platforms directly from your app. Whether you're looking to share images, text, or other file types, this [...]
example/lib/main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:native_social_share/native_social_share.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
File? file;
Future<File> assetToFile(String assetPath) async {
ByteData byteData = await rootBundle.load(assetPath);
Directory tempDir = Directory.systemTemp;
File file = File('${tempDir.path}/${assetPath.split('/').last}');
await file.writeAsBytes(byteData.buffer.asUint8List());
return file;
}
pickFile() async {
final result = await assetToFile('assets/image.jpg');
setState(() {
file = File(result.path);
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: [
if (file != null)
Image.file(file!)
else
const Text(
'No file selected.',
),
ElevatedButton(
onPressed: pickFile,
child: const Text('Pick file'),
),
if (file != null)
Column(
children: [
ElevatedButton(
onPressed: () {
NativeSocialShare.instance
.whatsappShare(file!.path, 'Try this plugin!').then((result){
print(result);
});
},
child: const Text('Share on WhatsApp'),
),
ElevatedButton(
onPressed: () {
NativeSocialShare.instance.whatsappBusinessShare(
file!.path, 'Try this plugin!')
.then((result) {
print(result);
});
},
child: const Text('Share on WhatsApp Business'),
),
ElevatedButton(
onPressed: () {
NativeSocialShare.instance
.facebookShare(file!.path, 'Try this plugin!')
.then((result) {
print(result);
});
},
child: const Text('Share on Facebook'),
),
ElevatedButton(
onPressed: () {
NativeSocialShare.instance
.instagramShare(file!.path, 'Try this plugin!')
.then((result) {
print(result);
});
},
child: const Text('Share on Instagram'),
),
],
)
],
),
),
);
}
}