Add `axis` parameter to `ArrowIndicatedButtonList`

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

@ -551,7 +551,10 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
width: axis == Axis.vertical ? 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(
axis: axis,
buttons: children,
),
), ),
); );
} }

@ -7,9 +7,13 @@ import 'package:flutter/material.dart';
/// The arrow indicators are automatically hidden if the list is not /// The arrow indicators are automatically hidden if the list is not
/// scrollable in the direction of the respective arrow. /// scrollable in the direction of the respective arrow.
class ArrowIndicatedButtonList extends StatefulWidget { class ArrowIndicatedButtonList extends StatefulWidget {
const ArrowIndicatedButtonList({required this.buttons, Key? key}) const ArrowIndicatedButtonList({
: super(key: key); required this.axis,
required this.buttons,
Key? key,
}) : super(key: key);
final Axis axis;
final List<Widget> buttons; final List<Widget> buttons;
@override @override
@ -20,8 +24,8 @@ class ArrowIndicatedButtonList extends StatefulWidget {
class _ArrowIndicatedButtonListState extends State<ArrowIndicatedButtonList> class _ArrowIndicatedButtonListState extends State<ArrowIndicatedButtonList>
with WidgetsBindingObserver { with WidgetsBindingObserver {
final ScrollController _controller = ScrollController(); final ScrollController _controller = ScrollController();
bool _showLeftArrow = false; bool _showBackwardArrow = false;
bool _showRightArrow = false; bool _showForwardArrow = false;
@override @override
void initState() { void initState() {
@ -40,13 +44,19 @@ class _ArrowIndicatedButtonListState extends State<ArrowIndicatedButtonList>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Row( final children = <Widget>[
children: <Widget>[ _buildBackwardArrow(),
_buildLeftArrow(), _buildScrollableList(),
_buildScrollableList(), _buildForwardArrow(),
_buildRightColor(), ];
],
); return widget.axis == Axis.horizontal
? Row(
children: children,
)
: Column(
children: children,
);
} }
@override @override
@ -63,20 +73,29 @@ class _ArrowIndicatedButtonListState extends State<ArrowIndicatedButtonList>
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
_showLeftArrow = _showBackwardArrow =
_controller.position.minScrollExtent != _controller.position.pixels; _controller.position.minScrollExtent != _controller.position.pixels;
_showRightArrow = _showForwardArrow =
_controller.position.maxScrollExtent != _controller.position.pixels; _controller.position.maxScrollExtent != _controller.position.pixels;
}); });
} }
Widget _buildLeftArrow() { Widget _buildBackwardArrow() {
IconData? icon;
if (_showBackwardArrow) {
if (widget.axis == Axis.horizontal) {
icon = Icons.arrow_left;
} else {
icon = Icons.arrow_drop_up;
}
}
return SizedBox( return SizedBox(
width: 8, width: 8,
child: Transform.translate( child: Transform.translate(
// Move the icon a few pixels to center it // Move the icon a few pixels to center it
offset: const Offset(-5, 0), offset: const Offset(-5, 0),
child: _showLeftArrow ? const Icon(Icons.arrow_left, size: 18) : null, child: icon != null ? Icon(icon, size: 18) : null,
), ),
); );
} }
@ -87,18 +106,24 @@ class _ArrowIndicatedButtonListState extends State<ArrowIndicatedButtonList>
// Remove the glowing effect, as we already have the arrow indicators // Remove the glowing effect, as we already have the arrow indicators
behavior: _NoGlowBehavior(), behavior: _NoGlowBehavior(),
// The CustomScrollView is necessary so that the children are not // The CustomScrollView is necessary so that the children are not
// stretched to the height of the toolbar, https://bit.ly/3uC3bjI // stretched to the height of the toolbar:
// https://stackoverflow.com/a/65998731/7091839
child: CustomScrollView( child: CustomScrollView(
scrollDirection: Axis.horizontal, scrollDirection: widget.axis,
controller: _controller, controller: _controller,
physics: const ClampingScrollPhysics(), physics: const ClampingScrollPhysics(),
slivers: [ slivers: [
SliverFillRemaining( SliverFillRemaining(
hasScrollBody: false, hasScrollBody: false,
child: Row( child: widget.axis == Axis.horizontal
mainAxisAlignment: MainAxisAlignment.spaceEvenly, ? Row(
children: widget.buttons, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
), children: widget.buttons,
)
: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: widget.buttons,
),
) )
], ],
), ),
@ -106,13 +131,22 @@ class _ArrowIndicatedButtonListState extends State<ArrowIndicatedButtonList>
); );
} }
Widget _buildRightColor() { Widget _buildForwardArrow() {
IconData? icon;
if (_showForwardArrow) {
if (widget.axis == Axis.horizontal) {
icon = Icons.arrow_right;
} else {
icon = Icons.arrow_drop_down;
}
}
return SizedBox( return SizedBox(
width: 8, width: 8,
child: Transform.translate( child: Transform.translate(
// Move the icon a few pixels to center it // Move the icon a few pixels to center it
offset: const Offset(-5, 0), offset: const Offset(-5, 0),
child: _showRightArrow ? const Icon(Icons.arrow_right, size: 18) : null, child: icon != null ? Icon(icon, size: 18) : null,
), ),
); );
} }

Loading…
Cancel
Save