Add `axis` parameter to `QuillToolbar`

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

@ -43,9 +43,12 @@ const double kDefaultIconSize = 18;
const double kIconButtonFactor = 1.77; const double kIconButtonFactor = 1.77;
class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
const QuillToolbar({ QuillToolbar({
required this.children, required this.children,
this.toolbarHeight = 36, this.axis = Axis.horizontal,
@Deprecated('Use toolbarSize instead')
double? toolbarHeight,
double? toolbarSize,
this.toolbarIconAlignment = WrapAlignment.center, this.toolbarIconAlignment = WrapAlignment.center,
this.toolbarSectionSpacing = 4, this.toolbarSectionSpacing = 4,
this.multiRowsDisplay = true, this.multiRowsDisplay = true,
@ -54,7 +57,9 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
this.locale, this.locale,
VoidCallback? afterButtonPressed, VoidCallback? afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key) {
this.toolbarSize = toolbarSize ?? toolbarHeight ?? 36;
}
factory QuillToolbar.basic({ factory QuillToolbar.basic({
required QuillController controller, required QuillController controller,
@ -171,7 +176,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
return QuillToolbar( return QuillToolbar(
key: key, key: key,
color: color, color: color,
toolbarHeight: toolbarIconSize * 2, toolbarSize: toolbarIconSize * 2,
toolbarSectionSpacing: toolbarSectionSpacing, toolbarSectionSpacing: toolbarSectionSpacing,
toolbarIconAlignment: toolbarIconAlignment, toolbarIconAlignment: toolbarIconAlignment,
multiRowsDisplay: multiRowsDisplay, multiRowsDisplay: multiRowsDisplay,
@ -504,7 +509,8 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
} }
final List<Widget> children; final List<Widget> children;
final double toolbarHeight; final Axis axis;
late final double toolbarSize;
final double toolbarSectionSpacing; final double toolbarSectionSpacing;
final WrapAlignment toolbarIconAlignment; final WrapAlignment toolbarIconAlignment;
final bool multiRowsDisplay; final bool multiRowsDisplay;
@ -523,7 +529,9 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
final List<QuillCustomButton> customButtons; final List<QuillCustomButton> customButtons;
@override @override
Size get preferredSize => Size.fromHeight(toolbarHeight); Size get preferredSize => axis == Axis.horizontal
? Size.fromHeight(toolbarSize)
: Size.fromWidth(toolbarSize);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -531,14 +539,17 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
initialLocale: locale, initialLocale: locale,
child: multiRowsDisplay child: multiRowsDisplay
? Wrap( ? Wrap(
direction: axis,
alignment: toolbarIconAlignment, alignment: toolbarIconAlignment,
runSpacing: 4, runSpacing: 4,
spacing: toolbarSectionSpacing, spacing: toolbarSectionSpacing,
children: children, children: children,
) )
: Container( : Container(
constraints: constraints: BoxConstraints.tightFor(
BoxConstraints.tightFor(height: preferredSize.height), height: axis == Axis.horizontal ? toolbarSize : null,
width: axis == Axis.vertical ? toolbarSize : null,
),
color: color ?? Theme.of(context).canvasColor, color: color ?? Theme.of(context).canvasColor,
child: ArrowIndicatedButtonList(buttons: children), child: ArrowIndicatedButtonList(buttons: children),
), ),

Loading…
Cancel
Save