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

unify YaruIconButton and YaruRoundToggleButton #264

Merged
merged 1 commit into from
Oct 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions example/lib/example_page_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'pages/carousel_page.dart';
import 'pages/color_disk_page.dart';
import 'pages/draggable_page.dart';
import 'pages/expandable_page.dart';
import 'pages/icon_button_page.dart';
import 'pages/option_button_page.dart';
import 'pages/progress_indicator_page.dart';
import 'pages/round_toggle_button_page.dart';
import 'pages/section_page.dart';
import 'pages/selectable_container_page.dart';
import 'pages/tabbed_page_page.dart';
Expand Down Expand Up @@ -54,6 +54,11 @@ final examplePageItems = <PageItem>[
iconBuilder: (context, selected) => const Icon(YaruIcons.pan_down),
pageBuilder: (_) => const ExpandablePage(),
),
PageItem(
titleBuilder: (context) => YaruPageItemTitle.text('YaruIconButton'),
iconBuilder: (context, selected) => const Icon(YaruIcons.app_grid),
pageBuilder: (_) => const IconButtonPage(),
),
PageItem(
titleBuilder: (context) => YaruPageItemTitle.text('YaruOptionButton'),
iconBuilder: (context, selected) => const Icon(YaruIcons.settings),
Expand All @@ -64,11 +69,6 @@ final examplePageItems = <PageItem>[
iconBuilder: (context, selected) => const Icon(YaruIcons.download),
pageBuilder: (_) => const ProgressIndicatorPage(),
),
PageItem(
titleBuilder: (context) => YaruPageItemTitle.text('YaruRoundToggleButton'),
pageBuilder: (context) => const RoundToggleButtonPage(),
iconBuilder: (context, selected) => const Icon(YaruIcons.app_grid),
),
PageItem(
titleBuilder: (context) => YaruPageItemTitle.text('YaruSection'),
iconBuilder: (context, selected) => const Icon(YaruIcons.window),
Expand Down
39 changes: 39 additions & 0 deletions example/lib/pages/icon_button_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

class IconButtonPage extends StatefulWidget {
const IconButtonPage({super.key});

@override
_IconButtonPageState createState() => _IconButtonPageState();
}

class _IconButtonPageState extends State<IconButtonPage> {
bool _selected = false;
@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(kYaruPagePadding),
children: [
Row(
children: [
YaruIconButton(
onPressed: () {},
icon: const Icon(YaruIcons.ubuntu_logo),
),
const SizedBox(width: 10),
YaruIconButton(
onPressed: () => setState(
() => _selected = !_selected,
),
isSelected: _selected,
icon: const Icon(YaruIcons.view),
tooltip: 'View',
),
],
),
],
);
}
}
32 changes: 0 additions & 32 deletions example/lib/pages/round_toggle_button_page.dart

This file was deleted.

120 changes: 98 additions & 22 deletions lib/src/controls/yaru_icon_button.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,104 @@
import 'package:flutter/material.dart';

/// An [IconButton] with a default fixed size of 40x40.
class YaruIconButton extends IconButton {
YaruIconButton({
class YaruIconButton extends StatelessWidget {
const YaruIconButton({
required this.icon,
this.alignment = Alignment.center,
this.autofocus = false,
this.constraints,
this.enableFeedback = true,
this.focusNode,
this.iconSize = 40.0,
this.isSelected,
this.mouseCursor,
this.onPressed,
this.padding = const EdgeInsets.all(8.0),
this.selectedIcon,
this.splashRadius,
this.style,
this.tooltip,
this.visualDensity,
super.key,
super.iconSize,
super.visualDensity,
super.padding = const EdgeInsets.all(8.0),
super.alignment = Alignment.center,
super.splashRadius,
required super.onPressed,
super.mouseCursor,
super.focusNode,
super.autofocus = false,
super.tooltip,
super.enableFeedback = true,
super.constraints,
ButtonStyle? style,
super.isSelected,
super.selectedIcon,
required super.icon,
}) : super(style: _kDefaultStyle.merge(style));
});

static final _kDefaultStyle = IconButton.styleFrom(
fixedSize: const Size.square(40),
);
final Alignment alignment;
final bool autofocus;
final BoxConstraints? constraints;
final bool enableFeedback;
final FocusNode? focusNode;
final Widget icon;
final double iconSize;
final bool? isSelected;
final MouseCursor? mouseCursor;
final VoidCallback? onPressed;
final EdgeInsets padding;
final Widget? selectedIcon;
final double? splashRadius;
final ButtonStyle? style;
final String? tooltip;
final VisualDensity? visualDensity;

ButtonStyle defaultStyleOf(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return ButtonStyle(
fixedSize: MaterialStateProperty.all(Size(iconSize, iconSize)),
foregroundColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return colors.primary;
}
return colors.onSurface.withOpacity(0.8);
}),
backgroundColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
return colors.onSurface.withOpacity(0.1);
}
return null;
}),
overlayColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.selected)) {
if (states.contains(MaterialState.hovered)) {
return colors.onSurface.withOpacity(0.08);
}
if (states.contains(MaterialState.focused)) {
return colors.onSurface.withOpacity(0.12);
}
if (states.contains(MaterialState.pressed)) {
return colors.onSurface.withOpacity(0.12);
}
}
if (states.contains(MaterialState.hovered)) {
return colors.onSurfaceVariant.withOpacity(0.08);
}
if (states.contains(MaterialState.focused)) {
return colors.onSurfaceVariant.withOpacity(0.08);
}
if (states.contains(MaterialState.pressed)) {
return colors.onSurfaceVariant.withOpacity(0.12);
}
return null;
}),
);
}

@override
Widget build(BuildContext context) {
return IconButton(
alignment: alignment,
autofocus: autofocus,
constraints: constraints,
enableFeedback: enableFeedback,
focusNode: focusNode,
icon: icon,
isSelected: isSelected,
mouseCursor: mouseCursor,
onPressed: onPressed,
padding: padding,
selectedIcon: selectedIcon,
splashRadius: splashRadius,
style: defaultStyleOf(context).merge(style),
tooltip: tooltip,
visualDensity: visualDensity,
);
}
}
53 changes: 0 additions & 53 deletions lib/src/controls/yaru_round_toggle_button.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/yaru_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export 'src/controls/yaru_color_disk.dart';
export 'src/controls/yaru_icon_button.dart';
export 'src/controls/yaru_option_button.dart';
export 'src/controls/yaru_progress_indicator.dart';
export 'src/controls/yaru_round_toggle_button.dart';
// Dialogs
export 'src/dialogs/yaru_alert_dialog.dart';
export 'src/dialogs/yaru_dialog_title.dart';
Expand Down