Best Practices 🎯

Code Organization

Category-based Import Strategy

// ❌ Bad - Importing everything
import 'package:normie/normie.dart';

// βœ… Good - Clear intention of usage
class ColorService {
  final _palette = Normie.palette;
  final _numeric = Normie.numeric;
  
  Color getContrastingColor(String hex) {
    final color = _palette.hexToColor(hex);
    return _palette.isLight(color) 
      ? Colors.black 
      : Colors.white;
  }
}

Error Handling

Cache Management

Common Patterns πŸ”„

Builder Pattern with Normie

Validation Chain

Format Utilities

Performance Tips πŸš€

Cache Expensive Operations

Batch Operations

Memory Management

Lazy Initialization

Best Practices by Category

Cache Best Practices

  • Set appropriate expiry times

  • Regularly clean expired items

  • Use type-safe getters

  • Handle cache misses gracefully

Validation Best Practices

  • Combine multiple validations

  • Provide clear error messages

  • Use appropriate regex patterns

  • Handle edge cases

Date/Time Best Practices

  • Use consistent formats

  • Handle timezone differences

  • Consider locale settings

  • Validate date strings

Collection Best Practices

  • Use appropriate page sizes

  • Handle empty results

  • Consider memory implications

  • Use efficient algorithms

File Best Practices

  • Validate file types

  • Handle large files appropriately

  • Use proper MIME types

  • Consider security implications

Remember: These are guidelines, not strict rules. Adapt them to your specific needs!

Last updated