Skip to content

Commit

Permalink
YaruExpandable: expand button position control (#499)
Browse files Browse the repository at this point in the history
Fixes #493
  • Loading branch information
Jupi007 committed Jan 11, 2023
1 parent 72b3d4e commit 8819761
Showing 1 changed file with 44 additions and 17 deletions.
61 changes: 44 additions & 17 deletions lib/src/utilities/yaru_expandable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ import '../../yaru_widgets.dart';
const _kAnimationDuration = Duration(milliseconds: 250);
const _kAnimationCurve = Curves.easeInOutCubic;

enum YaruExpandableButtonPosition {
/// Align the button before the header widget
start,

/// Align the button at the opposite of the header widget
end,
}

class YaruExpandable extends StatefulWidget {
const YaruExpandable({
super.key,
required this.header,
this.expandIcon,
this.expandButtonPosition = YaruExpandableButtonPosition.end,
required this.child,
this.collapsedChild,
this.gapHeight = 4.0,
Expand All @@ -25,6 +34,9 @@ class YaruExpandable extends StatefulWidget {
/// A 25° rotation is used when expanded
final Widget? expandIcon;

/// Controls expand button position, see [YaruExpandableButtonPosition]
final YaruExpandableButtonPosition expandButtonPosition;

/// Widget show when expanded
final Widget child;

Expand Down Expand Up @@ -56,26 +68,41 @@ class _YaruExpandableState extends State<YaruExpandable> {

@override
Widget build(BuildContext context) {
final iconButton = YaruIconButton(
iconSize: 36,
padding: EdgeInsets.zero,
onPressed: _onTap,
icon: AnimatedRotation(
turns: _isExpanded ? .25 : 0,
duration: _kAnimationDuration,
curve: _kAnimationCurve,
child: widget.expandIcon ?? const Icon(YaruIcons.pan_end),
),
);

final header = Flexible(
child: GestureDetector(onTap: _onTap, child: widget.header),
);

final MainAxisAlignment expandButtonPosition;
final List<Widget> headerChildren;

switch (widget.expandButtonPosition) {
case YaruExpandableButtonPosition.start:
expandButtonPosition = MainAxisAlignment.start;
headerChildren = [iconButton, header];
break;
case YaruExpandableButtonPosition.end:
expandButtonPosition = MainAxisAlignment.spaceBetween;
headerChildren = [header, iconButton];
break;
}

return Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: GestureDetector(onTap: _onTap, child: widget.header),
),
YaruIconButton(
iconSize: 36,
padding: EdgeInsets.zero,
onPressed: _onTap,
icon: AnimatedRotation(
turns: _isExpanded ? .25 : 0,
duration: _kAnimationDuration,
curve: _kAnimationCurve,
child: widget.expandIcon ?? const Icon(YaruIcons.pan_end),
),
),
],
mainAxisAlignment: expandButtonPosition,
children: headerChildren,
),
AnimatedCrossFade(
firstChild: _buildChild(widget.child),
Expand Down

0 comments on commit 8819761

Please sign in to comment.