Bug fix and other changes

pull/1486/head
Ellet 2 years ago
parent 2610dab118
commit c2d1942af6
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 10
      .github/ISSUE_TEMPLATE/issue-template.md
  2. 65
      lib/src/models/config/toolbar/buttons/link_style2.dart
  3. 2
      lib/src/models/config/toolbar/buttons/select_alignment.dart
  4. 17
      lib/src/models/config/toolbar/buttons/select_header_style.dart
  5. 14
      lib/src/models/rules/insert.dart
  6. 4
      lib/src/widgets/toolbar/buttons/arrow_indicated_list.dart
  7. 18
      lib/src/widgets/toolbar/buttons/link_style.dart
  8. 186
      lib/src/widgets/toolbar/buttons/link_style2.dart
  9. 64
      lib/src/widgets/toolbar/buttons/select_alignment.dart
  10. 52
      lib/src/widgets/toolbar/buttons/select_header_style.dart

@ -1,20 +1,16 @@
--- ---
name: Issue template name: Issue template
about: Common things to fill about: Common things to fill
title: "[Web] or [Mobile] or [Desktop]" title: "Issue in [Mobile, Desktop, Web]"
labels: '' labels: ''
assignees: '' assignees: ''
--- ---
My issue is about [Web]
My issue is about [Mobile]
My issue is about [Desktop]
I have tried running `example` directory successfully before creating an issue here.
Please note that we are using <b>latest</b> flutter version in stable channel on branch master. If you are using beta or master channel, or you are not using <b>latest</b> flutter version in stable channel, you may experience error. Please note that we are using <b>latest</b> flutter version in stable channel on branch master. If you are using beta or master channel, or you are not using <b>latest</b> flutter version in stable channel, you may experience error.
<!-- Did you try the running `example` directory?? How does it goes -->
<!-- Please explain how to encounter the issue in details if possible --> <!-- Please explain how to encounter the issue in details if possible -->
<!-- Don't forgot to mention the platform you are testing in --> <!-- Don't forgot to mention the platform you are testing in -->

@ -0,0 +1,65 @@
import 'package:flutter/widgets.dart';
import '../../../../widgets/controller.dart';
import '../../../themes/quill_dialog_theme.dart';
import '../../../themes/quill_icon_theme.dart';
import 'base.dart';
class QuillToolbarLinkStyleButton2ExtraOptions
extends QuillToolbarBaseButtonExtraOptions {
const QuillToolbarLinkStyleButton2ExtraOptions({
required super.controller,
required super.context,
required super.onPressed,
});
}
class QuillToolbarLinkStyleButton2Options extends QuillToolbarBaseButtonOptions<
QuillToolbarLinkStyleButton2Options,
QuillToolbarLinkStyleButton2ExtraOptions> {
const QuillToolbarLinkStyleButton2Options({
this.iconSize,
this.dialogTheme,
this.constraints,
this.addLinkLabel,
this.editLinkLabel,
this.linkColor,
this.validationMessage,
this.buttonSize,
this.dialogBarrierColor,
this.childrenSpacing = 16.0,
this.autovalidateMode = AutovalidateMode.disabled,
super.iconData,
super.afterButtonPressed,
super.tooltip,
super.iconTheme,
super.childBuilder,
super.controller,
});
final double? iconSize;
final QuillDialogTheme? dialogTheme;
/// The constrains for dialog.
final BoxConstraints? constraints;
/// The text of label in link add mode.
final String? addLinkLabel;
/// The text of label in link edit mode.
final String? editLinkLabel;
/// The color of URL.
final Color? linkColor;
/// The margin between child widgets in the dialog.
final double childrenSpacing;
final AutovalidateMode autovalidateMode;
final String? validationMessage;
/// The size of dialog buttons.
final Size? buttonSize;
final Color? dialogBarrierColor;
}

@ -19,6 +19,8 @@ class QuillToolbarSelectAlignmentButtonOptions
this.tooltips, this.tooltips,
this.iconSize, this.iconSize,
super.afterButtonPressed, super.afterButtonPressed,
/// This will called on every select alignment button
super.childBuilder, super.childBuilder,
super.controller, super.controller,
super.iconTheme, super.iconTheme,

