dart_conversion_utils 1.0.0
dart_conversion_utils: ^1.0.0 copied to clipboard
Utility functions for color, date, number, and screen conversions.
dart_conversion_utils #
A lightweight Dart/Flutter package providing utility functions for conversions. It helps developers easily handle colors, dates, numbers, strings, and screen size conversions, making mobile app design faster and more consistent.
Features #
- Color conversions:
hexToColor,colorToHex - Date conversions:
formatDate,timestampToDate,dateToTimestamp - Number & string utilities:
formatNumber,formatCurrency,capitalize - Screen size conversions:
dpToPx,percentWidth,percentHeight
Installation #
Add this to your pubspec.yaml:
dependencies:
dart_conversion_utils:
git:
url: https://github.com/YOUR_USERNAME/dart_conversion_utils.git
Then fetch dependencies:
dart pub get
Or for Flutter:
flutter pub get
Usage #
Import the package #
import 'package:dart_conversion_utils/dart_conversion_utils.dart';
Color Utilities #
hexToColor
Color myColor = hexToColor("#5CBF6D"); // Color(0xFF5CBF6D)
- Converts a hex string to a
Colorobject. - Adds full opacity if alpha is missing.
colorToHex
String hex = colorToHex(Colors.blue); // "#0000FF"
String hexWithAlpha = colorToHex(Colors.blue, includeAlpha: true); // "#FF0000FF"
- Converts a
Colorobject to a hex string. - Optional: include alpha channel.
Date Utilities #
formatDate
String date = formatDate(DateTime.now()); // "2025-10-09"
String customDate = formatDate(DateTime.now(), separator: '/'); // "2025/10/09"
timestampToDate
DateTime date = timestampToDate(1739020000000);
dateToTimestamp
int timestamp = dateToTimestamp(DateTime.now());
Number & String Utilities #
formatNumber
String formatted = formatNumber(1234567); // "1,234,567"
formatCurrency
String price = formatCurrency(19.99, symbol: '\$'); // "$19.99"
capitalize
String name = capitalize("flutter"); // "Flutter"
Screen Size Utilities #
dpToPx
double buttonWidth = dpToPx(context, 120, baseWidth: 375);
- Converts design pixels to logical pixels relative to current screen width.
baseWidthdefaults to 375 (common iPhone design width).
percentWidth
double boxWidth = percentWidth(context, 50); // 50% of screen width
percentHeight
double boxHeight = percentHeight(context, 30); // 30% of screen height
Running Tests #
dart test
Or for Flutter tests:
flutter test
Ensure all conversion methods work correctly across different screen sizes and values.
License #
MIT © [Arno Massart]