Skip to content

Commit

Permalink
Add YaruRoundIconButton and get rid of IconButtons (#146)
Browse files Browse the repository at this point in the history
* YaruRoundToggleButton: replace icon button

* RoundButtons: adapt to material 3

* Ger rid of icon buttons in yaru_widgets
  • Loading branch information
Feichtmeier committed Jun 11, 2022
1 parent 2773458 commit f27dc73
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 28 deletions.
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(100),
child: InkWell(
borderRadius: BorderRadius.circular(100),
onTap: onTap,
child: child,
),
),
),
);
}
}
29 changes: 13 additions & 16 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,7 +12,7 @@ class YaruRoundToggleButton extends StatelessWidget {
/// Optional onPressed callback to select the button
final Function()? onPressed;

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

const YaruRoundToggleButton({
Expand All @@ -24,22 +25,18 @@ class YaruRoundToggleButton extends StatelessWidget {

@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

0 comments on commit f27dc73

Please sign in to comment.