From 864b17030673113e3ebaaed1ee050de888d11395 Mon Sep 17 00:00:00 2001 From: mark8044 <87546778+mark8044@users.noreply.github.com> Date: Sun, 14 Nov 2021 10:05:50 -0800 Subject: [PATCH] Update select_alignment_button.dart --- .../toolbar/select_alignment_button.dart | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/src/widgets/toolbar/select_alignment_button.dart b/lib/src/widgets/toolbar/select_alignment_button.dart index 9761a96d..df3abb8b 100644 --- a/lib/src/widgets/toolbar/select_alignment_button.dart +++ b/lib/src/widgets/toolbar/select_alignment_button.dart @@ -12,6 +12,10 @@ class SelectAlignmentButton extends StatefulWidget { required this.controller, this.iconSize = kDefaultIconSize, this.iconTheme, + this.showLeftAlignment, + this.showCenterAlignment, + this.showRightAlignment, + this.showJustifyAlignment, Key? key, }) : super(key: key); @@ -19,6 +23,10 @@ class SelectAlignmentButton extends StatefulWidget { final double iconSize; final QuillIconTheme? iconTheme; + final bool? showLeftAlignment; + final bool? showCenterAlignment; + final bool? showRightAlignment; + final bool? showJustifyAlignment; @override _SelectAlignmentButtonState createState() => _SelectAlignmentButtonState(); @@ -42,30 +50,32 @@ class _SelectAlignmentButtonState extends State { @override Widget build(BuildContext context) { final _valueToText = { - Attribute.leftAlignment: Attribute.leftAlignment.value!, - Attribute.centerAlignment: Attribute.centerAlignment.value!, - Attribute.rightAlignment: Attribute.rightAlignment.value!, - Attribute.justifyAlignment: Attribute.justifyAlignment.value!, + if (widget.showLeftAlignment!) Attribute.leftAlignment: Attribute.leftAlignment.value!, + if (widget.showCenterAlignment!) Attribute.centerAlignment: Attribute.centerAlignment.value!, + if (widget.showRightAlignment!) Attribute.rightAlignment: Attribute.rightAlignment.value!, + if (widget.showJustifyAlignment!) Attribute.justifyAlignment: Attribute.justifyAlignment.value!, }; final _valueAttribute = [ - Attribute.leftAlignment, - Attribute.centerAlignment, - Attribute.rightAlignment, - Attribute.justifyAlignment + if (widget.showLeftAlignment!) Attribute.leftAlignment, + if (widget.showCenterAlignment!) Attribute.centerAlignment, + if (widget.showRightAlignment!) Attribute.rightAlignment, + if (widget.showJustifyAlignment!) Attribute.justifyAlignment ]; final _valueString = [ - Attribute.leftAlignment.value!, - Attribute.centerAlignment.value!, - Attribute.rightAlignment.value!, - Attribute.justifyAlignment.value!, + if (widget.showLeftAlignment!) Attribute.leftAlignment.value!, + if (widget.showCenterAlignment!) Attribute.centerAlignment.value!, + if (widget.showRightAlignment!) Attribute.rightAlignment.value!, + if (widget.showJustifyAlignment!) Attribute.justifyAlignment.value!, ]; final theme = Theme.of(context); + + final buttonCount = ((widget.showLeftAlignment!) ? 1 : 0) + ((widget.showCenterAlignment!) ? 1 : 0) + ((widget.showRightAlignment!) ? 1 : 0) + ((widget.showJustifyAlignment!) ? 1 : 0); return Row( mainAxisSize: MainAxisSize.min, - children: List.generate(4, (index) { + children: List.generate(buttonCount, (index) { return Padding( padding: const EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0), child: ConstrainedBox(