string_to_hex 0.1.1+2

  • Readme
  • Changelog
  • Example
  • Installing
  • new69

string_to_hex pub package #

A powerful conversion of [String] or/and Hash to HEX. It returns a unique HEX, or a unique int of [Color()] per provided String/hash. It's provided two methods [toHexString] and [toColor], which return a Hex-String, or integer of Color() respectively.

Default: #

This package return hex-string or hex-int-color, check bellow:


Return a [int] of 'bit hex': Its return is proper to use as hex [color int] in a Color() For example: ... color: Color(StringToHex().toColor('a nice String')) ... then it'll generate and fill a hex-color int in it.

return a hex-color.
i.e: 0xFF353535
or: 8787451701

how to:

you can use as:

  var myNiceColor = StringToHex().toColor('your nice string');
    color: Color(myNiceColor);


color: Color(StringToHex().toColor('your nice string'));


Return a [String] of 'bit hex': Its return is proper to your custom manipulating (as you lik better 🧑‍💻).

Returns a String HEX with prefix '0xFF'
i.e: '0xFF343434'

Example: #

This example app shows all implementations

App shot
App Shots

Have a Nice Code!

[0.0.1] - 2020-06-25. #

  • Initial release.

[0.1.0] - 2020-06-27. #

  • Release upgrade.

[0.1.1] - 2020-06-27. #

  • Update docs.

[0.1.1+1] - 2020-06-27. #

  • fix image docs.

[0.1.1+2] - 2020-06-27. #

  • fix image docs.


import 'dart:math';

import 'package:flutter/material.dart';
import 'package:string_to_hex/string_to_hex.dart';

void main() {

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        visualDensity: VisualDensity.adaptivePlatformDensity,
      home: MyHomePage(title: 'Flutter Demo Home Page'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 5;
  String _string = 'your nice string';
  String hexColor = 'The Hex String comes here';
  Color generatedColor;
  int generatedColorInt;

  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      body: Center(
        child: Column(
          children: <Widget>[
              child: Text('press to generate Color & HexString'),
              color: Color(generatedColorInt ?? 0xfff5f535),
              onPressed: () {
                setState(() {
                  hexColor = getRandomString(_counter);
                  _string = StringToHex().toHexString(_string);
                  generatedColor = Color(StringToHex().toColor(_string));
                  generatedColorInt = StringToHex().toColor(_string);
              style: Theme.of(context).textTheme.headline4,
              style: Theme.of(context).textTheme.headline4,

const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _rnd = Random();

String getRandomString(int length) {
  return String.fromCharCodes(Iterable.generate(
      length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  string_to_hex: ^0.1.1+2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:string_to_hex/string_to_hex.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 6, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
pedantic ^1.9.0
test ^1.0.0