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! ✨

ai_profanity

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

Get Your API Key

  1. Visit Google AI Studio
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Copy your API key

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 πŸ”„

  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 🌐

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.

  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 file for details.


Support πŸ’ͺ

If you like this package, please give it a ⭐️ on GitHub!

For bugs or feature requests, please create an issue.