flutter_colorpicker 0.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 95

flutter_colorpicker

pub package

A HSV color picker inspired by chrome devtools and a material color picker for your flutter app.

Getting Started

Installation

Add this to your pubspec.yaml (or create it):

dependencies:
  flutter_colorpicker: any

Then run the flutter tooling:

flutter packages get

Or upgrade the packages with:

flutter packages upgrade

Example

Use it in [showDialog] widget:

// create some value
Color pickerColor = Color(0xff443a49);
Color currentColor = Color(0xff443a49);
ValueChanged<Color> onColorChanged;

// bind some values with [ValueChanged<Color>] callback
changeColor(Color color) {
  setState(() => pickerColor = color);
}

// raise the [showDialog] widget
showDialog(
  context: context,
  child: AlertDialog(
    title: const Text('Pick a color!'),
    content: SingleChildScrollView(
      child: ColorPicker(
        pickerColor: pickerColor,
        onColorChanged: changeColor,
        enableLabel: true,
        pickerAreaHeightPercent: 0.8,
      ),
      // Use Material color picker
      // child: MaterialPicker(
      //   pickerColor: pickerColor,
      //   onColorChanged: changeColor,
      //   enableLabel: true, // only on portrait mode
      // ),
    ),
    actions: <Widget>[
      FlatButton(
        child: Text('Got it'),
        onPressed: () {
          setState(() => currentColor = pickerColor);
          Navigator.of(context).pop();
        },
      ),
    ],
  ),
)

preview

01 02 03 04

Details in example/ folder.

I have created the ColorPicker widget so you can use the color picker out of the box. But you can create your own style with the CustomPaint.

CHANGELOG

[0.1.0]

  • Improve slider dragging.
  • A new material color picker.
  • Update example app.

[0.0.7]

  • Fix analysis warning.

[0.0.6]

  • Better landscape view.

[0.0.5]

  • Replace some deprecated functions.
  • Bump SDK version.

[0.0.4]

  • Replace a parameter from colorPainterHeight to pickerAreaHeightPercent to give a ratio on the picker area.

[0.0.3]

  • Optimization for responsive design.

[0.0.2]

  • Change widget's width.

[0.0.1+1]

  • Update readme.

[0.0.1]

  • Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:flutter_colorpicker/material_picker.dart';

main() => runApp(
      MaterialApp(
        title: 'Flutter Example',
        theme: ThemeData(primaryColor: Colors.blue),
        home: MyApp(),
      ),
    );

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Color currentColor = Color(0xff443a49);

  ValueChanged<Color> onColorChanged;

  changeSimpleColor(Color color) => setState(() => currentColor = color);
  changeMaterialColor(Color color) => setState(() {
        currentColor = color;
        Navigator.of(context).pop();
      });

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: Text('Flutter Color Picker Example'),
          bottom: TabBar(
            tabs: <Widget>[
              Tab(text: 'Simple picker'),
              Tab(text: 'Material picker'),
            ],
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            Center(
              child: RaisedButton(
                elevation: 3.0,
                onPressed: () {
                  showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        titlePadding: EdgeInsets.all(0.0),
                        contentPadding: EdgeInsets.all(0.0),
                        content: SingleChildScrollView(
                          child: ColorPicker(
                            pickerColor: currentColor,
                            onColorChanged: changeSimpleColor,
                            colorPickerWidth: 1000.0,
                            pickerAreaHeightPercent: 0.7,
                            enableAlpha: true,
                          ),
                        ),
                      );
                    },
                  );
                },
                child: Text('Change me'),
                color: currentColor,
                textColor: useWhiteForeground(currentColor)
                    ? const Color(0xffffffff)
                    : const Color(0xff000000),
              ),
            ),
            Center(
              child: RaisedButton(
                elevation: 3.0,
                onPressed: () {
                  showDialog(
                    context: context,
                    builder: (BuildContext context) {
                      return AlertDialog(
                        titlePadding: EdgeInsets.all(0.0),
                        contentPadding: EdgeInsets.all(0.0),
                        content: SingleChildScrollView(
                          child: MaterialPicker(
                            pickerColor: currentColor,
                            onColorChanged: changeMaterialColor,
                            enableLabel: true,
                          ),
                        ),
                      );
                    },
                  );
                },
                child: Text('Change me'),
                color: currentColor,
                textColor: useWhiteForeground(currentColor)
                    ? const Color(0xffffffff)
                    : const Color(0xff000000),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_colorpicker: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_colorpicker/flutter_colorpicker.dart';
  
Version Uploaded Documentation Archive
0.1.0 Oct 8, 2018 Go to the documentation of flutter_colorpicker 0.1.0 Download flutter_colorpicker 0.1.0 archive
0.0.7 Aug 20, 2018 Go to the documentation of flutter_colorpicker 0.0.7 Download flutter_colorpicker 0.0.7 archive
0.0.6 Aug 20, 2018 Go to the documentation of flutter_colorpicker 0.0.6 Download flutter_colorpicker 0.0.6 archive
0.0.5 May 24, 2018 Go to the documentation of flutter_colorpicker 0.0.5 Download flutter_colorpicker 0.0.5 archive
0.0.4 Mar 12, 2018 Go to the documentation of flutter_colorpicker 0.0.4 Download flutter_colorpicker 0.0.4 archive
0.0.3 Mar 11, 2018 Go to the documentation of flutter_colorpicker 0.0.3 Download flutter_colorpicker 0.0.3 archive
0.0.2 Mar 10, 2018 Go to the documentation of flutter_colorpicker 0.0.2 Download flutter_colorpicker 0.0.2 archive
0.0.1+1 Feb 23, 2018 Go to the documentation of flutter_colorpicker 0.0.1+1 Download flutter_colorpicker 0.0.1+1 archive
0.0.1 Feb 23, 2018 Go to the documentation of flutter_colorpicker 0.0.1 Download flutter_colorpicker 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
91
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]
95
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8