Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YaruExpandable: expand button position control #499

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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