function_linter 1.1.0
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.
Function Linter 🔍 #
Keep your Flutter code clean and organized!
Function Linter is a simple tool that helps you write better Flutter code by catching messy inline functions and suggesting cleaner alternatives. It's like having a code reviewer that never sleeps! 😴
🤔 What Problem Does This Solve? #
Have you ever written Flutter code that looks like this?
ElevatedButton(
onPressed: () {
// 20 lines of complex logic here...
if (something) {
doThis();
andThat();
maybeThis();
}
// More logic...
},
child: Text('Click me'),
)
This makes your code hard to read, test, and reuse. Function Linter catches these cases and suggests better approaches!
✨ What You Get #
- Cleaner code → Easier to read and understand
- Better testing → Extract functions to test them separately
- Code reuse → Share common functions across widgets
- Consistent style → Your whole team writes organized code
🚀 Quick Start #
Step 1: Install #
Add this to your pubspec.yaml:
dev_dependencies:
function_linter: ^1.1.0
Step 2: Configure #
Add this to your analysis_options.yaml:
analyzer:
plugins:
- custom_lint
Step 3: That's it! #
Run dart pub get and the linter will start helping you write better code automatically!
📝 Examples - Before & After #
❌ This Will Get Flagged #
Complex inline functions that make your widgets hard to read:
ElevatedButton(
onPressed: () {
// Multiple lines of complex logic - this gets flagged!
if (user.isLoggedIn) {
analytics.track('button_pressed');
Navigator.push(context, MaterialPageRoute(builder: (context) => ProfilePage()));
} else {
showLoginDialog();
}
},
child: Text('View Profile'),
)
✅ This Is Much Better #
Extract the function for cleaner, testable code:
ElevatedButton(
onPressed: _handleProfileButton, // Clean and simple!
child: Text('View Profile'),
)
void _handleProfileButton() {
if (user.isLoggedIn) {
analytics.track('button_pressed');
Navigator.push(context, MaterialPageRoute(builder: (context) => ProfilePage()));
} else {
showLoginDialog();
}
}
✅ These Are Fine (Won't Be Flagged) #
Simple one-liners:
ElevatedButton(
onPressed: () => Navigator.pop(context), // Short and sweet ✓
child: Text('Back'),
)
Flutter builder patterns:
ListView.builder(
itemBuilder: (context, index) { // This is a Flutter pattern ✓
return ListTile(title: Text('Item $index'));
},
)
Function references:
TextField(
onChanged: _handleTextChanged, // Already extracted ✓
)
🔧 How It Works #
Function Linter is smart about what it flags:
- Scans your widgets - Looks at all widget constructors
- Finds complex functions - Only flags functions with multiple statements
- Respects Flutter patterns - Ignores builder functions and one-liners
- Shows helpful warnings - Appears right in your IDE
🛠️ Works With Your Favorite Editor #
- ✅ Visual Studio Code
- ✅ Android Studio / IntelliJ IDEA
- ✅ Any editor with Dart support
You'll see warnings directly in your code with helpful suggestions!
🤫 Need to Skip a Warning? #
Sometimes you really need an inline function. No problem:
// ignore: prefer-extracting-callbacks
ElevatedButton(
onPressed: () {
// This won't trigger a warning
},
child: Text('Button'),
)
💡 Questions? #
- Found a bug? Open an issue
- Want to contribute? Pull requests are welcome!
- Need help? Check out our example project
📄 License #
MIT License - see LICENSE for details.
Made with ❤️ by WebMobTech Solutions