Add `axis` parameter to `SelectHeaderStyleButton`

pull/1101/head
Adil Hanney 2 years ago
parent d10a98c6e2
commit 31770f51d9
No known key found for this signature in database
GPG Key ID: 27A0885BC5740457
  1. 1
      lib/src/widgets/toolbar.dart
  2. 97
      lib/src/widgets/toolbar/select_header_style_button.dart

@ -376,6 +376,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
if (showHeaderStyle) if (showHeaderStyle)
SelectHeaderStyleButton( SelectHeaderStyleButton(
controller: controller, controller: controller,
axis: axis,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed, afterButtonPressed: afterButtonPressed,

@ -10,6 +10,7 @@ import '../toolbar.dart';
class SelectHeaderStyleButton extends StatefulWidget { class SelectHeaderStyleButton extends StatefulWidget {
const SelectHeaderStyleButton({ const SelectHeaderStyleButton({
required this.controller, required this.controller,
this.axis = Axis.horizontal,
this.iconSize = kDefaultIconSize, this.iconSize = kDefaultIconSize,
this.iconTheme, this.iconTheme,
this.attributes = const [ this.attributes = const [
@ -23,6 +24,7 @@ class SelectHeaderStyleButton extends StatefulWidget {
}) : super(key: key); }) : super(key: key);
final QuillController controller; final QuillController controller;
final Axis axis;
final double iconSize; final double iconSize;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final List<Attribute> attributes; final List<Attribute> attributes;
@ -67,53 +69,60 @@ class _SelectHeaderStyleButtonState extends State<SelectHeaderStyleButton> {
fontSize: widget.iconSize * 0.7, fontSize: widget.iconSize * 0.7,
); );
return Row( final children = widget.attributes.map((attribute) {
mainAxisSize: MainAxisSize.min, final isSelected = _selectedAttribute == attribute;
children: widget.attributes.map((attribute) { return Padding(
final isSelected = _selectedAttribute == attribute; // ignore: prefer_const_constructors
return Padding( padding: EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0),
// ignore: prefer_const_constructors child: ConstrainedBox(
padding: EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0), constraints: BoxConstraints.tightFor(
child: ConstrainedBox( width: widget.iconSize * kIconButtonFactor,
constraints: BoxConstraints.tightFor( height: widget.iconSize * kIconButtonFactor,
width: widget.iconSize * kIconButtonFactor, ),
height: widget.iconSize * kIconButtonFactor, child: RawMaterialButton(
), hoverElevation: 0,
child: RawMaterialButton( highlightElevation: 0,
hoverElevation: 0, elevation: 0,
highlightElevation: 0, visualDensity: VisualDensity.compact,
elevation: 0, shape: RoundedRectangleBorder(
visualDensity: VisualDensity.compact, borderRadius: BorderRadius.circular(
shape: RoundedRectangleBorder( widget.iconTheme?.borderRadius ?? 2)),
borderRadius: BorderRadius.circular( fillColor: isSelected
widget.iconTheme?.borderRadius ?? 2)), ? (widget.iconTheme?.iconSelectedFillColor ??
fillColor: isSelected Theme.of(context).primaryColor)
? (widget.iconTheme?.iconSelectedFillColor ?? : (widget.iconTheme?.iconUnselectedFillColor ??
Theme.of(context).primaryColor) theme.canvasColor),
: (widget.iconTheme?.iconUnselectedFillColor ?? onPressed: () {
theme.canvasColor), final _attribute = _selectedAttribute == attribute
onPressed: () { ? Attribute.header
final _attribute = _selectedAttribute == attribute : attribute;
? Attribute.header widget.controller.formatSelection(_attribute);
: attribute; widget.afterButtonPressed?.call();
widget.controller.formatSelection(_attribute); },
widget.afterButtonPressed?.call(); child: Text(
}, _valueToText[attribute] ?? '',
child: Text( style: style.copyWith(
_valueToText[attribute] ?? '', color: isSelected
style: style.copyWith( ? (widget.iconTheme?.iconSelectedColor ??
color: isSelected theme.primaryIconTheme.color)
? (widget.iconTheme?.iconSelectedColor ?? : (widget.iconTheme?.iconUnselectedColor ??
theme.primaryIconTheme.color) theme.iconTheme.color),
: (widget.iconTheme?.iconUnselectedColor ??
theme.iconTheme.color),
),
), ),
), ),
), ),
); ),
}).toList(), );
); }).toList();
return widget.axis == Axis.horizontal
? Row(
mainAxisSize: MainAxisSize.min,
children: children,
)
: Column(
mainAxisSize: MainAxisSize.min,
children: children,
);
} }
void _didChangeEditingValue() { void _didChangeEditingValue() {

Loading…
Cancel
Save