colors_parser 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

A Material Colors parsing library.

The colors_parser package provides string parsing operations for MaterialColor and MaterialAccentColor values with an optional indexed shade as well as black and white variants and even hex values.

Installing #

Use pub to install this package. Add the following to your pubspec.yaml file.

dependencies:
  colors_parser: any

Then run pub install.

For more information, see the colors_parser package on pub.dev.

Using #

The colors_parser package was designed to be imported with a prefix, though you don't have to if you don't want to:

import 'package:colors_parser/colors_parser.dart' as cp;

The most common way to use the library is through the top-level functions. These parse Material Colors based on English language names. For example:

cp.parse('blue');

This calls the top-level parse() function to parse "blue" using English language names.

If you want to work with colors for a different language, you can create a ColorsParser and give it an explicit colors map:

var cpES = new cp.ColorsParser(colorsMap: ["azul", Colors.blue]);
cpES.parse('azul');

This will parse "azul" using the supplied Spanish language colors map.

1.0.2 #

  • Bump version for CHANGELOG.

1.0.0 #

  • Initial release.

example/lib/main.dart

// Copyright (c) 2020, Charles Esrock. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.

import 'package:flutter/material.dart';

import 'package:colors_parser/colors_parser.dart' as cp;

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

class App extends StatelessWidget {
  final colors = <String>[];

  App() {
    for (var color in Colors.primaries) colors.add(cp.toColorsString(color));
    for (var color in Colors.accents) colors.add(cp.toColorsString(color));
    for (var index in [50, 100, 200, 300, 400, 500, 600, 700, 800, 900])
      colors.add(cp.toColorsString(Colors.blue[index]));
    for (var index in [100, 200, 400, 700])
      colors.add(cp.toColorsString(Colors.blueAccent[index]));
    for (var color in ['grey', 'black', 'white']) colors.add(color);
    for (var color in [12, 26, 38, 45, 54, 87]) colors.add('black$color');
    for (var color in [10, 12, 30, 38, 54, 60, 70]) colors.add('white$color');
  }

  Widget build(BuildContext context) {
    var black = cp.parse('black');
    var grey500 = cp.parse('grey[500]');
    var white54 = cp.parse('white54');
    var black54 = cp.parse('black54');
    return MaterialApp(
      home: Scaffold(
          body: SafeArea(
              child: ListView.builder(
        itemCount: colors.length,
        itemBuilder: (BuildContext context, int index) {
          var color = cp.parse(colors[index]);
          var backColor = color.alpha == 0xFF ? color : grey500;
          var textColor =
              color.alpha != 0xFF ? color : color == black ? white54 : black54;
          return Container(
            height: 50,
            color: backColor,
            child: Center(
                child: Text(
                    '${colors[index]} #${cp.parse(colors[index]).value.toRadixString(16)}',
                    style: TextStyle(
                        fontSize: 20,
                        fontWeight: FontWeight.bold,
                        color: textColor))),
          );
        },
      ))),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  colors_parser: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support 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:colors_parser/colors_parser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test