CommonKit

A lightweight, reusable utility package for Flutter apps, providing a collection of widgets, helpers, and extensions to simplify common development tasks. Designed for both mobile/desktop and web (WASM) platforms with robust compatibility and accessibility features.

Pub Version License

Features

Widgets

  • LoadingOverlay: Display a customizable loading spinner with theme support (e.g., color, opacity).
  • CustomSnackbar: Show styled snackbars with icons, colors, and duration options.
  • CustomButton: Create reusable buttons with text, icons, themes, and disabled states.
  • Toast: Present short-lived notifications using ScaffoldMessenger for web compatibility.
  • CustomDialog: Offer customizable dialogs with themed buttons and layouts.
  • AdvancedImagePicker: Pick and preview images (non-web only; web stub ensures WASM compatibility).

Extensions

  • StringExtensions: Add capitalize() (e.g., "hello" → "Hello") and truncate() (e.g., shorten with "...") to strings.
  • ContextExtensions: Access screenWidth, screenHeight, theme data, and more.

Helpers

  • Validators: Validate form fields (e.g., email, required, password strength).
  • DateFormatter: Format dates (e.g., "MM/dd/yyyy") and get "time ago" strings (e.g., "2 hours ago").
  • NetworkHelper: Simplify HTTP GET/POST with file uploads and error handling.
  • ImageCacheHelper: Preload single or batch images, manage cache policies, monitor cache size, and clear caches (disk caching non-web only via flutter_cache_manager).
  • Debouncer: Delay function calls for input debouncing (e.g., search fields).
  • StorageHelper: Store key-value pairs persistently (non-web only; WASM-safe).
  • AnimationHelper: Create fade, slide, and scale animations with customizable durations.
  • ResponsiveHelper: Build responsive layouts with mobile, tablet, and desktop breakpoints.
  • SessionManager: Manage login/logout with global state and persistence.
  • DirectoryManager: Handle file system operations (create, update, delete, list; non-web only; WASM-safe).
  • Logger: Log messages with info, warning, and error levels (web uses debugPrint).
  • ClipboardManager: Copy/paste text to/from the clipboard (web-compatible via dart:html).
  • DataSerializer: Serialize/deserialize JSON data with error handling.
  • PermissionManager: Request and check permissions (e.g., storage, camera; non-web only; WASM-safe).

Configuration

  • CommonKitTheme: Define app-wide colors, typography, border radius, elevation, and accessibility options (e.g., high-contrast mode, dark mode).
  • GlobalConfig: Manage global settings like base URL, API timeout, locale, environment, custom headers, analytics, and user session (with persistence for username, session token, etc.).

WASM Compatibility

  • Fully compatible with WebAssembly (WASM) runtimes.
  • Non-web features (e.g., DirectoryManager, StorageHelper, PermissionManager, AdvancedImagePicker) are disabled on web with clear feedback (e.g., toasts like "Feature unavailable on web").
  • Conditional imports ensure no dart:io usage on web, maintaining compatibility.

Installation

Add commonkit to your pubspec.yaml:

dependencies:
  commonkit: ^0.1.4