Skip to content

Commit f9fdadb

Browse files
authored
feat(share_plus): Added excludedCupertinoActivities share parameter (#3376)
1 parent 1b37ba2 commit f9fdadb

File tree

8 files changed

+458
-201
lines changed

8 files changed

+458
-201
lines changed

packages/share_plus/share_plus/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ if (result.status == ShareResultStatus.dismissed) {
110110
}
111111
```
112112

113+
On iOS or macOS, if you want to exclude certain options from appearing in your share sheet,
114+
you can set the excludedActivityTypes array.
115+
For the list of supported excludedActivityTypes, you can refer to [CupertinoActivityType](https://pub.dev/documentation/share_plus/latest/share_plus/ShareParams-class.html).
116+
117+
```dart
118+
ShareParams(
119+
// rest of params
120+
excludedActivityTypes: [CupertinoActivityType.postToFacebook],
121+
)
122+
```
123+
113124
On web, this uses the [Web Share API](https://web.dev/web-share/)
114125
if it's available. Otherwise it falls back to downloading the shared files.
115126
See [Can I Use - Web Share API](https://caniuse.com/web-share) to understand
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:share_plus/share_plus.dart';
3+
4+
class ExcludedCupertinoActivityTypePage extends StatefulWidget {
5+
final List<CupertinoActivityType>? excludedActivityType;
6+
7+
const ExcludedCupertinoActivityTypePage({
8+
super.key,
9+
this.excludedActivityType,
10+
});
11+
12+
@override
13+
State<StatefulWidget> createState() => _ExcludedActivityTypePageState();
14+
}
15+
16+
class _ExcludedActivityTypePageState
17+
extends State<ExcludedCupertinoActivityTypePage> {
18+
final List<String> options = [];
19+
final List<String> selected = [];
20+
21+
@override
22+
void initState() {
23+
for (final type in CupertinoActivityType.values) {
24+
options.add(type.value);
25+
}
26+
if (widget.excludedActivityType != null &&
27+
widget.excludedActivityType!.isNotEmpty) {
28+
for (final type in widget.excludedActivityType!) {
29+
selected.add(type.value);
30+
}
31+
}
32+
super.initState();
33+
}
34+
35+
@override
36+
Widget build(BuildContext context) {
37+
return Scaffold(
38+
appBar: AppBar(
39+
title: const Text('Excluded Activity Type'),
40+
actions: [
41+
IconButton(
42+
icon: const Icon(Icons.check),
43+
onPressed: () {
44+
final List<CupertinoActivityType> tempSelected = [];
45+
for (final String type in selected) {
46+
tempSelected.add(
47+
CupertinoActivityType.values
48+
.firstWhere((e) => e.value == type),
49+
);
50+
}
51+
Navigator.pop(context, tempSelected);
52+
},
53+
),
54+
],
55+
),
56+
body: ListView(
57+
children: options.map((option) {
58+
return CheckboxListTile(
59+
value: selected.contains(option),
60+
title: Text(option),
61+
controlAffinity: ListTileControlAffinity.leading,
62+
onChanged: (bool? checked) {
63+
setState(() {
64+
if (checked == true) {
65+
selected.add(option);
66+
} else {
67+
selected.remove(option);
68+
}
69+
});
70+
},
71+
);
72+
}).toList(),
73+
),
74+
);
75+
}
76+
}

0 commit comments

Comments
 (0)