app_color_parser 0.0.4 copy "app_color_parser: ^0.0.4" to clipboard
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 from int 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 a Color to a hex string.
  • fromHex(String hexString): Converts a hex string to a Color.

ColorJsonHelper #

  • toJson(Color? color): Converts a Color to an int.
  • fromJson(int? json): Converts an int to a Color.

HexColorJsonHelper #

  • toJson(Color? color): Converts a Color to a hex string.
  • fromJson(String? json): Converts a hex string to a Color.

License #

MIT License. See LICENSE file for details.

Contributions #

Contributions are welcome! Please open an issue or submit a pull request.

0
likes
150
points
306
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight Flutter package for converting between Color, hex strings, and ARGB integers, with built-in JSON serialization support.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on app_color_parser