@ -20,20 +20,21 @@ class QuillToolbarSelectHeaderStyleButtonsOptions
super.afterButtonPressed, super.afterButtonPressed,
super.childBuilder, super.childBuilder,
super.controller, super.controller,
super.iconData,
super.iconTheme, super.iconTheme,
super.tooltip, super.tooltip,
this.axis, this.axis,
this.attributes = const [ this.attributes,
Attribute.header,
Attribute.h1,
Attribute.h2,
Attribute.h3,
],
this.iconSize, this.iconSize,
}); });
final List<Attribute> attributes; /// Default value:
/// const [
/// Attribute.header,
/// Attribute.h1,
/// Attribute.h2,
/// Attribute.h3,
/// ]
final List<Attribute>? attributes;
/// By default we will the toolbar axis from [QuillToolbarConfigurations] /// By default we will the toolbar axis from [QuillToolbarConfigurations]
final Axis? axis; final Axis? axis;

@ -358,14 +358,14 @@ class AutoFormatMultipleLinksRule extends InsertRule {
// TODO: You might want to rename those but everywhere even in // TODO: You might want to rename those but everywhere even in
// flutter_quill_extensions // flutter_quill_extensions
static const _oneLinePattern = static const _oneLineLinkPattern =
r'^https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?(\/.*)?$'; r'^https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?(\/.*)?$';
static const _detectLinkPattern = static const _detectLinkPattern =
r'https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?(\/[^\s]*)?'; r'https?:\/\/[\w\-]+(\.[\w\-]+)*(:\d+)?(\/[^\s]*)?';
/// It requires a valid link in one link /// It requires a valid link in one link
static final oneLineRegExp = RegExp( static final oneLineLinkRegExp = RegExp(
_oneLinePattern, _oneLineLinkPattern,
caseSensitive: false, caseSensitive: false,
); );
@ -375,10 +375,10 @@ class AutoFormatMultipleLinksRule extends InsertRule {
_detectLinkPattern, _detectLinkPattern,
caseSensitive: false, caseSensitive: false,
); );
@Deprecated( // @Deprecated(
'Please use [linkRegExp1] or [linkRegExp2]', // 'Please use [linkRegExp1] or [linkRegExp2]',
) // )
static final linkRegExp = oneLineRegExp; static final linkRegExp = oneLineLinkRegExp;
@override @override
Delta? applyRule( Delta? applyRule(

@ -10,8 +10,8 @@ class QuillToolbarArrowIndicatedButtonList extends StatefulWidget {
const QuillToolbarArrowIndicatedButtonList({ const QuillToolbarArrowIndicatedButtonList({
required this.axis, required this.axis,
required this.buttons, required this.buttons,
Key? key, super.key,
}) : super(key: key); });
final Axis axis; final Axis axis;
final List<Widget> buttons; final List<Widget> buttons;

@ -95,14 +95,13 @@ class _QuillToolbarLinkStyleButtonState
context.requireQuillSharedConfigurations.dialogBarrierColor; context.requireQuillSharedConfigurations.dialogBarrierColor;
} }
RegExp get linkRegExp { RegExp? get linkRegExp {
return options.linkRegExp ?? RegExp(r'https?://\S+'); return options.linkRegExp;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isToggled = _getLinkAttributeValue() != null; final isToggled = _getLinkAttributeValue() != null;
final pressedHandler = () => _openLinkDialog(context);
final childBuilder = final childBuilder =
options.childBuilder ?? baseButtonExtraOptions.childBuilder; options.childBuilder ?? baseButtonExtraOptions.childBuilder;
@ -124,7 +123,7 @@ class _QuillToolbarLinkStyleButtonState
context: context, context: context,
controller: controller, controller: controller,
onPressed: () { onPressed: () {
pressedHandler(); _openLinkDialog(context);
afterButtonPressed?.call(); afterButtonPressed?.call();
}, },
), ),
@ -144,10 +143,10 @@ class _QuillToolbarLinkStyleButtonState
: (iconTheme?.iconUnselectedColor ?? theme.iconTheme.color), : (iconTheme?.iconUnselectedColor ?? theme.iconTheme.color),
), ),
fillColor: isToggled fillColor: isToggled
? (iconTheme?.iconSelectedFillColor ?? Theme.of(context).primaryColor) ? (iconTheme?.iconSelectedFillColor ?? theme.primaryColor)
: (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor), : (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor),
borderRadius: iconTheme?.borderRadius ?? 2, borderRadius: iconTheme?.borderRadius ?? 2,
onPressed: pressedHandler, onPressed: () => _openLinkDialog(context),
afterPressed: afterButtonPressed, afterPressed: afterButtonPressed,
); );
} }
@ -236,7 +235,11 @@ class _LinkDialog extends StatefulWidget {
class _LinkDialogState extends State<_LinkDialog> { class _LinkDialogState extends State<_LinkDialog> {
late String _link; late String _link;
late String _text; late String _text;
late RegExp linkRegExp;
RegExp get linkRegExp {
return widget.linkRegExp ?? AutoFormatMultipleLinksRule.oneLineLinkRegExp;
}
late TextEditingController _linkController; late TextEditingController _linkController;
late TextEditingController _textController; late TextEditingController _textController;
@ -245,7 +248,6 @@ class _LinkDialogState extends State<_LinkDialog> {
super.initState(); super.initState();
_link = widget.link ?? ''; _link = widget.link ?? '';
_text = widget.text ?? ''; _text = widget.text ?? '';
linkRegExp = widget.linkRegExp ?? AutoFormatMultipleLinksRule.oneLineRegExp;
_linkController = TextEditingController(text: _link); _linkController = TextEditingController(text: _link);
_textController = TextEditingController(text: _text); _textController = TextEditingController(text: _text);
} }

@ -5,9 +5,11 @@ import 'package:url_launcher/link.dart';
import '../../../../extensions.dart' import '../../../../extensions.dart'
show UtilityWidgets, AutoFormatMultipleLinksRule; show UtilityWidgets, AutoFormatMultipleLinksRule;
import '../../../../translations.dart'; import '../../../../translations.dart';
import '../../../models/config/toolbar/buttons/link_style2.dart';
import '../../../models/documents/attribute.dart'; import '../../../models/documents/attribute.dart';
import '../../../models/themes/quill_dialog_theme.dart'; import '../../../models/themes/quill_dialog_theme.dart';
import '../../../models/themes/quill_icon_theme.dart'; import '../../../models/themes/quill_icon_theme.dart';
import '../../../utils/extensions/build_context.dart';
import '../../controller.dart'; import '../../controller.dart';
import '../../link.dart'; import '../../link.dart';
import '../base_toolbar.dart'; import '../base_toolbar.dart';
@ -16,60 +18,20 @@ import '../base_toolbar.dart';
/// customization /// customization
/// and uses dialog similar to one which is used on [http://quilljs.com]. /// and uses dialog similar to one which is used on [http://quilljs.com].
class QuillToolbarLinkStyleButton2 extends StatefulWidget { class QuillToolbarLinkStyleButton2 extends StatefulWidget {
const QuillToolbarLinkStyleButton2({ QuillToolbarLinkStyleButton2({
required this.controller, required this.controller,
this.icon, required this.options,
this.iconSize = kDefaultIconSize, super.key,
this.iconTheme, }) : assert(options.addLinkLabel == null ||
this.dialogTheme, (options.addLinkLabel?.isNotEmpty ?? true)),
this.afterButtonPressed, assert(options.editLinkLabel == null ||
this.tooltip, (options.editLinkLabel?.isNotEmpty ?? true)),
this.constraints, assert(options.childrenSpacing > 0),
this.addLinkLabel, assert(options.validationMessage == null ||
this.editLinkLabel, (options.validationMessage?.isNotEmpty ?? true));
this.linkColor,
this.childrenSpacing = 16.0,
this.autovalidateMode = AutovalidateMode.disabled,
this.validationMessage,
this.buttonSize,
this.dialogBarrierColor = Colors.black54,
Key? key,
}) : assert(addLinkLabel == null || addLinkLabel.length > 0),
assert(editLinkLabel == null || editLinkLabel.length > 0),
assert(childrenSpacing > 0),
assert(validationMessage == null || validationMessage.length > 0),
super(key: key);
final QuillController controller; final QuillController controller;
final IconData? icon; final QuillToolbarLinkStyleButton2Options options;
final double iconSize;
final QuillIconTheme? iconTheme;
final QuillDialogTheme? dialogTheme;
final VoidCallback? afterButtonPressed;
final String? tooltip;
/// The constrains for dialog.
final BoxConstraints? constraints;
/// The text of label in link add mode.
final String? addLinkLabel;
/// The text of label in link edit mode.
final String? editLinkLabel;
/// The color of URL.
final Color? linkColor;
/// The margin between child widgets in the dialog.
final double childrenSpacing;
final AutovalidateMode autovalidateMode;
final String? validationMessage;
/// The size of dialog buttons.
final Size? buttonSize;
final Color dialogBarrierColor;
@override @override
State<QuillToolbarLinkStyleButton2> createState() => State<QuillToolbarLinkStyleButton2> createState() =>
@ -99,30 +61,101 @@ class _QuillToolbarLinkStyleButton2State
} }
} }
QuillController get controller {
return widget.controller;
}
QuillToolbarLinkStyleButton2Options get options {
return widget.options;
}
double get iconSize {
final baseFontSize = baseButtonExtraOptions.globalIconSize;
final iconSize = options.iconSize;
return iconSize ?? baseFontSize;
}
VoidCallback? get afterButtonPressed {
return options.afterButtonPressed ??
baseButtonExtraOptions.afterButtonPressed;
}
QuillIconTheme? get iconTheme {
return options.iconTheme ?? baseButtonExtraOptions.iconTheme;
}
QuillToolbarBaseButtonOptions get baseButtonExtraOptions {
return context.requireQuillToolbarBaseButtonOptions;
}
String get tooltip {
return options.tooltip ??
baseButtonExtraOptions.tooltip ??
'Insert URL'.i18n;
}
IconData get iconData {
return options.iconData ?? baseButtonExtraOptions.iconData ?? Icons.link;
}
Color get dialogBarrierColor {
return options.dialogBarrierColor ??
context.requireQuillSharedConfigurations.dialogBarrierColor;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final childBuilder =
options.childBuilder ?? baseButtonExtraOptions.childBuilder;
if (childBuilder != null) {
return childBuilder(
QuillToolbarLinkStyleButton2Options(
iconData: iconData,
addLinkLabel: options.addLinkLabel,
afterButtonPressed: options.afterButtonPressed,
autovalidateMode: options.autovalidateMode,
buttonSize: options.buttonSize,
childrenSpacing: options.childrenSpacing,
dialogBarrierColor: dialogBarrierColor,
dialogTheme: options.dialogTheme,
iconSize: iconSize,
constraints: options.constraints,
tooltip: tooltip,
iconTheme: iconTheme,
editLinkLabel: options.editLinkLabel,
validationMessage: options.validationMessage,
linkColor: options.linkColor,
),
QuillToolbarLinkStyleButton2ExtraOptions(
controller: controller,
context: context,
onPressed: () {
_openLinkDialog();
afterButtonPressed?.call();
},
),
);
}
final theme = Theme.of(context); final theme = Theme.of(context);
final isToggled = _getLinkAttributeValue() != null; final isToggled = _getLinkAttributeValue() != null;
return QuillToolbarIconButton( return QuillToolbarIconButton(
tooltip: widget.tooltip, tooltip: tooltip,
highlightElevation: 0, highlightElevation: 0,
hoverElevation: 0, hoverElevation: 0,
size: widget.iconSize * kIconButtonFactor, size: iconSize * kIconButtonFactor,
icon: Icon( icon: Icon(
widget.icon ?? Icons.link, iconData,
size: widget.iconSize, size: iconSize,
color: isToggled color: isToggled
? (widget.iconTheme?.iconSelectedColor ?? ? (iconTheme?.iconSelectedColor ?? theme.primaryIconTheme.color)
theme.primaryIconTheme.color) : (iconTheme?.iconUnselectedColor ?? theme.iconTheme.color),
: (widget.iconTheme?.iconUnselectedColor ?? theme.iconTheme.color),
), ),
fillColor: isToggled fillColor: isToggled
? (widget.iconTheme?.iconSelectedFillColor ?? ? (iconTheme?.iconSelectedFillColor ?? theme.primaryColor)
Theme.of(context).primaryColor) : (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor),
: (widget.iconTheme?.iconUnselectedFillColor ?? theme.canvasColor), borderRadius: iconTheme?.borderRadius ?? 2,
borderRadius: widget.iconTheme?.borderRadius ?? 2,
onPressed: _openLinkDialog, onPressed: _openLinkDialog,
afterPressed: widget.afterButtonPressed, afterPressed: afterButtonPressed,
); );
} }
@ -131,19 +164,19 @@ class _QuillToolbarLinkStyleButton2State
final textLink = await showDialog<QuillTextLink>( final textLink = await showDialog<QuillTextLink>(
context: context, context: context,
barrierColor: widget.dialogBarrierColor, barrierColor: dialogBarrierColor,
builder: (_) => LinkStyleDialog( builder: (_) => LinkStyleDialog(
dialogTheme: widget.dialogTheme, dialogTheme: options.dialogTheme,
text: initialTextLink.text, text: initialTextLink.text,
link: initialTextLink.link, link: initialTextLink.link,
constraints: widget.constraints, constraints: options.constraints,
addLinkLabel: widget.addLinkLabel, addLinkLabel: options.addLinkLabel,
editLinkLabel: widget.editLinkLabel, editLinkLabel: options.editLinkLabel,
linkColor: widget.linkColor, linkColor: options.linkColor,
childrenSpacing: widget.childrenSpacing, childrenSpacing: options.childrenSpacing,
autovalidateMode: widget.autovalidateMode, autovalidateMode: options.autovalidateMode,
validationMessage: widget.validationMessage, validationMessage: options.validationMessage,
buttonSize: widget.buttonSize, buttonSize: options.buttonSize,
), ),
); );
@ -166,7 +199,7 @@ class _QuillToolbarLinkStyleButton2State
class LinkStyleDialog extends StatefulWidget { class LinkStyleDialog extends StatefulWidget {
const LinkStyleDialog({ const LinkStyleDialog({
Key? key, super.key,
this.text, this.text,
this.link, this.link,
this.dialogTheme, this.dialogTheme,
@ -183,8 +216,7 @@ class LinkStyleDialog extends StatefulWidget {
}) : assert(addLinkLabel == null || addLinkLabel.length > 0), }) : assert(addLinkLabel == null || addLinkLabel.length > 0),
assert(editLinkLabel == null || editLinkLabel.length > 0), assert(editLinkLabel == null || editLinkLabel.length > 0),
assert(childrenSpacing > 0), assert(childrenSpacing > 0),
assert(validationMessage == null || validationMessage.length > 0), assert(validationMessage == null || validationMessage.length > 0);
super(key: key);
final String? text; final String? text;
final String? link; final String? link;
@ -387,7 +419,7 @@ class _LinkStyleDialogState extends State<LinkStyleDialog> {
String? _validateLink(String? value) { String? _validateLink(String? value) {
if ((value?.isEmpty ?? false) || if ((value?.isEmpty ?? false) ||
!AutoFormatMultipleLinksRule.oneLineRegExp.hasMatch(value!)) { !AutoFormatMultipleLinksRule.oneLineLinkRegExp.hasMatch(value!)) {
return widget.validationMessage ?? 'That is not a valid URL'; return widget.validationMessage ?? 'That is not a valid URL';
} }

@ -60,18 +60,18 @@ class _QuillToolbarSelectAlignmentButtonState
return widget.controller; return widget.controller;
} }
double get iconSize { double get _iconSize {
final baseFontSize = baseButtonExtraOptions.globalIconSize; final baseFontSize = baseButtonExtraOptions.globalIconSize;
final iconSize = options.iconSize; final iconSize = options.iconSize;
return iconSize ?? baseFontSize; return iconSize ?? baseFontSize;
} }
VoidCallback? get afterButtonPressed { VoidCallback? get _afterButtonPressed {
return options.afterButtonPressed ?? return options.afterButtonPressed ??
baseButtonExtraOptions.afterButtonPressed; baseButtonExtraOptions.afterButtonPressed;
} }
QuillIconTheme? get iconTheme { QuillIconTheme? get _iconTheme {
return options.iconTheme ?? baseButtonExtraOptions.iconTheme; return options.iconTheme ?? baseButtonExtraOptions.iconTheme;
} }
@ -191,25 +191,42 @@ class _QuillToolbarSelectAlignmentButtonState
final childBuilder = final childBuilder =
options.childBuilder ?? baseButtonExtraOptions.childBuilder; options.childBuilder ?? baseButtonExtraOptions.childBuilder;
if (childBuilder != null) { void _sharedOnPressed(int index) {
throw UnsupportedError( _valueAttribute[index] == Attribute.leftAlignment
'Sorry but the `childBuilder` for the Select alignment buttons' ? controller.formatSelection(
' is not supported. Yet but we will work on that soon.', Attribute.clone(Attribute.align, null),
); )
: controller.formatSelection(_valueAttribute[index]);
_afterButtonPressed?.call();
} }
final theme = Theme.of(context);
return Row( return Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: List.generate(buttonCount, (index) { children: List.generate(buttonCount, (index) {
if (childBuilder != null) {
return childBuilder(
QuillToolbarSelectAlignmentButtonOptions(
afterButtonPressed: _afterButtonPressed,
iconSize: _iconSize,
iconTheme: _iconTheme,
tooltips: _tooltips,
iconsData: _iconsData,
),
QuillToolbarSelectAlignmentButtonExtraOptions(
context: context,
controller: controller,
onPressed: () => _sharedOnPressed(index),
),
);
}
final theme = Theme.of(context);
return Padding( return Padding(
padding: widget.padding ?? padding: widget.padding ??
const EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0), const EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0),
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints.tightFor( constraints: BoxConstraints.tightFor(
width: iconSize * kIconButtonFactor, width: _iconSize * kIconButtonFactor,
height: iconSize * kIconButtonFactor, height: _iconSize * kIconButtonFactor,
), ),
child: UtilityWidgets.maybeTooltip( child: UtilityWidgets.maybeTooltip(
message: _valueString[index] == Attribute.leftAlignment.value message: _valueString[index] == Attribute.leftAlignment.value
@ -226,19 +243,12 @@ class _QuillToolbarSelectAlignmentButtonState
visualDensity: VisualDensity.compact, visualDensity: VisualDensity.compact,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: borderRadius:
BorderRadius.circular(iconTheme?.borderRadius ?? 2)), BorderRadius.circular(_iconTheme?.borderRadius ?? 2)),
fillColor: _valueToText[_value] == _valueString[index] fillColor: _valueToText[_value] == _valueString[index]
? (iconTheme?.iconSelectedFillColor ?? ? (_iconTheme?.iconSelectedFillColor ?? theme.primaryColor)
Theme.of(context).primaryColor) : (_iconTheme?.iconUnselectedFillColor ??
: (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor), theme.canvasColor),
onPressed: () { onPressed: () => _sharedOnPressed(index),
_valueAttribute[index] == Attribute.leftAlignment
? controller.formatSelection(
Attribute.clone(Attribute.align, null),
)
: controller.formatSelection(_valueAttribute[index]);
afterButtonPressed?.call();
},
child: Icon( child: Icon(
_valueString[index] == Attribute.leftAlignment.value _valueString[index] == Attribute.leftAlignment.value
? _iconsData.leftAlignment ? _iconsData.leftAlignment
@ -248,11 +258,11 @@ class _QuillToolbarSelectAlignmentButtonState
Attribute.rightAlignment.value Attribute.rightAlignment.value
? _iconsData.rightAlignment ? _iconsData.rightAlignment
: _iconsData.justifyAlignment, : _iconsData.justifyAlignment,
size: iconSize, size: _iconSize,
color: _valueToText[_value] == _valueString[index] color: _valueToText[_value] == _valueString[index]
? (iconTheme?.iconSelectedColor ?? ? (_iconTheme?.iconSelectedColor ??
theme.primaryIconTheme.color) theme.primaryIconTheme.color)
: (iconTheme?.iconUnselectedColor ?? : (_iconTheme?.iconUnselectedColor ??
theme.iconTheme.color), theme.iconTheme.color),
), ),
), ),

@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../../extensions.dart'; import '../../../../extensions.dart';
@ -90,10 +91,20 @@ class _QuillToolbarSelectHeaderStyleButtonsState
afterButtonPressed?.call(); afterButtonPressed?.call();
} }
List<Attribute> get _attrbuites {
return options.attributes ??
const [
Attribute.header,
Attribute.h1,
Attribute.h2,
Attribute.h3,
];
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
assert( assert(
options.attributes.every( _attrbuites.every(
(element) => _valueToText.keys.contains(element), (element) => _valueToText.keys.contains(element),
), ),
'All attributes must be one of them: header, h1, h2 or h3', 'All attributes must be one of them: header, h1, h2 or h3',
@ -107,19 +118,28 @@ class _QuillToolbarSelectHeaderStyleButtonsState
final childBuilder = final childBuilder =
options.childBuilder ?? baseButtonExtraOptions.childBuilder; options.childBuilder ?? baseButtonExtraOptions.childBuilder;
if (childBuilder != null) { final children = _attrbuites.map((attribute) {
throw UnsupportedError( if (childBuilder != null) {
'Sorry but the `childBuilder` for the Select header button' return childBuilder(
' is not supported. Yet but we will work on that soon.', QuillToolbarSelectHeaderStyleButtonsOptions(
); afterButtonPressed: afterButtonPressed,
} attributes: _attrbuites,
final theme = Theme.of(context); axis: axis,
iconSize: iconSize,
final children = options.attributes.map((attribute) { iconTheme: iconTheme,
tooltip: tooltip,
),
QuillToolbarSelectHeaderStyleButtonExtraOptions(
controller: controller,
context: context,
onPressed: () => _sharedOnPressed(attribute),
),
);
}
final theme = Theme.of(context);
final isSelected = _selectedAttribute == attribute; final isSelected = _selectedAttribute == attribute;
return Padding( return Padding(
// Do we really need to ignore (prefer_const_constructors)?? padding: const EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0),
padding: EdgeInsets.symmetric(horizontal: !isWeb() ? 1.0 : 5.0),
child: ConstrainedBox( child: ConstrainedBox(
constraints: BoxConstraints.tightFor( constraints: BoxConstraints.tightFor(
width: iconSize * kIconButtonFactor, width: iconSize * kIconButtonFactor,
@ -136,12 +156,14 @@ class _QuillToolbarSelectHeaderStyleButtonsState
borderRadius: borderRadius:
BorderRadius.circular(iconTheme?.borderRadius ?? 2)), BorderRadius.circular(iconTheme?.borderRadius ?? 2)),
fillColor: isSelected fillColor: isSelected
? (iconTheme?.iconSelectedFillColor ?? ? (iconTheme?.iconSelectedFillColor ?? theme.primaryColor)
Theme.of(context).primaryColor)
: (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor), : (iconTheme?.iconUnselectedFillColor ?? theme.canvasColor),
onPressed: () => _sharedOnPressed(attribute), onPressed: () => _sharedOnPressed(attribute),
child: Text( child: Text(
_valueToText[attribute] ?? '', _valueToText[attribute] ??
(throw ArgumentError.notNull(
'attrbuite',
)),
style: style.copyWith( style: style.copyWith(
color: isSelected color: isSelected
? (iconTheme?.iconSelectedColor ?? ? (iconTheme?.iconSelectedColor ??

Loading…
Cancel
Save