flutter_censor_it 2.0.0 copy "flutter_censor_it: ^2.0.0" to clipboard
flutter_censor_it: ^2.0.0 copied to clipboard

A Flutter widget for censoring text with customizable profanity patterns.

Banner

Pub

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 style and censoredStyle for normal and censored text
  • Interactive: onTap callback for reveal/hide functionality in overlay builder
  • Widget Alignment: Control vertical alignment with PlaceholderAlignment and TextBaseline
  • Profanity Detection: Built on censor_it package 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 chars parameter - Implement in builder function
  • โŒ Renamed CensorPattern to LanguagePattern

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

2
likes
160
points
111
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter widget for censoring text with customizable profanity patterns.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

censor_it, flutter

More

Packages that depend on flutter_censor_it