AI Profanity TextField π‘οΈ
A smart, AI-powered Flutter text field widget that filters profanity in real-time using Gemini API! Keep your app's content clean and friendly in any language! β¨
Features π
- π Multilingual profanity detection for ALL languages
- π€ AI-powered profanity detection using Gemini
- β Custom validators support
- β‘ Real-time validation while typing
- π¨ Fully customizable appearance
- π Loading indicators and validation states
- β Custom error messages
- β Success indicators
- π Debounce support for optimal performance
Language Support π
Thanks to Gemini's powerful AI capabilities, our widget can detect profanity in:
- English πΊπΈ
- Spanish πͺπΈ
- French π«π·
- German π©πͺ
- Turkish πΉπ·
- Chinese π¨π³
- Japanese π―π΅
- Korean π°π·
- Arabic πΈπ¦
- Russian π·πΊ
- ...and many more!
The AI model understands context and cultural nuances in each language, ensuring accurate profanity detection worldwide! π
Getting Started π
Installation
Add this to your pubspec.yaml
:
dependencies:
ai_profanity_textfield: ^1.0.0
Quick Start π
ProfanityTextFormField(
geminiService: geminiService, // Your Gemini service instance
decoration: InputDecoration(
hintText: 'Enter text here...',
),
onProfanityDetected: (text) {
print('Profanity detected in: $text');
},
)
Custom Validators β¨
Add your own validation rules alongside AI profanity detection!
ProfanityTextFormField(
geminiService: geminiService,
checkWhileTyping: true,
debounceDuration: const Duration(milliseconds: 500),
validators: [
(value) => value.isEmpty ? 'Required field' : null,
(value) => value.length < 3 ? 'Too short' : null,
(value) => !value.contains('@') ? 'Must contain @' : null,
],
onProfanityDetected: (text) => print('Profanity detected!'),
onCleanText: (text) => print('Text is clean and valid'),
decoration: InputDecoration(
hintText: 'Type something...',
fillColor: Colors.white,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
),
),
showValidIcon: true,
profanityMessage: 'Oops! Let\'s keep it friendly π',
validationMessageDuration: const Duration(seconds: 3),
)
Validation Process π
- Custom validators run first in the order they are defined
- If all custom validations pass, AI profanity check runs
- Text is considered valid only when both custom validations and profanity check pass
Multilingual Example π
ProfanityTextFormField(
geminiService: geminiService,
decoration: InputDecoration(
hintText: 'μ¬κΈ°μ ν
μ€νΈλ₯Ό μ
λ ₯νμΈμ...', // Korean
// or 'ε¨ζ€θΎε
₯ζε...' // Chinese
// or 'Γcrivez ici...' // French
// etc.
),
profanityMessage: 'LΓΌtfen nazik olalΔ±m! π', // Turkish
validators: [
// Custom validators work with any language!
(value) {
if (value.length < 5) {
return 'ζε°5ζεεΏ
θ¦γ§γ'; // Japanese error message
}
return null;
},
],
)
Advanced Features π§
Real-time Validation β‘
The widget validates text as users type, with a customizable debounce duration:
ProfanityTextFormField(
geminiService: geminiService,
checkWhileTyping: true,
debounceDuration: Duration(milliseconds: 500),
validators: [
// Custom validators run in real-time too!
(value) => value.length < 3 ? 'Too short!' : null,
],
onCleanText: (text) {
print('Text is clean and valid: $text');
},
)
Custom Styling π¨
Make it match your app's theme:
ProfanityTextFormField(
geminiService: geminiService,
successDecoration: InputDecoration(
fillColor: Colors.green,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
),
),
profanityDecoration: InputDecoration(
fillColor: Colors.red,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(18),
),
),
progressIndicatorColor: Colors.blue,
progressIndicatorSize: 20,
)
Validation States π¦
The widget provides different states with customizable appearances:
- β³ Loading
- β Valid (all custom validators and profanity check passed)
- β Invalid
- π Initial
Error Handling π«
Custom error messages and handlers in any language:
ProfanityTextFormField(
geminiService: geminiService,
profanityMessage: 'Please keep it friendly! π',
validators: [
(value) => value.isEmpty ? 'Field cannot be empty!' : null,
],
onError: (error) {
print('Error occurred: $error');
},
clearOnProfanity: true,
)
Properties π
Property | Type | Description |
---|---|---|
geminiService |
GeminiService |
Required. Your Gemini API service instance |
validators |
List<FormFieldValidator<String>>? |
Custom validation rules |
checkWhileTyping |
bool |
Enable/disable real-time validation |
debounceDuration |
Duration |
Delay before validation triggers |
onProfanityDetected |
Function(String)? |
Callback when profanity is found |
onCleanText |
Function(String)? |
Callback when text is clean and valid |
clearOnProfanity |
bool |
Clear field when profanity detected |
showValidIcon |
bool |
Show/hide validation icons |
profanityMessage |
String |
Custom error message (supports all languages) |
Examples π
Username Field
ProfanityTextFormField(
geminiService: geminiService,
decoration: InputDecoration(
labelText: 'Username',
prefixIcon: Icon(Icons.person),
),
validators: [
(value) => value.length < 3 ? 'Username too short' : null,
(value) => value.contains(' ') ? 'No spaces allowed' : null,
],
)
Comment Field
ProfanityTextFormField(
geminiService: geminiService,
decoration: InputDecoration(
labelText: 'Comment',
hintText: 'Share your thoughts...',
),
maxLines: 3,
clearOnProfanity: true,
profanityMessage: 'Please keep comments friendly!',
)
Search Field
ProfanityTextFormField(
geminiService: geminiService,
decoration: InputDecoration(
labelText: 'Search',
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
),
),
debounceDuration: Duration(milliseconds: 300),
)
Contributing π€
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
License π
This project is licensed under the MIT License - see the LICENSE file for details.
Support πͺ
If you like this package, please give it a βοΈ on GitHub!
For bugs or feature requests, please create an issue.