function_linter 1.1.0 copy "function_linter: ^1.1.0" to clipboard
function_linter: ^1.1.0 copied to clipboard

A specialized tool for Flutter devs, discouraging inline functions to promote clean code. Enhance readability and reusability.

example/README.md

Function Linter Example πŸ“š #

This example shows you how to use Function Linter in a real project!

πŸš€ Try It Yourself #

  1. Install dependencies:

    dart pub get
    
  2. Create a Dart file (like lib/main.dart) with some messy inline functions:

    import 'package:flutter/material.dart';
    
    class MyWidget extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return ElevatedButton(
          onPressed: () {
            // This will get flagged! 🚨
            print('Button pressed');
            showDialog(
              context: context,
              builder: (context) => AlertDialog(title: Text('Hello!')),
            );
          },
          child: Text('Press me'),
        );
      }
    }
    
  3. Run analysis:

    dart analyze
    
  4. See the magic! You'll get a helpful warning suggesting to extract the function.

✨ What You'll See #

The linter will show warnings like:

Warning: Prefer extracting the callback to a separate widget method.

πŸ”§ Fix It Like This #

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: _handleButtonPress,  // Much cleaner! ✨
      child: Text('Press me'),
    );
  }

  void _handleButtonPress() {
    print('Button pressed');
    showDialog(
      context: context,
      builder: (context) => AlertDialog(title: Text('Hello!')),
    );
  }
}

🎯 Pro Tips #

  • The linter only flags complex inline functions (with multiple statements)
  • One-liners like () => print('hello') are totally fine
  • Builder functions like ListView.builder() are automatically ignored

Happy coding! πŸŽ‰

7
likes
140
points
70
downloads

Publisher

verified publisherwebmobtech.com

Weekly Downloads

A specialized tool for Flutter devs, discouraging inline functions to promote clean code. Enhance readability and reusability.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, analyzer_plugin, custom_lint_builder, custom_lint_core

More

Packages that depend on function_linter