Utility Library
A comprehensive set of Dart extensions and utilities to enhance your Flutter applications with additional functionality like advanced number, date, and string manipulations.
Features
- Color utilities
- Extended number formatting and validation
- Date and time formatting and computations
- String transformations and checks
- Unique and JSON transformation functionalities for collections
Installation
To use the utility library in your project, add it to your dependencies in your pubspec.yaml file:
dependencies:
utility_library: ^1.0.0
Then run:
flutter pub get
Usage
Import the library
Add the following import to your Dart file:
import 'package:utility_library/utility_library.dart';
Color Utilities
Set your app's primary and secondary colors:
AppColors.primaryColor = Color(0xff02a4ff); // Your app primary color
AppColors.secondaryColor = Color(0xffffffff); // Your app secondary color
Number Extensions
Formatting and checking numbers:
double myNumber = 123.456;
print(myNumber.reFormat(formatDigits: '000', asFixedNumber: 3)); // Using the extension method
DateTime Extensions
Work with DateTime formatting easily:
DateTime now = DateTime.now();
print('Standard DateTime: ${now.format(pattern: PredefinedDateFormats.standardDateTime.pattern)}');
print('Date Only: ${now.format(pattern: PredefinedDateFormats.dateOnly.pattern)}');
print('Time Only: ${now.format(pattern: PredefinedDateFormats.timeOnly.pattern)}');
print('Custom DateTime: ${now.format(pattern: PredefinedDateFormats.customDateTime.pattern)}');
print('Verbose DateTime with Day of Week: ${now.format(pattern: PredefinedDateFormats.verboseDateTimeWithDayOfWeek.pattern)}');
print('Year and Full Month: ${now.format(pattern: PredefinedDateFormats.yearAndFullMonth.pattern)}');
More Utilities
- Checking leap year, day computations, weekend checks for dates.
- Validating and formatting for doubles and integers.
- String manipulations such as title casing, palindrome checks, and base64 conversions.
- Unique and JSON transformations for lists.
Example
Here's how you might use some of these utilities in a Flutter app:
// Example usage of the library
void main() {
// Initialize and use colors
AppColors.primaryColor = Color(0xff02a4ff);
AppColors.secondaryColor = Color(0xffffffff);
// Work with extensions
DateTime today = DateTime.now();
print('Today is ${today.isLeapYear ? "a" : "not a"} leap year.');
}
Contributing
Contributions are welcome! Feel free to submit pull requests or create issues for bugs and feature requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
words unique? ${words.isUnique}'); print('JSON String of words: ${words.toJsonString()}'); print('Transformed numbers: ${numbers.transform((n) => 'Number $n').toString()}');
## Contributing
Contributions are welcome! Feel free to submit pull requests or create issues for bugs and feature requests.
## License
This project is licensed under the MIT License - see the LICENSE file for details.