flutter_nsfw_detector_text 0.0.3
flutter_nsfw_detector_text: ^0.0.3 copied to clipboard
Pure-Dart text content filtering with keyword matching, profanity detection, and leet-speak normalization.
import 'package:flutter/material.dart';
import 'package:flutter_nsfw_detector_text/flutter_nsfw_detector_text.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Text Filter Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
// 1. Initialize the scanner with some basic rules
final scanner = TextScanner(
filters: [
ProfanityFilter(words: {'badword1', 'badword2'}),
KeywordFilter(keywords: {'drugs'}),
],
);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Text Filter Example')),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Text('Try typing "badword1" or "drugs" below:'),
const SizedBox(height: 16),
TextField(
// 2. Attach the formatter for real-time censoring
inputFormatters: [
NsfwTextInputFormatter(
scanner: scanner,
mode: NsfwInputMode.censorInPlace,
),
],
decoration: const InputDecoration(
border: OutlineInputBorder(),
hintText: 'Enter some text...',
),
),
],
),
),
);
}
}