Dropdown tweaks (#1182)

pull/1186/head
BambinoUA 2 years ago committed by GitHub
parent 752e1a746b
commit 6d9b43f909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      lib/src/utils/widgets.dart
  2. 63
      lib/src/widgets/toolbar/quill_font_family_button.dart
  3. 42
      lib/src/widgets/toolbar/quill_font_size_button.dart

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
typedef WidgetWrapper = Widget Function(Widget child);
/// Provides utiulity widgets. /// Provides utiulity widgets.
abstract class UtilityWidgets { abstract class UtilityWidgets {
/// Conditionally wraps the [child] with [Tooltip] widget if [message] /// Conditionally wraps the [child] with [Tooltip] widget if [message]
@ -8,4 +10,12 @@ abstract class UtilityWidgets {
(message ?? '').isNotEmpty (message ?? '').isNotEmpty
? Tooltip(message: message!, child: child) ? Tooltip(message: message!, child: child)
: child; : child;
/// Conditionally wraps the [child] with [wrapper] widget if [enabled]
/// is true.
static Widget maybeWidget(
{required WidgetWrapper wrapper,
required Widget child,
bool enabled = false}) =>
enabled ? wrapper(child) : child;
} }

@ -25,9 +25,16 @@ class QuillFontFamilyButton extends StatefulWidget {
this.style, this.style,
this.width, this.width,
this.renderFontFamilies = true, this.renderFontFamilies = true,
this.alignment, this.initialValue,
this.labelOverflow = TextOverflow.visible,
this.overrideTooltipByFontFamily = false,
this.itemHeight,
this.itemPadding,
this.defaultItemColor = Colors.red,
Key? key, Key? key,
}) : super(key: key); }) : assert(rawItemsMap.length > 0),
assert(initialValue == null || initialValue.length > 0),
super(key: key);
final double iconSize; final double iconSize;
final Color? fillColor; final Color? fillColor;
@ -46,7 +53,12 @@ class QuillFontFamilyButton extends StatefulWidget {
final TextStyle? style; final TextStyle? style;
final double? width; final double? width;
final bool renderFontFamilies; final bool renderFontFamilies;
final AlignmentGeometry? alignment; final String? initialValue;
final TextOverflow labelOverflow;
final bool overrideTooltipByFontFamily;
final double? itemHeight;
final EdgeInsets? itemPadding;
final Color? defaultItemColor;
@override @override
_QuillFontFamilyButtonState createState() => _QuillFontFamilyButtonState(); _QuillFontFamilyButtonState createState() => _QuillFontFamilyButtonState();
@ -60,7 +72,7 @@ class _QuillFontFamilyButtonState extends State<QuillFontFamilyButton> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_currentValue = _defaultDisplayText = 'Font'.i18n; _currentValue = _defaultDisplayText = widget.initialValue ?? 'Font'.i18n;
widget.controller.addListener(_didChangeEditingValue); widget.controller.addListener(_didChangeEditingValue);
} }
@ -105,8 +117,18 @@ class _QuillFontFamilyButtonState extends State<QuillFontFamilyButton> {
height: widget.iconSize * 1.81, height: widget.iconSize * 1.81,
width: widget.width, width: widget.width,
), ),
child: UtilityWidgets.maybeTooltip( child: UtilityWidgets.maybeWidget(
message: widget.tooltip, enabled: (widget.tooltip ?? '').isNotEmpty ||
widget.overrideTooltipByFontFamily,
wrapper: (child) {
var effectiveTooltip = widget.tooltip ?? '';
if (widget.overrideTooltipByFontFamily) {
effectiveTooltip = effectiveTooltip.isNotEmpty
? '$effectiveTooltip: $_currentValue'
: '${'Font'.i18n}: $_currentValue';
}
return Tooltip(message: effectiveTooltip, child: child);
},
child: RawMaterialButton( child: RawMaterialButton(
visualDensity: VisualDensity.compact, visualDensity: VisualDensity.compact,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
@ -146,12 +168,16 @@ class _QuillFontFamilyButtonState extends State<QuillFontFamilyButton> {
PopupMenuItem<String>( PopupMenuItem<String>(
key: ValueKey(fontFamily.key), key: ValueKey(fontFamily.key),
value: fontFamily.value, value: fontFamily.value,
height: widget.itemHeight ?? kMinInteractiveDimension,
padding: widget.itemPadding,
child: Text( child: Text(
fontFamily.key.toString(), fontFamily.key.toString(),
style: TextStyle( style: TextStyle(
fontFamily: fontFamily: widget.renderFontFamilies ? fontFamily.value : null,
widget.renderFontFamilies ? fontFamily.value : null, color: fontFamily.value == 'Clear'
color: fontFamily.value == 'Clear' ? Colors.red : null), ? widget.defaultItemColor
: null,
),
), ),
), ),
], ],
@ -177,18 +203,27 @@ class _QuillFontFamilyButtonState extends State<QuillFontFamilyButton> {
Widget _buildContent(BuildContext context) { Widget _buildContent(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
return Container( final hasFinalWidth = widget.width != null;
alignment: widget.alignment ?? Alignment.center, return Padding(
padding: widget.padding ?? const EdgeInsets.fromLTRB(10, 0, 0, 0), padding: widget.padding ?? const EdgeInsets.fromLTRB(10, 0, 0, 0),
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: !hasFinalWidth ? MainAxisSize.min : MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text(_currentValue, UtilityWidgets.maybeWidget(
enabled: hasFinalWidth,
wrapper: (child) => Expanded(child: child),
child: Text(
_currentValue,
maxLines: 1,
overflow: widget.labelOverflow,
style: widget.style ?? style: widget.style ??
TextStyle( TextStyle(
fontSize: widget.iconSize / 1.15, fontSize: widget.iconSize / 1.15,
color: widget.iconTheme?.iconUnselectedColor ?? color: widget.iconTheme?.iconUnselectedColor ??
theme.iconTheme.color)), theme.iconTheme.color),
),
),
const SizedBox(width: 3), const SizedBox(width: 3),
Icon(Icons.arrow_drop_down, Icon(Icons.arrow_drop_down,
size: widget.iconSize / 1.15, size: widget.iconSize / 1.15,

@ -26,9 +26,13 @@ class QuillFontSizeButton extends StatefulWidget {
this.style, this.style,
this.width, this.width,
this.initialValue, this.initialValue,
this.alignment, this.labelOverflow = TextOverflow.visible,
this.itemHeight,
this.itemPadding,
this.defaultItemColor = Colors.red,
Key? key, Key? key,
}) : assert(rawItemsMap.length > 0), }) : assert(rawItemsMap.length > 0),
assert(initialValue == null || initialValue.length > 0),
super(key: key); super(key: key);
final double iconSize; final double iconSize;
@ -48,7 +52,10 @@ class QuillFontSizeButton extends StatefulWidget {
final TextStyle? style; final TextStyle? style;
final double? width; final double? width;
final String? initialValue; final String? initialValue;
final AlignmentGeometry? alignment; final TextOverflow labelOverflow;
final double? itemHeight;
final EdgeInsets? itemPadding;
final Color? defaultItemColor;
@override @override
_QuillFontSizeButtonState createState() => _QuillFontSizeButtonState(); _QuillFontSizeButtonState createState() => _QuillFontSizeButtonState();
@ -148,10 +155,13 @@ class _QuillFontSizeButtonState extends State<QuillFontSizeButton> {
PopupMenuItem<String>( PopupMenuItem<String>(
key: ValueKey(fontSize.key), key: ValueKey(fontSize.key),
value: fontSize.value, value: fontSize.value,
height: widget.itemHeight ?? kMinInteractiveDimension,
padding: widget.itemPadding,
child: Text( child: Text(
fontSize.key.toString(), fontSize.key.toString(),
style: style: TextStyle(
TextStyle(color: fontSize.value == '0' ? Colors.red : null), color: fontSize.value == '0' ? widget.defaultItemColor : null,
),
), ),
), ),
], ],
@ -177,18 +187,24 @@ class _QuillFontSizeButtonState extends State<QuillFontSizeButton> {
Widget _buildContent(BuildContext context) { Widget _buildContent(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
return Container( final hasFinalWidth = widget.width != null;
alignment: widget.alignment ?? Alignment.center, return Padding(
padding: widget.padding ?? const EdgeInsets.fromLTRB(10, 0, 0, 0), padding: widget.padding ?? const EdgeInsets.fromLTRB(10, 0, 0, 0),
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: !hasFinalWidth ? MainAxisSize.min : MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text(_currentValue, UtilityWidgets.maybeWidget(
style: widget.style ?? enabled: hasFinalWidth,
TextStyle( wrapper: (child) => Expanded(child: child),
fontSize: widget.iconSize / 1.15, child: Text(_currentValue,
color: widget.iconTheme?.iconUnselectedColor ?? overflow: widget.labelOverflow,
theme.iconTheme.color)), style: widget.style ??
TextStyle(
fontSize: widget.iconSize / 1.15,
color: widget.iconTheme?.iconUnselectedColor ??
theme.iconTheme.color)),
),
const SizedBox(width: 3), const SizedBox(width: 3),
Icon(Icons.arrow_drop_down, Icon(Icons.arrow_drop_down,
size: widget.iconSize / 1.15, size: widget.iconSize / 1.15,

Loading…
Cancel
Save