flutter_censor_it 2.0.0
flutter_censor_it: ^2.0.0 copied to clipboard
A Flutter widget for censoring text with customizable profanity patterns.
En | Ru
Flutter widget for censoring text based on predefined patterns with customizable strategies. Built on top of censor_it package.
Migration Guide #
Upgrading from v1.x? See the detailed Migration Guide for step-by-step instructions.
Introduction #
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.
Supported languages #
- ๐บ๐ธ English (EN)
- ๐ซ๐ฎ Finnish (FI)
- ๐ซ๐ท French (FR)
- ๐ฉ๐ช German (DE)
- ๐ฎ๐น Italian (IT)
- ๐ฐ๐ฟ Kazakh (KZ)
- ๐ฑ๐ป Latvian (LV)
- ๐ฑ๐น Lithuanian (LT)
- ๐ต๐น Portuguese (PT)
- ๐ต๐ฑ Polish (PL)
- ๐ท๐บ Russian (RU)
- ๐ช๐ธ Spanish (ES)
- ๐ธ๐ช Swedish (SE)
- ๐บ๐ฆ Ukrainian (UA)
Getting started #
Add flutter_censor_it to your pubspec.yaml:
dependencies:
flutter_censor_it: ^2.0.0
Or using the command:
flutter pub add flutter_censor_it
Import the package in your Dart file:
import 'package:flutter_censor_it/flutter_censor_it.dart';
Usage #
Basic Example #
import 'package:flutter/material.dart';
import 'package:flutter_censor_it/flutter_censor_it.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,
),
),
),
),
);
}
}
Factory Constructors (v2.0.0+) #
CensorItWidget v2.0.0 introduces three factory constructors for different censoring strategies:
1. CensorItWidget.textBuilder() - Text Replacement #
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.
2. CensorItWidget.widgetBuilder() - Widget Replacement #
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.
3. CensorItWidget.overlayBuilder() - Visual Effects #
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.
Advanced Usage #
Dynamic Text Replacement #
CensorItWidget.textBuilder(
'Fuck this shit!',
builder: (context, word) {
// Different replacements based on word length
if (word.length > 4) return '[CENSORED]';
return '***';
},
pattern: LanguagePattern.english,
)
Custom Widget Censoring #
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,
)
Blur Effect with Overlay #
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.
Animated Reveal #
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.
Language Patterns #
Using Predefined Patterns #
// Single language
CensorItWidget.textBuilder(
'Fuck this!',
builder: (context, word) => '***',
pattern: LanguagePattern.english,
)
// All languages
CensorItWidget.textBuilder(
'Fuck this ะฑะปััั!',
builder: (context, word) => '***',
pattern: LanguagePattern.all,
)
Combining Multiple Languages #
// Combine specific languages
CensorItWidget.textBuilder(
'Fuck this puta!',
builder: (context, word) => '***',
pattern: CensorPattern.multi([
LanguagePattern.english,
LanguagePattern.spanish,
]),
)
Locale-Based Pattern Selection #
// 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,
)
Custom Patterns with RegExp #
// 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,
)
Features #
- 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
What's New in v2.0.0 #
Factory Constructors #
- โ
CensorItWidget.textBuilder()- Replace with custom text - โ
CensorItWidget.widgetBuilder()- Replace with widgets - โ
CensorItWidget.overlayBuilder()- Apply visual effects
New Parameters #
- โ
censoredStyle- Custom styling for censored text - โ
onTap- Interactive tap-to-reveal in overlay builder - โ
alignment- Widget vertical alignment control - โ
baseline- Baseline alignment for widgets
Breaking Changes #
- โ Removed direct constructor - Use factory constructors
- โ Removed
charsparameter - Implement in builder function - โ Renamed
CensorPatterntoLanguagePattern
See MIGRATION.md for upgrade instructions.
Changelog #
The list of changes is available in the file CHANGELOG.md
Contributions #
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.
License #
MIT License - see LICENSE file for details