NashTech Blog

Protect Sensitive Content in Flutter with SensitiveContent Widget (Android 15+)

Table of Contents

Why does protecting sensitive content matter?

In many apps—banking, healthcare, password managers—you display highly sensitive user data: credit card numbers, medical records, passwords.

If a user accidentally starts screen recording or screen sharing during a meeting, all that private data could be exposed. That’s a huge security and trust issue. Protecting sensitive UI is not only good practice—it’s a requirement for user trust and compliance.

Before Flutter 3.35 — How was this handled?

Android: FLAG_SECURE

Traditionally, Android developers had to manually set FLAG_SECURE to block screenshots and screen recording:

window.setFlags(
  WindowManager.LayoutParams.FLAG_SECURE,
  WindowManager.LayoutParams.FLAG_SECURE
)

In Flutter, you could use plugins like flutter_windowmanager to toggle FLAG_SECURE at runtime

iOS: No direct equivalent

iOS does not provide a direct FLAG_SECURE API. Developers had to use workarounds:

Overlaying a UITextField with secureTextEntry set to true (hacky and risky).

Using libraries like ScreenProtectorKit to show a blur/placeholder when the app is backgrounded.

Blocking screenshots with third-party Flutter plugins like anti_screenshot or secure_content

Problem: These methods often broke UX (e.g., preventing users from taking screenshots for legitimate reasons) and didn’t integrate cleanly with Flutter’s widget tree.

The new way — SensitiveContent in Flutter (Android 15+)

With Android 15 (API 35), Flutter introduces a native solution: the SensitiveContent widget.

This widget lets you declare specific UI areas as sensitive. When screen recording or screen sharing is active, Android will automatically obscure the entire screen if any SensitiveContent widget is marked sensitive.

SensitiveContent(
  sensitivity: ContentSensitivity.sensitive,
  child: MySensitiveWidget(),
);

Possible sensitivity modes:

notSensitive → Always safe.

sensitive → Obscures the screen during media projection.

autoSensitive → Reserved for future use (currently behaves like notSensitive).

Example: Protecting a Checkout Screen

import 'package:flutter/material.dart';

class CheckoutScreen extends StatelessWidget {
  const CheckoutScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Checkout")),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: SensitiveContent(
          sensitivity: ContentSensitivity.sensitive,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              const Text(
                "Payment Details",
                style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
              ),
              const SizedBox(height: 20),
              TextField(
                decoration: const InputDecoration(
                  labelText: "Card Number",
                  border: OutlineInputBorder(),
                ),
                keyboardType: TextInputType.number,
              ),
              const SizedBox(height: 16),
              TextField(
                decoration: const InputDecoration(
                  labelText: "CVV",
                  border: OutlineInputBorder(),
                ),
                obscureText: true,
              ),
              const SizedBox(height: 16),
              ElevatedButton(
                onPressed: () {
                  // Process payment
                },
                child: const Text("Pay Now"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

On Android 15+, this screen is blacked out during screen sharing/recording.

On older Android / iOS, the widget has no effect but won’t break anything.

What about iOS? Will it support this in the future?

Currently, iOS does not support SensitiveContent or a direct equivalent. Apple may introduce something similar in the future, especially as privacy demands grow.

For now, Flutter developers targeting iOS can rely on:

  • secure_content plugin → allows conditional protection on iOS & Android.
  • Overlay blur screens when app backgrounded.
  • Restrict screenshots (with caution, since Apple may reject apps that block all screenshots).

Hybrid example (Android 15+ + iOS fallback)

import 'dart:io' show Platform;
import 'package:secure_content/secure_content.dart';

class SecureSection extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    if (Platform.isAndroid) {
      return SensitiveContent(
        sensitivity: ContentSensitivity.sensitive,
        child: _child(),
      );
    } else if (Platform.isIOS) {
      return SecureContent(
        isSecure: true,
        child: _child(),
      );
    }
    return _child();
  }

  Widget _child() => MySensitiveContent();
}

With the new SensitiveContent widget, protecting user privacy is now simpler and more reliable than ever—especially as Android 15 adoption grows. Start using it today to make your Flutter apps more secure, trustworthy, and future-ready.

For more info, please refer https://docs.flutter.dev/platform-integration/android/sensitive-content

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top