|
| 1 | +--- |
| 2 | +title: Protect your app's sensitive content |
| 3 | +short-title: Sensitive content |
| 4 | +description: >- |
| 5 | + Learn how to protect sensitive content in your Flutter app. |
| 6 | +--- |
| 7 | + |
| 8 | +This feature is available on Android API 35+, and you can try it out by using |
| 9 | +the [`SensitiveContent`] widget. See the guide below for details. |
| 10 | + |
| 11 | +## About the `SensitiveContent` widget |
| 12 | + |
| 13 | +You can use the `SensitiveContent` widget in your app to set the content |
| 14 | +sensitivity of a child `Widget` to one of the following [`ContentSensitivity`] |
| 15 | +values: `notSensitive`, `sensitive`, or `autoSensitive`. The mode that you |
| 16 | +choose helps to determine if the device screen should be obscured |
| 17 | +(blacked out) during media projection to protect users’ sensitive data. |
| 18 | + |
| 19 | +You can have as many `SensitiveContent` widgets in your app as you wish, |
| 20 | +but if _any_ one of those widgets has a `sensitive` content value, then the |
| 21 | +screen will be obscured during media projection. Thus, for most use cases, |
| 22 | +using multiple `SensitiveContent` widgets provides no advantage over having |
| 23 | +one `SensitiveContent` widget in your app’s widget tree. This feature is |
| 24 | +available on Android API 35+ and has no effect on lower API versions and |
| 25 | +other platforms. |
| 26 | + |
| 27 | +:::note |
| 28 | +The `autoSensitive` value isn't supported as of Flutter 3.35 and behaves |
| 29 | +the same as `notSensitive`. See the [Issue #160879][] for more information. |
| 30 | +::: |
| 31 | + |
| 32 | +## Using the `SensitiveContent` widget |
| 33 | + |
| 34 | +Given some content that you want to protect from media screen share |
| 35 | +(for example, a `MySensitiveContent()` widget), you can wrap it with the |
| 36 | +`SensitiveContent` widget as shown in the following example: |
| 37 | + |
| 38 | +```dart |
| 39 | +class MyWidget extends StatelessWidget { |
| 40 | + ... |
| 41 | + Widget build(BuildContext context) { |
| 42 | + return SensitiveContent( |
| 43 | + sensitivivity: ContentSensitivity.sensitive, |
| 44 | + child: MySensitiveContent(), |
| 45 | + ); |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +When running on Android API 34 and below, the screen will not been obscured |
| 51 | +during media projection. The widget will exist in the tree but has no other |
| 52 | +effect, and you do not need to avoid usages of `SensitiveContent` on platforms |
| 53 | +that do not support this feature. |
| 54 | + |
| 55 | +## For more information |
| 56 | + |
| 57 | +For more information, visit the [`SensitiveContent`][] |
| 58 | +and [`ContentSensitivity`][] API docs. |
| 59 | + |
| 60 | +[`SensitiveContent`]: {{site.api}}/flutter/widgets/SensitiveContent-class.html |
| 61 | +[`ContentSensitivity`]: {{site.api}}/flutter/services/ContentSensitivity.html |
| 62 | +[Issue #160879]: {{site.github}}/flutter/flutter/issues/160879 |
0 commit comments