app_color_parser 0.0.4
app_color_parser: ^0.0.4 copied to clipboard
A lightweight Flutter package for converting between Color, hex strings, and ARGB integers, with built-in JSON serialization support.
app_color_parser #
app_color_parser
is a simple and lightweight Dart package for Flutter that provides utilities to convert between Color
and hex string or integer formats, and also includes tools for easy JSON serialization and deserialization of color values.
Features #
- Convert
Color
objects to and from hex strings (e.g.,#RRGGBB
,0xAARRGGBB
). - Convert
Color
objects to and fromint
values (ARGB). - JSON serialization helpers for both hex and int formats.
Getting Started #
Add the dependency to your pubspec.yaml
:
dependencies:
app_color_parser: ^0.0.4
Usage #
Convert Color
to Hex String #
final color = Colors.blue;
final hex = color.toHex(); // e.g., '0xFF2196F3'
Convert Hex String to Color
#
final color = HexColorExtension.fromHex('0xFF2196F3');
Use JSON Helpers #
ARGB Int Helper
final helper = ColorJsonHelper();
final jsonValue = helper.toJson(Colors.red); // e.g., 0xFFFF0000
final color = helper.fromJson(jsonValue);
Hex String Helper
final helper = HexColorJsonHelper();
final jsonValue = helper.toJson(Colors.green); // e.g., '0xFF4CAF50'
final color = helper.fromJson(jsonValue);
API Reference #
HexColorExtension
#
toHex({bool includeAlpha = false})
: Converts aColor
to a hex string.fromHex(String hexString)
: Converts a hex string to aColor
.
ColorJsonHelper
#
toJson(Color? color)
: Converts aColor
to anint
.fromJson(int? json)
: Converts anint
to aColor
.
HexColorJsonHelper
#
toJson(Color? color)
: Converts aColor
to a hex string.fromJson(String? json)
: Converts a hex string to aColor
.
License #
MIT License. See LICENSE file for details.
Contributions #
Contributions are welcome! Please open an issue or submit a pull request.