Skip to content

Commit 0672dfc

Browse files
committed
FEATURE: ColorPicker.tonalColorSameSize
1 parent 5bec50e commit 0672dfc

File tree

13 files changed

+81
-14
lines changed

13 files changed

+81
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
All notable changes to the **FlexColorPicker** package are documented in this file.
44

5-
## 3.2.3
5+
## 3.3.0
66

77
**July 18, 2023**
88

9+
**NEW**
10+
11+
- Use `ColorPicker.tonalColorSameSize` set to true, to make the Material-3 HCT tonal palette color indicators use the same size as the size defined for the other color indicators. Previously and by default, the tonal color indicators are smaller to make the palette width match the width of the Material-2 swatch color palette, that has fewer colors.
12+
913
**FIX**
1014

1115
- Fixed issue [#67 Inner circle does not move](https://github.com/rydmike/flex_color_picker/issues/67).

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ aware COPY-PASTE keyboard shortcuts.
3535
- [Elements of the Picker](#elements-of-the-picker)
3636
- [Enabled Color Pickers](#enabled-color-pickers)
3737
- [Enable Shades Selection](#enable-shades-selection)
38+
- [Tonal Palette](#tonal-palette)
3839
- [Custom Color Swatches](#custom-color-swatches)
3940
- [Customized labels](#customized-labels)
4041
- [Enable Opacity](#enable-opacity)
@@ -721,11 +722,11 @@ which you do by setting `enableShadesSelection` to false.
721722

722723
<img src="https://github.com/rydmike/flex_color_picker/blob/master/resources/FCP-enabled-4.png?raw=true" alt="Pickers 4"/>
723724

724-
### Enable Tonal Palette
725+
### Tonal Palette
725726

726-
API reference: [enableTonalPalette](https://pub.dev/documentation/flex_color_picker/latest/flex_color_picker/ColorPicker/enableTonalPalette.html)
727+
API reference: [enableTonalPalette](https://pub.dev/documentation/flex_color_picker/latest/flex_color_picker/ColorPicker/enableTonalPalette.html), [tonalColorSameSize](https://pub.dev/documentation/flex_color_picker/latest/flex_color_picker/ColorPicker/tonalColorSameSize.html)
727728

728-
By default, generation of a selected color's new Material 3 tonal-palette is disabled. You can enable
729+
By default, generation of a selected color's Material-3 tonal-palette is disabled. You can enable
729730
it by setting `enableTonalPalette` to true.
730731

731732
When you click/select a color in the color picker and tonal palette is enabled, a 15 shade
@@ -742,17 +743,20 @@ does not update the palette. Only when you select a color from the other color
742743
sources in the picker, is that color used as key color, to seed and generate an
743744
updated color palette for the selected color.
744745

745-
For more info on Material 3 Color system, see:
746-
https://m3.material.io/styles/color/the-color-system/key-colors-tones
746+
For more info on Material-3 Color system, see the [official guide](https://m3.material.io/styles/color/the-color-system/key-colors-tones).
747747

748748
The picker item size for tonal palette color indicator items is
749749
10/13 the size of defined width and height. This is done in order to
750750
as far as possible try to match the width of the Primary Material Swatch
751751
items total width. It has 10 colors, the M3 tonal palette has 15 colors.
752-
The goal is to match their width when they are both shown.
752+
The goal is to match their width when they are both shown. If you want the tonal
753+
palette color indicator items to be the same size as the other color indicators,
754+
set `tonalColorSameSize: true`.
753755

754756
<img src="https://github.com/rydmike/flex_color_picker/blob/master/resources/FCP-enabled-tonal-4.png?raw=true" alt="Tonal pickers 4"/>
755757

758+
759+
756760
### Custom Color Swatches
757761

758762
API reference: [customColorSwatchesAndNames](https://pub.dev/documentation/flex_color_picker/latest/flex_color_picker/ColorPicker/customColorSwatchesAndNames.html)
@@ -816,7 +820,7 @@ This will create three custom color swatches, using our "Alpine", "Rust" and "La
816820
swatch picker.
817821
<img src="https://github.com/rydmike/flex_color_picker/blob/master/resources/FCP-enabled-6.png?raw=true" alt="Picker 6"/>
818822

819-
### Customized labels
823+
### Customized labels
820824
API reference: [pickerTypeLabels](https://pub.dev/documentation/flex_color_picker/latest/flex_color_picker/ColorPicker/pickerTypeLabels.html)
821825

822826
The picker labels have default English labels, you can override them to customize or translate the labels. You set the

example/lib/demo/pods/pods.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ final StateProvider<bool> enableTonesSelectionPod =
163163
defaultValue: Keys.defaults[Keys.enableTonesSelection]! as bool) as bool;
164164
}, name: Keys.enableTonesSelection);
165165

166+
// State of using same size tonal color items.
167+
final StateProvider<bool> tonalSameSizePod =
168+
StateProvider<bool>((StateProviderRef<bool> ref) {
169+
return hiveStore.get(Keys.tonalSameSize,
170+
defaultValue: Keys.defaults[Keys.tonalSameSize]! as bool) as bool;
171+
}, name: Keys.tonalSameSize);
172+
166173
// State of including index 850 for grey color.
167174
final StateProvider<bool> includeIndex850Pod =
168175
StateProvider<bool>((StateProviderRef<bool> ref) {

example/lib/demo/pods/pods_reset.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ void resetSettings(WidgetRef ref) {
9090

9191
ref.read(sizePod.notifier).state = Keys.defaults[Keys.size]! as double;
9292

93+
ref.read(tonalSameSizePod.notifier).state =
94+
Keys.defaults[Keys.tonalSameSize]! as bool;
95+
9396
ref.read(borderRadiusPod.notifier).state =
9497
Keys.defaults[Keys.borderRadius]! as double;
9598

example/lib/demo/screens/color_picker/all_control_widgets.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export 'picker_switches/shades_switch.dart';
5555
export 'picker_switches/snackbar_parse_error_switch.dart';
5656
export 'picker_switches/subheading_switch.dart';
5757
export 'picker_switches/title_switch.dart';
58+
export 'picker_switches/tonal_same_size_switch.dart';
5859
export 'picker_switches/tonal_subheading_switch.dart';
5960
export 'picker_switches/tonal_switch.dart';
6061
export 'picker_switches/toolbar_copy_switch.dart';

example/lib/demo/screens/color_picker/color_picker_card.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ColorPickerCard extends ConsumerWidget {
6060
),
6161
width: ref.watch(sizePod),
6262
height: ref.watch(sizePod),
63+
tonalColorSameSize: ref.watch(tonalSameSizePod),
6364
spacing: ref.watch(spacingPod),
6465
runSpacing: ref.watch(runSpacingPod),
6566
elevation: ref.watch(elevationPod),

example/lib/demo/screens/color_picker/color_picker_dialog.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Future<bool> colorPickerDialog(
7474
),
7575
width: ref.watch(sizePod),
7676
height: ref.watch(sizePod),
77+
tonalColorSameSize: ref.watch(tonalSameSizePod),
7778
spacing: ref.watch(spacingPod),
7879
runSpacing: ref.watch(runSpacingPod),
7980
elevation: ref.watch(elevationPod),

example/lib/demo/screens/color_picker/color_picker_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ class _Column3 extends StatelessWidget {
272272
),
273273
// Color picker size
274274
const ItemSizeSlider(),
275+
const TonalSameSizeSwitch(),
275276
const BorderRadiusSlider(),
276277
const ElevationSlider(),
277278
const SpacingSlider(),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_riverpod/flutter_riverpod.dart';
3+
4+
import '../../../pods/pods.dart';
5+
import '../../../widgets/switch_tile_tooltip.dart';
6+
7+
@immutable
8+
class TonalSameSizeSwitch extends ConsumerWidget {
9+
const TonalSameSizeSwitch({super.key});
10+
11+
@override
12+
Widget build(BuildContext context, WidgetRef ref) {
13+
return SwitchTileTooltip(
14+
title: const Text('Tonal color items same size'),
15+
subtitle: const Text('When OFF tonal color items are smaller and same '
16+
'width as the items making up a Material swatch color palette.'),
17+
value: ref.watch(tonalSameSizePod),
18+
onChanged: (bool value) =>
19+
ref.read(tonalSameSizePod.notifier).state = value,
20+
tooltipEnabled: ref.watch(enableTooltipsPod),
21+
tooltip: 'ColorPicker(tonalColorSameSize: '
22+
'${ref.read(tonalSameSizePod)})',
23+
);
24+
}
25+
}

example/lib/demo/utils/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class App {
99
// Web demo with inside the app. Shown on the start screen in the demo,
1010
// so people testing it don't have to ask. Also info for the About screen.
1111
static const String appName = 'FlexColorPicker';
12-
static const String version = '3.2.3';
12+
static const String version = '3.3.0';
1313
static const String packageVersion = 'FlexColorPicker package $version';
1414
static final Uri packageUri = Uri(
1515
scheme: 'https',

example/lib/demo/utils/keys.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Keys {
1919
static const String pickersEnabled = 'pickersEnabled';
2020
static const String enableShadesSelection = 'enableShadesSelection';
2121
static const String enableTonesSelection = 'enableTonesSelection';
22+
static const String tonalSameSize = 'tonalSameSize';
2223
static const String includeIndex850 = 'includeIndex850';
2324
static const String enableOpacity = 'enableOpacity';
2425
static const String showMaterialName = 'showMaterialName';
@@ -95,6 +96,7 @@ class Keys {
9596
},
9697
enableShadesSelection: true,
9798
enableTonesSelection: true,
99+
tonalSameSize: false,
98100
includeIndex850: false,
99101
enableOpacity: true,
100102
showMaterialName: true,

lib/src/color_picker.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class ColorPicker extends StatefulWidget {
102102
// Picker item and wheel picker properties.
103103
this.width = 40,
104104
this.height = 40,
105+
this.tonalColorSameSize = false,
105106
this.spacing = 4,
106107
this.runSpacing = 4,
107108
this.elevation = 0,
@@ -341,6 +342,19 @@ class ColorPicker extends StatefulWidget {
341342
/// Defaults to 40 dp. Must be from 15 to 150 dp.
342343
final double height;
343344

345+
/// Set to true to make tonal color items same size as the size defined
346+
/// for main and swatch shades indicator items.
347+
///
348+
/// If false, the tonal color items will be smaller and auto sized for the
349+
/// palette to be same width as the Material Color palette.
350+
///
351+
/// Defaults to false. The color boxes are smaller, but length of their
352+
/// items is the same as MaterialColor swatch. You may prefer true to get
353+
/// them to be same size, especially if you only use tonal palette.
354+
///
355+
/// For legacy compatibility reasons, this property is false by default.
356+
final bool tonalColorSameSize;
357+
344358
/// The horizontal spacing between the color picker indicator items.
345359
///
346360
/// Defaults to 4 dp. Must be from 0 to 50 dp.
@@ -1821,10 +1835,14 @@ class _ColorPickerState extends State<ColorPicker> {
18211835
});
18221836
},
18231837
tonalShouldUpdate: _tonalShouldUpdate,
1824-
width: (widget.width + widget.spacing) * 10 / 15 -
1825-
widget.spacing,
1826-
height: (widget.width + widget.spacing) * 10 / 15 -
1827-
widget.spacing,
1838+
width: widget.tonalColorSameSize
1839+
? widget.width
1840+
: (widget.width + widget.spacing) * 10 / 15 -
1841+
widget.spacing,
1842+
height: widget.tonalColorSameSize
1843+
? widget.width
1844+
: (widget.width + widget.spacing) * 10 / 15 -
1845+
widget.spacing,
18281846
borderRadius: widget.borderRadius,
18291847
hasBorder: widget.hasBorder,
18301848
borderColor: widget.borderColor,

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flex_color_picker
22
description: A customizable Flutter primary, accent and custom color picker. Includes an optional HSV wheel color picker.
3-
version: 3.2.3
3+
version: 3.3.0
44
homepage: https://github.com/rydmike/flex_color_picker
55
repository: https://github.com/rydmike/flex_color_picker
66
issue_tracker: https://github.com/rydmike/flex_color_picker/issues

0 commit comments

Comments
 (0)