flutter_nsfw_detector_text 0.0.3 copy "flutter_nsfw_detector_text: ^0.0.3" to clipboard
flutter_nsfw_detector_text: ^0.0.3 copied to clipboard

Pure-Dart text content filtering with keyword matching, profanity detection, and leet-speak normalization.

flutter_nsfw_detector_text #

Pure-Dart text content filtering for Flutter and Dart applications. Features keyword matching, profanity detection, leet-speak normalization, regex pattern matching, and an abstract Native ML bridge.

Zero Native Dependencies: Works perfectly on iOS, Android, Web, macOS, Windows, Linux, and pure Dart servers.

Features #

  • Blazing Fast O(1) Scanning: Profanity filters use word-boundary tokenization with absolute coordinate tracking.
  • Evasion Detection: Automatically compiles user keywords into padded Regex to catch evasion (e.g., d.r.u.g.s).
  • Leet-speak Normalization: Built-in normalization for character substitution (f@ckfuck).
  • Multiple Loaders: Load wordlists from Set, JSON strings, JSON decoded lists, or via async HTTP fetchers (Dio, http).
  • Native ML Bridge: Includes the NativeModelTextClassifier abstract interface for building multi-layered pipelines.
  • Flutter Helpers: Includes NsfwTextInputFormatter and NsfwTextValidator for easy UI integration.

Getting Started #

1. Initialize a Scanner #

import 'package:flutter_nsfw_detector_text/flutter_nsfw_detector_text.dart';

// Basic keyword scanner
final scanner = TextScanner.keywords({'bad', 'words'});

// Profanity scanner (leet-speak enabled by default)
final profanityScanner = TextScanner.profanity(
  words: {'fuck', 'shit'},
  allowedWords: {'hello'}, // whitelist
);

// Advanced multi-filter scanner
final advancedScanner = TextScanner(
  filters: [
    KeywordFilter(keywords: {'drugs'}, category: FilterCategory.drugs),
    RegexFilter.piiDetector(), // catches emails, phones, credit cards
  ]
);

2. Loading Wordlists from APIs (HTTP/Dio) #

The package doesn't force a specific HTTP client. Use the fromLoader async factory:

// Using package:http
final filter = await KeywordFilter.fromLoader(() async {
  final res = await http.get(Uri.parse('https://api.example.com/words'));
  return Set<String>.from(jsonDecode(res.body));
});

// Using package:dio
final filter = await ProfanityFilter.fromLoader(() async {
  final res = await Dio().get<List>('https://api.example.com/words');
  return Set<String>.from(res.data!.cast<String>());
});

final scanner = TextScanner(filters: [filter]);

3. Flutter UI Integration #

Form Validation (Recommended UX)

TextFormField(
  validator: NsfwTextValidator(
    scanner: myScanner,
    errorMessage: 'Inappropriate content detected',
    showMatchedCategory: true,
  ),
)

Real-time Blocking

TextField(
  inputFormatters: [
    NsfwTextInputFormatter(
      scanner: myScanner,
      mode: NsfwInputMode.rejectChange, // or censorInPlace
    ),
  ],
)
0
likes
160
points
42
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Pure-Dart text content filtering with keyword matching, profanity detection, and leet-speak normalization.

Repository (GitHub)
View/report issues

Topics

#content-moderation #text-moderation #profanity-filter #nsfw

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_nsfw_detector_text