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:

toColor()

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);
    ...

or:

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

toHexString()

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.

example/lib/main.dart

import 'dart:math';

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        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;

  @override
  _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;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            MaterialButton(
              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);
                });
              },
            ),
            Text(
              '$_string',
              style: Theme.of(context).textTheme.headline4,
            ),
            Text(
              '$hexColor',
              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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
37
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
69
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

Dependencies

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