in

Flutter Material Color Picker

Flutter Material Color Picker

Material Color picker is a Flutter widget, and you totally that can be customizable follow your own way. By default, it’s Material Colors, but you can completely define your own colors.

Moreover, you can use CircleColor widget to display color in your application. For a particular example, you can set the color picker in a dialog and display the selected color in a ListTile, for settings.

How to use it

Here are these examples use a static color for ‘selectedColor’, but you can utterly use a variable (state)

Add to your Flutter project

You just need to add flutter_material_color_picker as a dependency in your pubspec.yaml file.

flutter_material_color_picker: ^1.0.3

Import

import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';

Basic

MaterialColorPicker(
    onColorChange: (Color color) {
        // Handle color changes
    },
    selectedColor: Colors.red
)

Listen main color changes

MaterialColorPicker(
    onColorChange: (Color color) {
        // Handle color changes
    },
    onMainColorChange: (ColorSwatch color) {
        // Handle main color changes
    },
    selectedColor: Colors.red
)

Disallow Shades

MaterialColorPicker(
    allowShades: false, // default true
    onMainColorChange: (ColorSwatch color) {
        // Handle main color changes
    },
    selectedColor: Colors.red
)

If allowShades is set to false then only main colors will be shown and allowed to be selected.
onColorChange will not be called, use onMainColorChange instead.

Custom colors

In this example, custom colors are a list of Material Colors (class who extend of ColorSwatch).
But you can create your own list of ColorSwatch.

MaterialColorPicker(
    onColorChange: (Color color) {
        // Handle color changes
    },
    selectedColor: Colors.red,
    colors: [
        Colors.red,
        Colors.deepOrange,
        Colors.yellow,
        Colors.lightGreen
    ],
)

Screenshot

Color selection

Here, there is two-step for you. The first step: choose the main color, and when you press it, you have to choose a shade of the main color. According to the default available, it’s all Material Colors, but you can define custom colors by your way, a list of ColorSwatch.

shade_color
main_color

Example of usages

You can insert the color picker into a Dialog

main_color_dialog
shade_color_dialog

Display color

Into your settings for example, you totally can use the CircleColor widget to display the selected color.

example_circle_color

GitHub

https://github.com/Pyozer/flutter_material_color_picker

Written by James

A package can help you to change your flutter app’s statusbar’s color

A Crossplatform Color Matching Game made with Flutter