flutter_nsfw_detector_text 0.0.2
flutter_nsfw_detector_text: ^0.0.2 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@ck→fuck). - Multiple Loaders: Load wordlists from
Set, JSON strings, JSON decoded lists, or via async HTTP fetchers (Dio, http). - Native ML Bridge: Includes the
NativeModelTextClassifierabstract interface for building multi-layered pipelines. - Flutter Helpers: Includes
NsfwTextInputFormatterandNsfwTextValidatorfor 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
),
],
)