derived_colors 0.2.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

derived_colors #

logo

Generate color variants.

Usage #

import 'package:derived_colors/derived_colors.dart';

final color = Color(0xFFFF0000);
final light = color.variants.light;
final dark = color.variants.dark;
final invert = color.variants.invert;

final hoverColor = color.subtle();

Thanks #

  • Bulma : inspired by Bulma's calculations.

[0.2.4] - 2020/03/24 #

  • Fixing black and white saturation issue with updated lightness.

[0.2.3] - 2020/03/24 #

  • Fixing black and white saturation issue with updated lightness.

[0.2.2] - 2020/03/24 #

  • Updated [ColorExtensions.findDark] calculation.

[0.2.1] - 2020/03/24 #

  • Fixed issue with hot reloading.

[0.2.0] - 2020/03/24 #

  • Renamed [ColorExtensions.decline] to [ColorExtensions.subtle].

[0.1.4] - 2020/03/24 #

  • Better performance on [ColorExtensions.decline].

[0.1.2] - 2020/03/24 #

  • Added a default amount value on [ColorExtensions.darken] and [ColorExtensions.lighten].

[0.1.1] - 2020/03/24 #

  • Fixed darkenLimit not taken into account in [ColorExtensions.decline].

[0.1.0] - 2020/03/24 #

  • Added illustration

[0.0.1] - 2020/03/24 #

  • Initial release

example/lib/main.dart

import 'package:derived_colors/derived_colors.dart';
import 'package:example/swatches.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Auto Colors Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: ExamplePage(),
    );
  }
}

class ExamplePage extends StatefulWidget {
  @override
  _ExamplePageState createState() => _ExamplePageState();
}

class _ExamplePageState extends State<ExamplePage> {
  Swatch swatch = bulma;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SingleChildScrollView(
        child: SafeArea(
          child: Column(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Palette(swatch.primary),
                    Palette(swatch.link),
                    Palette(swatch.info),
                    Palette(swatch.danger),
                    Palette(swatch.warning),
                    Palette(swatch.grey),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Wrap(
                  spacing: 8.0,
                  runSpacing: 8.0,
                  children: <Widget>[
                    Button.regular(color: swatch.primary, text: 'Example'),
                    Button.regular(color: swatch.link, text: 'Example'),
                    Button.regular(color: swatch.info, text: 'Example'),
                    Button.regular(color: swatch.danger, text: 'Example'),
                    Button.regular(color: swatch.warning, text: 'Example'),
                    Button.regular(color: swatch.success, text: 'Example'),
                  ],
                ),
              ),
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Wrap(
                  spacing: 8.0,
                  runSpacing: 8.0,
                  children: <Widget>[
                    Button.light(color: swatch.primary, text: 'Example'),
                    Button.light(color: swatch.link, text: 'Example'),
                    Button.light(color: swatch.info, text: 'Example'),
                    Button.light(color: swatch.danger, text: 'Example'),
                    Button.light(color: swatch.warning, text: 'Example'),
                    Button.light(color: swatch.success, text: 'Example'),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

class Palette extends StatelessWidget {
  final Color color;

  Palette(this.color);

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Container(
          width: 24,
          height: 24,
          color: color.variants.dark,
        ),
        Container(
          width: 24,
          height: 24,
          color: color.variants.regular.darken(0.05),
        ),
        Container(
          width: 24,
          height: 24,
          color: color.variants.regular,
        ),
        Container(
          width: 24,
          height: 24,
          color: color.variants.regular.lighten(0.05),
        ),
        Container(
          width: 24,
          height: 24,
          color: color.variants.light,
        ),
        Container(
          width: 24,
          height: 24,
          color: color.variants.regular,
          child: Center(
            child: Container(
              width: 8,
              height: 8,
              color: color.variants.invert,
            ),
          ),
        ),
      ],
    );
  }
}

class Button extends StatefulWidget {
  final Color backgroundColor;
  final Color foregroundColor;
  final String text;

  const Button({
    @required this.backgroundColor,
    @required this.foregroundColor,
    @required this.text,
  });

  factory Button.light({
    @required String text,
    @required Color color,
  }) =>
      Button(
        backgroundColor: color.variants.light,
        foregroundColor: color.variants.dark,
        text: text,
      );

  factory Button.regular({
    @required String text,
    @required Color color,
  }) =>
      Button(
        backgroundColor: color.variants.regular,
        foregroundColor: color.variants.invert,
        text: text,
      );

  @override
  _LightButtonState createState() => _LightButtonState();
}

class _LightButtonState extends State<Button> {
  bool isActive = false;
  bool isHover = false;

  @override
  Widget build(BuildContext context) {
    return MouseRegion(
      onEnter: (_) => this.setState(() => this.isHover = true),
      onExit: (_) => this.setState(() => this.isHover = false),
      child: Listener(
        onPointerDown: (_) => this.setState(() => this.isActive = true),
        onPointerUp: (_) => this.setState(() => this.isActive = false),
        onPointerCancel: (_) => this.setState(() => this.isActive = false),
        child: AnimatedContainer(
          duration: const Duration(milliseconds: 200),
          decoration: BoxDecoration(
            color: widget.backgroundColor.subtle(
              isActive ? 0.06 : (isHover ? 0.03 : 0.0),
            ),
            borderRadius: BorderRadius.circular(4.0),
          ),
          padding: const EdgeInsets.all(8.0),
          child: Text(
            widget.text,
            style: TextStyle(
              color: widget.foregroundColor,
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  derived_colors: ^0.2.4

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:derived_colors/derived_colors.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
70
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • derived_colors that is a package requiring null.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

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