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

Add YaruRoundIconButton and get rid of IconButtons #146

Merged
merged 3 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
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
19 changes: 11 additions & 8 deletions lib/src/yaru_expandable.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

const _kAnimationDuration = Duration(milliseconds: 250);
const _kAnimationCurve = Curves.easeInOutCubic;
Expand Down Expand Up @@ -53,14 +54,16 @@ class _YaruExpandableState extends State<YaruExpandable> {
GestureDetector(
onTap: () => setState(() => _isExpanded = !_isExpanded),
child: widget.header),
IconButton(
splashRadius: 20,
onPressed: () => setState(() => _isExpanded = !_isExpanded),
icon: AnimatedRotation(
turns: _isExpanded ? .25 : 0,
duration: _kAnimationDuration,
curve: _kAnimationCurve,
child: widget.expandIcon ?? const Icon(Icons.arrow_right))),
YaruRoundIconButton(
size: 32,
onTap: () => setState(() => _isExpanded = !_isExpanded),
child: AnimatedRotation(
turns: _isExpanded ? .25 : 0,
duration: _kAnimationDuration,
curve: _kAnimationCurve,
child: widget.expandIcon ?? const Icon(Icons.arrow_right),
),
),
],
),
AnimatedCrossFade(
Expand Down
46 changes: 46 additions & 0 deletions lib/src/yaru_round_icon_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';

class YaruRoundIconButton extends StatelessWidget {
const YaruRoundIconButton({
super.key,
this.backgroundColor,
this.onTap,
this.tooltip,
required this.child,
this.size = 40,
});

/// The [Color] used for the round background.
final Color? backgroundColor;

/// Optional onTap callback to select the button
final Function()? onTap;

/// String shown in the [Tooltip]
final String? tooltip;

///
final Widget child;

final double size;

@override
Widget build(BuildContext context) {
return Tooltip(
message: tooltip ?? '',
child: SizedBox(
height: size,
width: size,
child: Material(
color: backgroundColor,
borderRadius: BorderRadius.circular(size / 2),
child: InkWell(
borderRadius: BorderRadius.circular(size / 2),
onTap: onTap,
child: child,
),
),
),
);
}
}
31 changes: 14 additions & 17 deletions lib/src/yaru_round_toggle_button.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:yaru_widgets/src/yaru_round_icon_button.dart';

/// A selectable [IconButton], wrapped in a [CircleAvatar]
class YaruRoundToggleButton extends StatelessWidget {
Expand All @@ -11,35 +12,31 @@ class YaruRoundToggleButton extends StatelessWidget {
/// Optional onPressed callback to select the button
final Function()? onPressed;

/// Optional tooltip
/// Tooltip
final String? tooltip;

const YaruRoundToggleButton({
Key? key,
required this.selected,
required this.iconData,
this.onPressed,
this.tooltip,
required this.tooltip,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return CircleAvatar(
backgroundColor: selected
? Theme.of(context).colorScheme.onSurface.withOpacity(0.05)
: Colors.transparent,
child: IconButton(
tooltip: tooltip,
color: selected ? Colors.grey : null,
splashRadius: 20,
onPressed: onPressed,
icon: Icon(
iconData,
color: selected
? Theme.of(context).primaryColor
: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
return YaruRoundIconButton(
onTap: onPressed,
tooltip: tooltip,
child: Icon(
iconData,
color: selected
? Theme.of(context).primaryColor
: Theme.of(context).colorScheme.onSurface.withOpacity(0.8),
),
backgroundColor: selected
? Theme.of(context).colorScheme.onSurface.withOpacity(0.1)
: null,
);
}
}
8 changes: 4 additions & 4 deletions lib/src/yaru_search_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

/// Creates a search bar inside an [AppBar].
///
Expand Down Expand Up @@ -101,10 +102,9 @@ class YaruSearchAppBar extends StatelessWidget implements PreferredSizeWidget {
BoxConstraints.expand(width: 48, height: appBarHeight),
suffixIcon: Padding(
padding: const EdgeInsets.only(right: 6, bottom: 3),
child: IconButton(
splashRadius: appBarHeight / 3,
onPressed: onEscape,
icon: Icon(
child: YaruRoundIconButton(
onTap: onEscape,
child: Icon(
clearSearchIconData ?? Icons.close,
color: textColor,
),
Expand Down
1 change: 1 addition & 0 deletions lib/yaru_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export 'src/yaru_narrow_layout.dart';
export 'src/yaru_option_button.dart';
export 'src/yaru_page.dart';
export 'src/yaru_page_item.dart';
export 'src/yaru_round_icon_button.dart';
export 'src/yaru_round_toggle_button.dart';
export 'src/yaru_row.dart';
export 'src/yaru_search_app_bar.dart';
Expand Down