Skip to content

feat(share_plus): Added excludedActivityTypes support for the iOS platform. #3376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/share_plus/share_plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ if (result.status == ShareResultStatus.dismissed) {
}
```

On iOS or macOS, if you want to exclude certain options from appearing in your share sheet,
you can set the excludedActivityTypes array.
For the list of supported excludedActivityTypes, you can refer to [CupertinoActivityType](https://pub.dev/documentation/share_plus/latest/share_plus/ShareParams-class.html).

```dart
ShareParams(
// rest of params
excludedActivityTypes: [CupertinoActivityType.postToFacebook],
)
```

On web, this uses the [Web Share API](https://web.dev/web-share/)
if it's available. Otherwise it falls back to downloading the shared files.
See [Can I Use - Web Share API](https://caniuse.com/web-share) to understand
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';

class ExcludedCupertinoActivityTypePage extends StatefulWidget {
final List<CupertinoActivityType>? excludedActivityType;

const ExcludedCupertinoActivityTypePage({
super.key,
this.excludedActivityType,
});

@override
State<StatefulWidget> createState() => _ExcludedActivityTypePageState();
}

class _ExcludedActivityTypePageState
extends State<ExcludedCupertinoActivityTypePage> {
final List<String> options = [];
final List<String> selected = [];

@override
void initState() {
for (final type in CupertinoActivityType.values) {
options.add(type.value);
}
if (widget.excludedActivityType != null &&
widget.excludedActivityType!.isNotEmpty) {
for (final type in widget.excludedActivityType!) {
selected.add(type.value);
}
}
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Excluded Activity Type'),
actions: [
IconButton(
icon: const Icon(Icons.check),
onPressed: () {
final List<CupertinoActivityType> tempSelected = [];
for (final String type in selected) {
tempSelected.add(
CupertinoActivityType.values
.firstWhere((e) => e.value == type),
);
}
Navigator.pop(context, tempSelected);
},
),
],
),
body: ListView(
children: options.map((option) {
return CheckboxListTile(
value: selected.contains(option),
title: Text(option),
controlAffinity: ListTileControlAffinity.leading,
onChanged: (bool? checked) {
setState(() {
if (checked == true) {
selected.add(option);
} else {
selected.remove(option);
}
});
},
);
}).toList(),
),
);
}
}
Loading
Loading