From 993da6620a1b34cf823f012807d851d6f2e8e899 Mon Sep 17 00:00:00 2001 From: mchome Date: Sat, 11 Dec 2021 16:34:31 +0800 Subject: [PATCH] [#69] add toggle for the odd showDialog component --- example/pubspec.lock | 4 ++-- lib/src/block_picker.dart | 13 +++++++++---- lib/src/utils.dart | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index 0f4f799..263809f 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -66,7 +66,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.1.1" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=1.17.0" diff --git a/lib/src/block_picker.dart b/lib/src/block_picker.dart index d3dbbbf..9cbdf51 100644 --- a/lib/src/block_picker.dart +++ b/lib/src/block_picker.dart @@ -85,6 +85,7 @@ class BlockPicker extends StatefulWidget { required this.pickerColor, required this.onColorChanged, this.availableColors = _defaultColors, + this.useInShowDialog = true, this.layoutBuilder = _defaultLayoutBuilder, this.itemBuilder = _defaultItemBuilder, }) : super(key: key); @@ -92,6 +93,7 @@ class BlockPicker extends StatefulWidget { final Color pickerColor; final ValueChanged onColorChanged; final List availableColors; + final bool useInShowDialog; final PickerLayoutBuilder layoutBuilder; final PickerItemBuilder itemBuilder; @@ -118,9 +120,10 @@ class _BlockPickerState extends State { return widget.layoutBuilder( context, widget.availableColors, - (Color color, [bool? _, Function? __]) => widget.itemBuilder( + (Color color) => widget.itemBuilder( color, - _currentColor.value == color.value, + (_currentColor.value == color.value) && + (widget.useInShowDialog ? true : widget.pickerColor.value == color.value), () => changeColor(color), ), ); @@ -134,6 +137,7 @@ class MultipleChoiceBlockPicker extends StatefulWidget { required this.pickerColors, required this.onColorsChanged, this.availableColors = _defaultColors, + this.useInShowDialog = true, this.layoutBuilder = _defaultLayoutBuilder, this.itemBuilder = _defaultItemBuilder, }) : super(key: key); @@ -141,6 +145,7 @@ class MultipleChoiceBlockPicker extends StatefulWidget { final List pickerColors; final ValueChanged> onColorsChanged; final List availableColors; + final bool useInShowDialog; final PickerLayoutBuilder layoutBuilder; final PickerItemBuilder itemBuilder; @@ -167,9 +172,9 @@ class _MultipleChoiceBlockPickerState extends State { return widget.layoutBuilder( context, widget.availableColors, - (Color color, [bool? _, Function? __]) => widget.itemBuilder( + (Color color) => widget.itemBuilder( color, - _currentColors.contains(color), + _currentColors.contains(color) && (widget.useInShowDialog ? true : widget.pickerColors.contains(color)), () => toggleColor(color), ), ); diff --git a/lib/src/utils.dart b/lib/src/utils.dart index f663033..11c3e5e 100644 --- a/lib/src/utils.dart +++ b/lib/src/utils.dart @@ -7,8 +7,10 @@ import 'package:flutter/painting.dart'; /// the background color, and optional bias. /// /// Reference: +/// /// Old: https://www.w3.org/TR/WCAG20-TECHS/G18.html -/// new: https://github.com/mchome/flutter_statusbarcolor/issues/40 +/// +/// New: https://github.com/mchome/flutter_statusbarcolor/issues/40 bool useWhiteForeground(Color backgroundColor, {double bias = 0.0}) { // Old: // return 1.05 / (color.computeLuminance() + 0.05) > 4.5;