sensitive_content_analysis 1.0.0-rc.3 copy "sensitive_content_analysis: ^1.0.0-rc.3" to clipboard
sensitive_content_analysis: ^1.0.0-rc.3 copied to clipboard

Dart package for interacting with Apple's Sensitive Content Analysis Framework.

example/lib/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sensitive_content_analysis/sensitive_content_analysis.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final sca = SensitiveContentAnalysis.instance;

  @override
  void initState() {
    super.initState();
  }

  Future<void> analyzeImage() async {
    try {
      final ImagePicker picker = ImagePicker();

      // Pick an image.
      final XFile? image = await picker.pickImage(source: ImageSource.gallery);

      if (image != null) {
        Uint8List imageData = await image.readAsBytes();

        // Analyze the image for sensitive content.
        bool? isSensitive = await sca.analyzeImage(imageData);
        debugPrint("SENSITIVE: $isSensitive");
      }
    } catch (e) {
      debugPrint(e.toString());
    }
  }

  Future<void> analyzeNetworkImage(String? url) async {
    try {
      if (url != null) {
        // Analyze the image for sensitive content.
        bool? isSensitive = await sca.analyzeNetworkImage(url: url);
        debugPrint("SENSITIVE: $isSensitive");
      }
    } catch (e) {
      debugPrint(e.toString());
    }
  }

  checkPolicy() async {
    int? policy = await sca.checkPolicy();
    debugPrint("Policy: $policy");
  }

  final String? analyzeUrl =
      "https://docs-assets.developer.apple.com/published/517e263450/rendered2x-1685188934.png";

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
            ElevatedButton(
              onPressed: () => analyzeImage(),
              child: const Text("Select Image."),
            ),
            ElevatedButton(
              onPressed: () => analyzeNetworkImage(analyzeUrl),
              child: const Text("Select Network Image."),
            ),
            ElevatedButton(
              onPressed: () => checkPolicy(),
              child: const Text("Check Policy."),
            ),
          ]),
        ),
      ),
    );
  }
}
8
likes
0
pub points
67%
popularity

Publisher

unverified uploader

Dart package for interacting with Apple's Sensitive Content Analysis Framework.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on sensitive_content_analysis