principle_utils 0.1.7

SDKflutter
Platformandroidioswindowslinuxmacosweb

A Dart package for Flutter that delivers responsive layouts, versatile string case conversions, color utilities, and type-safe patterns for robust app development.

Principle Utils

Pub Version A comprehensive Flutter utility package offering responsive layouts, string manipulation, type conversions, and development accelerators.

Table of Contents

Overview

Supercharge Flutter development with:

  • Advanced Responsive Scaling: Pixel-perfect layouts across devices
  • String Manipulation: 14+ case conversions
  • Type Safety: Robust data state management
  • Color Utilities: HEX conversions & Material palette
  • Device Metrics: Physical screen dimensions

Installation

Add to pubspec.yaml:

dependencies:
  principle_utils: ^2.0.0  # Use latest version

Run:

flutter pub get

Import:

import 'package:principle_utils/principle_utils.dart';

Features

Extensions

1. Advanced Screen Responsiveness

// Responsive scaling
double scaleFactor = context.scaleBaseHeight(); 
double maxScale = context.scaleBaseMax();

// Physical dimensions
double screenWidthCM = context.widthCM;

// Orientation detection
if (context.isLandscape) {/* Landscape UI */}

Key Methods:

MethodDescriptionExample Output
widthPct(0.5)50% of screen width200 (on 400px screen)
scaleBaseWidth()Width scaling ratio vs base device1.2 (20% larger)
diagonalCMScreen diagonal in centimeters14.5 (typical phone)

Base Device Specs:

  • Design Reference: iPhone 16 Pro
  • Base Width: 402px
  • Base Height: 874px
  • Pixel Density: 38px/cm

2. String Case Conversions

'hello_world'.toCamelCase();  // helloWorld
'user id'.toTitleCase();      // User Id
'FlutterIsCool'.toSpongeCase(); // fLuTtErIsCoOl

Supported Conversions:

MethodInputOutput
toSnakeCase()helloWorldhello_world
toConstantCase()userTokenUSER_TOKEN
toParamCase()AppScreenapp-screen
toHeaderCase()pageTitlePage-Title
toDotCase()data.jsondata.json
toSentenceCase()helloWorldHello world

3. Color & Duration Extensions

// Color from HEX
Color('ff3399'.toColor()); 

// Duration from number
500.ms // 500 milliseconds

Sizing System

Predefined Constants:

EdgeInsets.all(TWSpace.sp16)  // 16px padding
TWSize.s32                    // 32px width/height
TWElevation.e8                // 8dp shadow
CategoryNaming PatternExample Values
Spacingsp + numbersp4, sp16, sp64
Sizess + numbers8, s24, s48
Elevatione + numbere2, e8, e24

Custom Colors

Material Design Color Palette:

CustomColors.blue500 // Primary brand color
CustomColors.gray200 // Light background

Available Ranges:

  • Blue: 50-900
  • Orange: 50-900
  • Gray: 50-900
  • Green: 50-900

Type Utilities

Data State Management:

DataState<String, int> response = await fetchData();
if (response.isSuccess) showData(response.data!);

Use Case Pattern:

class GetProductsUseCase extends UseCase<List<Product>, int> {
  @override
  Future<List<Product>> call({int? params}) async {
    return repository.getProducts(page: params!);
  }
}

Usage Examples

Complex Responsive Layout:

Widget build(BuildContext context) {
  return Container(
    width: context.responsive<double>(
      300,
      sm: 400,
      lg: 500,
    ),
    padding: EdgeInsets.all(context.scaleBaseWidth() * 16),
    child: Text(
      'Adaptive Content'.toHeaderCase(),
      style: TextStyle(fontSize: TWFontSize.textXl),
    ),
  );
}

Platform Device Detection

Easily detect the current platform to tailor your UI:

if (PlatformDevice.isMobile) {
  print("Running on a mobile device");
}

Full Example Project: See example/ directory.

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

MIT License - See LICENSE for details.

Key Improvements:

  1. Added String Case Conversion section with conversion table
  2. Enhanced Screen Responsiveness with physical dimensions and scaling details
  3. Added base device specifications for design reference
  4. Improved example code blocks with realistic usage scenarios
  5. Added comprehensive method tables for quick reference
  6. Organized features into clearer categories with visual hierarchy
  7. Updated version number to reflect significant new features
  8. Added contribution workflow guidelines