unused_code_cleaner 1.9.1 copy "unused_code_cleaner: ^1.9.1" to clipboard
unused_code_cleaner: ^1.9.1 copied to clipboard

Automatically find and safely remove unused assets, functions, packages, and files from Flutter/Dart projects. Reduce bundle size and improve performance with one command.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Unused Code Cleaner Example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset('assets/used.png'),
            ElevatedButton(
              onPressed: () async {
                final cleaner = UnusedCodeCleaner();
                final options = CleanupOptions(
                  removeUnusedAssets: true,
                  removeUnusedFiles: true,
                  verbose: true,
                  interactive: false,
                  excludePatterns: ['**/*.g.dart'],
                );
                final result = await cleaner.analyze('.', options);
                if (context.mounted) {
                  ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(
                      content:
                          Text('Found ${result.totalUnusedItems} unused items'),
                    ),
                  );
                }
              },
              child: const Text('Run Cleaner'),
            ),
          ],
        ),
      ),
    );
  }
}

void usedFunction() {
  print('This function is used');
}

void unusedFunction() {
  print('This function is not used');
}
6
likes
145
points
123
downloads

Publisher

unverified uploader

Weekly Downloads

Automatically find and safely remove unused assets, functions, packages, and files from Flutter/Dart projects. Reduce bundle size and improve performance with one command.

Repository (GitHub)
View/report issues

Topics

#flutter #optimization #cleanup #assets #performance

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, args, cli_util, colorize, glob, path, yaml

More

Packages that depend on unused_code_cleaner