今天要分像透過share_plus,分享文字、連結和圖片
下載套件
flutter pub add share_plus
建立share_screen.dart,輸入下方程式碼
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
class ShareScreen extends StatelessWidget {
const ShareScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Share.share("https://flutter.dev/");
},
child: const Text("Share Link"),
),
SizedBox(
height: 30,
),
ElevatedButton(
onPressed: () {
Share.share("Share Text", subject: 'Share Text');
},
child: const Text("Share Text"),
),
],
),
));
}
}