https://github.com/mchtsen/ai_profanity_textfield
pub.dev package that provide an ai profanity checker
https://github.com/mchtsen/ai_profanity_textfield
ai flutter profanity textfield-validation
Last synced: about 2 months ago
JSON representation
pub.dev package that provide an ai profanity checker
- Host: GitHub
- URL: https://github.com/mchtsen/ai_profanity_textfield
- Owner: MCHTSEN
- License: mit
- Created: 2024-07-05T17:58:48.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-30T12:14:30.000Z (over 1 year ago)
- Last Synced: 2025-10-23T04:51:42.046Z (8 months ago)
- Topics: ai, flutter, profanity, textfield-validation
- Language: Dart
- Homepage:
- Size: 300 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`:
```yaml
dependencies:
ai_profanity_textfield: ^1.0.0
```
### Get Your API Key
1. Visit [Google AI Studio](https://makersuite.google.com/app/apikey)
2. Sign in with your Google account
3. Click "Create API Key"
4. Copy your API key
### Quick Start π
```dart
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!
```dart
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 π
1. Custom validators run first in the order they are defined
2. If all custom validations pass, AI profanity check runs
3. Text is considered valid only when both custom validations and profanity check pass
### Multilingual Example π
```dart
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:
```dart
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:
```dart
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:
```dart
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>?` | 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
```dart
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
```dart
ProfanityTextFormField(
geminiService: geminiService,
decoration: InputDecoration(
labelText: 'Comment',
hintText: 'Share your thoughts...',
),
maxLines: 3,
clearOnProfanity: true,
profanityMessage: 'Please keep comments friendly!',
)
```
### Search Field
```dart
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](CONTRIBUTING.md) for details.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License π
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
## Support πͺ
If you like this package, please give it a βοΈ on [GitHub](https://github.com/yourusername/ai_profanity_textfield)!
For bugs or feature requests, please [create an issue](https://github.com/yourusername/ai_profanity_textfield/issues).