En | Ru
Flutter widget for censoring text based on predefined patterns with customizable strategies. Built on top of censor_it package.
For better understanding how it works check demo page
When it comes to censoring profanity in your Flutter application, you might need
to handle multiple languages and customize the visual representation of censored
content. CensorItWidget provides an easy-to-use solution with three distinct
censoring strategies.
- 🇺🇸 English (EN)
- 🇫🇮 Finnish (FI)
- 🇫🇷 French (FR)
- 🇩🇪 German (DE)
- 🇮🇹 Italian (IT)
- 🇰🇿 Kazakh (KK)
- 🇱🇻 Latvian (LV)
- 🇱🇹 Lithuanian (LT)
- 🇵🇹 Portuguese (PT)
- 🇵🇱 Polish (PL)
- 🇷🇺 Russian (RU)
- 🇪🇸 Spanish (ES)
- 🇸🇪 Swedish (SV)
- 🇺🇦 Ukrainian (UK)
Add censor_it_flutter to your pubspec.yaml:
dependencies:
censor_it_flutter: ^2.1.1Or using the command:
flutter pub add censor_it_flutterImport the package in your Dart file:
import 'package:censor_it_flutter/censor_it_flutter.dart';import 'package:flutter/material.dart';
import 'package:censor_it_flutter/censor_it_flutter.dart';
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: CensorItWidget.textBuilder(
'Holy shit, this fucking works!',
builder: (context, word) => '[censored]',
pattern: LanguagePattern.english,
censoredStyle: TextStyle(
color: Colors.red,
fontWeight: .bold,
),
),
),
),
);
}
}CensorItWidget v2.0.0 introduces three factory constructors for different censoring strategies:
Replaces profanity with custom text.
CensorItWidget.textBuilder(
'Fuck this shit!',
builder: (context, word) => '[censored]',
pattern: LanguagePattern.english,
style: TextStyle(color: Colors.black),
censoredStyle: TextStyle(color: Colors.red, fontWeight: .bold),
)Output: "Fuck [censored] this shit [censored]!" (censored words in
red)
Use case: Simple text-based censoring with custom styling.
Replaces profanity with Flutter widgets.
CensorItWidget.widgetBuilder(
'Fuck this shit!',
builder: (context, word) => Icon(Icons.block, size: 16, color: Colors.red),
pattern: LanguagePattern.english,
alignment: .middle,
)Output: "🚫 this 🚫!" (profanity replaced with icons)
Use case: Visual censoring with icons, images, or custom widgets.
Applies visual effects over profanity while keeping original text in layout.
CensorItWidget.overlayBuilder(
'Fuck this shit!',
builder: (context, word, revealed) => Container(
decoration: BoxDecoration(
color: revealed ? Colors.transparent : Colors.black.withOpacity(0.8),
borderRadius: .circular(4),
),
),
pattern: LanguagePattern.english,
onTap: (revealed) => !revealed, // Tap to reveal/hide
)Output: Profanity covered with dark overlay, tap to reveal
Use case: Interactive censoring with blur effects, overlays, or tap-to-reveal.
CensorItWidget.textBuilder(
'Fuck this shit!',
builder: (context, word) {
// Different replacements based on word length
if (word.length > 4) return '[CENSORED]';
return '***';
},
pattern: LanguagePattern.english,
)CensorItWidget.widgetBuilder(
'Fuck this!',
builder: (context, word) => Container(
padding: .symmetric(horizontal: 4, vertical: 2),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: .circular(4),
),
child: Text('***', style: TextStyle(color: Colors.white, fontSize: 10)),
),
pattern: LanguagePattern.english,
alignment: .middle,
baseline: .alphabetic,
)import 'dart:ui';
CensorItWidget.overlayBuilder(
'Fuck this!',
builder: (context, word, revealed) => ClipRRect(
child: BackdropFilter(
filter: .blur(
sigmaX: revealed ? 0 : 5,
sigmaY: revealed ? 0 : 5,
),
child: Container(color: Colors.transparent),
),
),
pattern: LanguagePattern.english,
onTap: (revealed) => !revealed,
)Use case: Elegant blur effect that can be toggled.
CensorItWidget.overlayBuilder(
'Fuck this!',
builder: (context, word, revealed) => AnimatedContainer(
duration: Duration(milliseconds: 300),
decoration: BoxDecoration(
gradient: revealed
? null
: LinearGradient(colors: [Colors.purple, Colors.blue]),
borderRadius: .circular(4),
),
),
pattern: LanguagePattern.english,
onTap: (revealed) => !revealed,
)Use case: Smooth animated transitions for reveal/hide.
// Single language
CensorItWidget.textBuilder(
'Fuck this!',
builder: (context, word) => '***',
pattern: LanguagePattern.english,
)
// All languages
CensorItWidget.textBuilder(
'Fuck this блять!',
builder: (context, word) => '***',
pattern: LanguagePattern.all,
)// Combine specific languages
CensorItWidget.textBuilder(
'Fuck this puta!',
builder: (context, word) => '***',
pattern: CensorPattern.multi([
LanguagePattern.english,
LanguagePattern.spanish,
]),
)// Get pattern by locale code
final latvian = LanguagePattern.fromLocale('lv');
CensorItWidget.textBuilder(
'pizdets',
builder: (context, word) => '***',
pattern: latvian,
)
// Multiple locales
final multi = LanguagePattern.fromLocales(['en', 'es']);
CensorItWidget.textBuilder(
'fuck this puta',
builder: (context, word) => '***',
pattern: multi,
)// Create custom pattern with RegExp
final customPattern = CensorPattern.fromRegExp(
RegExp(r'badword|anotherbad', caseSensitive: false),
);
CensorItWidget.textBuilder(
'badword here',
builder: (context, word) => '[censored]',
pattern: customPattern,
)- Three Censoring Strategies: Choose from text, widget, or overlay-based censoring
- Factory Constructors: Clean API with
CensorItWidget.textBuilder(),CensorItWidget.widgetBuilder(), etc. - Custom Styling: Separate
styleandcensoredStylefor normal and censored text - Interactive:
onTapcallback for reveal/hide functionality in overlay builder - Widget Alignment: Control vertical alignment with
PlaceholderAlignmentandTextBaseline - Profanity Detection: Built on
censor_itpackage with robust pattern matching - Multilingual Support: 14+ languages with Unicode support
- High Performance: Optimized text span building for smooth rendering
- ✅
CensorItWidget.textBuilder()- Replace with custom text - ✅
CensorItWidget.widgetBuilder()- Replace with widgets - ✅
CensorItWidget.overlayBuilder()- Apply visual effects
- ✅
censoredStyle- Custom styling for censored text - ✅
onTap- Interactive tap-to-reveal in overlay builder - ✅
alignment- Widget vertical alignment control - ✅
baseline- Baseline alignment for widgets
- ❌ Removed direct constructor - Use factory constructors
- ❌ Removed
charsparameter - Implement in builder function - ❌ Renamed
CensorPatterntoLanguagePattern
See MIGRATION.md for upgrade instructions.
The list of changes is available in the file CHANGELOG.md
Feel free to contribute to this project. If you find a bug or want to add a new feature but don't know how to fix/implement it, please write in issues. If you fixed a bug or implemented some feature, please make pull request.
MIT License - see LICENSE file for details
