corextra
A lightweight Dart package offering handy extensions and utility functions
for common types like String, int, double, List, and more.
Make your Dart and Flutter code cleaner, safer, and easier to read.
Features
Core Extensions
- Extensions on core types for safer parsing and formatting
- Null-safe and concise checks like
.isNullOrEmptyonString?andList? - Convenient conversion helpers:
.toTryInt(),.toTryDouble(),.toTryBool() - String utilities like
.capitalize(),.toPascalCase(),.toCamelCase() - Numeric helpers to sanitize negative values
- Helper functions like
isStringEmpty()andisListEmpty()for legacy or functional use - DateTime extensions for:
- Parsing from string to
DateTime - Formatting
DateTimeto string with customizable formats
- Parsing from string to
safeSetState:- Safely updates widget state only if the widget is still mounted
- Prevents
setState()calls on disposed widgets, reducing runtime errors
Form Validators
- General-purpose form field validators for Flutter
TextFormField - Validators included:
required— ensures a field is not emptyemail— validates email formatphone— validates phone numbers with optional mask lengthotp— validates OTP with customizable lengthpassword— validates password with customizable minimum lengthconfirmPassword— ensures password confirmation matches original password
- Optional translation support via
easy_localization
Responsive Utilities
- ResponsiveBreakpoints: simple and customizable screen size helpers (
xs,sm,md,lg,xl) for responsive layouts in Flutter
Error Handling
- Custom Exception System for structured error handling:
CorextraException(base class)CorextraCustomExceptionfor generic app-level errorsCorextraNetworkExceptionfor network-related errors (e.g., Dio, HTTP requests)
- DioErrorHandler:
- Maps Dio errors to user-friendly messages
- Throws typed exceptions (
CorextraNetworkException)
Logging Utilities
- debugLog:
- Lightweight, debug-only logger for development builds
- Supports multiple log levels (info, warning, error)
- AppLogger:
- Structured logging for app events, Dio requests, responses, and errors
- Easy integration with existing network layers
- Optional support for global tokens or custom metadata
Animation Utilities
- FadeSlideTransition:
- A combined fade + slide transition widget
- Supports directions:
top,bottom,left,right, andcustom - Built with
AnimatedSwitcherfor smooth transitions
Getting Started
Add this package to your Dart or Flutter project by adding this line to your pubspec.yaml:
dependencies:
corextra: ^1.1.4
Then import it in your Dart code:
import 'package:corextra/corextra.dart';
Libraries
- animation/fade_slide_transition
- corextra
- exceptions/corextra_exceptions
- extensions/date_time_extensions/nullable_date_time_extensions
- extensions/double_extensions/double_extensions
- extensions/int_extensions/int_extensions
- extensions/list_extensions/list_extensions
- extensions/responsive_extensions/responsive_constraints_extensions
- extensions/responsive_extensions/responsive_context_extensions
- extensions/state_extensions/state_extensions
- extensions/string_extensions/non_nullable_string_extensions
- extensions/string_extensions/nullable_string_extensions
- functions/validators
- logs/app_logger
- logs/debug_log
- network/dio_error_handler
- responsive/responsive_breakpoints
- validators/form_validators