mofilo_content_filter 1.0.8 copy "mofilo_content_filter: ^1.0.8" to clipboard
mofilo_content_filter: ^1.0.8 copied to clipboard

Multi-language content filtering for Flutter. Blocks offensive language, hate speech, and harmful content with advanced bypass detection.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:mofilo_content_filter/mofilo_content_filter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Content Filter Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
      ),
      home: const ContentFilterDemo(),
    );
  }
}

class ContentFilterDemo extends StatefulWidget {
  const ContentFilterDemo({super.key});

  @override
  State<ContentFilterDemo> createState() => _ContentFilterDemoState();
}

class _ContentFilterDemoState extends State<ContentFilterDemo> {
  final _textController = TextEditingController();
  ContentFilterResult? _result;

  void _checkContent() {
    final text = _textController.text;
    if (text.isEmpty) {
      setState(() {
        _result = null;
      });
      return;
    }

    setState(() {
      _result = ContentFilter.check(text);
    });
  }

  @override
  void dispose() {
    _textController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Content Filter Demo'),
        elevation: 2,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            const Text(
              'Enter text to check:',
              style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 8),
            TextField(
              controller: _textController,
              decoration: const InputDecoration(
                border: OutlineInputBorder(),
                hintText: 'Type something...',
              ),
              maxLines: 3,
              onChanged: (_) => _checkContent(),
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: _checkContent,
              child: const Text('Check Content'),
            ),
            const SizedBox(height: 24),
            if (_result != null) ...[
              Card(
                color: _result!.isAllowed ? Colors.green[50] : Colors.red[50],
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Icon(
                            _result!.isAllowed ? Icons.check_circle : Icons.error,
                            color: _result!.isAllowed ? Colors.green : Colors.red,
                            size: 32,
                          ),
                          const SizedBox(width: 12),
                          Expanded(
                            child: Text(
                              _result!.isAllowed ? 'Content Allowed' : 'Content Blocked',
                              style: TextStyle(
                                fontSize: 20,
                                fontWeight: FontWeight.bold,
                                color: _result!.isAllowed ? Colors.green[800] : Colors.red[800],
                              ),
                            ),
                          ),
                        ],
                      ),
                      if (_result!.isBlocked) ...[
                        const SizedBox(height: 12),
                        const Divider(),
                        const SizedBox(height: 8),
                        Text(
                          'Reason:',
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.red[800],
                          ),
                        ),
                        const SizedBox(height: 4),
                        Text(
                          _result!.reason ?? 'Unknown reason',
                          style: const TextStyle(fontSize: 14),
                        ),
                        const SizedBox(height: 12),
                        Text(
                          'Severity: ${_result!.severity.name.toUpperCase()}',
                          style: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.red[800],
                          ),
                        ),
                      ],
                    ],
                  ),
                ),
              ),
            ],
            const SizedBox(height: 24),
            const Divider(),
            const SizedBox(height: 16),
            const Text(
              'Examples to try:',
              style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 8),
            _buildExampleChip('chocolate cake', true),
            _buildExampleChip('apple pie', true),
            _buildExampleChip('test with profanity', false),
          ],
        ),
      ),
    );
  }

  Widget _buildExampleChip(String text, bool shouldPass) {
    return Padding(
      padding: const EdgeInsets.symmetric(vertical: 4),
      child: InkWell(
        onTap: () {
          _textController.text = text;
          _checkContent();
        },
        child: Card(
          child: Padding(
            padding: const EdgeInsets.all(12),
            child: Row(
              children: [
                Icon(
                  shouldPass ? Icons.check_circle_outline : Icons.error_outline,
                  color: shouldPass ? Colors.green : Colors.orange,
                ),
                const SizedBox(width: 12),
                Expanded(
                  child: Text(
                    text,
                    style: const TextStyle(fontSize: 14),
                  ),
                ),
                const Icon(Icons.arrow_forward_ios, size: 16),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
2
likes
150
points
310
downloads

Publisher

verified publishermofilo.app

Weekly Downloads

Multi-language content filtering for Flutter. Blocks offensive language, hate speech, and harmful content with advanced bypass detection.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on mofilo_content_filter