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 icon support to push buttons (#522) #526

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

skythomp16
Copy link

@skythomp16 skythomp16 commented Oct 30, 2024

This PR adds support for adding an icon to a push button. This approach allows passing in an iconData instead of an icon so that we can control the size of the icon proportional to the button size. I have also updated the buttons_page.dart class for the example to include both primary and secondary buttons with icons. Comparing against a fresh SwiftUI project side by side, these look identical to those produced by it.

Pre-launch Checklist

  • I have incremented the package version as appropriate and updated CHANGELOG.md with my changes
  • I have added/updated relevant documentation
  • I have run "optimize/organize imports" on all changed files
  • I have addressed all analyzer warnings as best I could

@skythomp16
Copy link
Author

I checked the box about updating documentation but I am just assuming that will get updated because of my comments in the push_button.dart class but is that true? If not, I need to update that an iconData can be passed.

@GroovinChip
Copy link
Collaborator

I checked the box about updating documentation but I am just assuming that will get updated because of my comments in the push_button.dart class but is that true? If not, I need to update that an iconData can be passed.

Your assumption is correct.

Would you mind providing a screenshot of what the buttons look like, please?

@skythomp16
Copy link
Author

Sure, here is a screenshot of the modified example next to a blank canvas in swiftui with a push button with an icon for comparison.
Screenshot 2024-11-01 at 3 02 04 PM

@skythomp16
Copy link
Author

skythomp16 commented Nov 2, 2024

I pushed an update to fix the tests that were failing. Apologies - I didn't know that I could run 'flutter test' to run all of the tests - I will do that from now on. I am a little new to Flutter and Dart

@GroovinChip
Copy link
Collaborator

Do the SwiftUI versions of these buttons have this extra space on the left of the icon, for mini and small control sizes? I think it looks kind of lopsided.
image

@skythomp16
Copy link
Author

I think you're right. I pushed a change to allow us to control that padding. Here is a screenshot of what it looks like now:
Screenshot 2024-11-03 at 4 48 09 PM

@skythomp16
Copy link
Author

It looks like the dart-code-metrics failing isn't due to anything in my PR

@GroovinChip
Copy link
Collaborator

Yes, that check needs to be removed

Comment on lines +234 to +235
/// An optional iconData that can be added to a button.
/// This is an iconData instead of icon so we can control the size
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An optional iconData that can be added to a button.
/// This is an iconData instead of icon so we can control the size
/// An optional `IconData` that can be added to a button.
///
/// This is an `IconData` instead of an `Icon` so that the icon's size can be controlled internally.

child: Row(
children: [
widget.iconData != null
? Padding(padding: widget.controlSize.iconPadding,)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? Padding(padding: widget.controlSize.iconPadding,)
? Padding(padding: widget.controlSize.iconPadding)

widget.iconData != null
? Padding(padding: widget.controlSize.iconPadding,)
: const SizedBox.shrink(),
widget.iconData != null ? Icon(widget.iconData,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this Icon to a MacosIcon

Comment on lines +403 to +418
widget.iconData != null ? Icon(widget.iconData,
size: widget.controlSize.iconSize,
color: Colors.white) : const SizedBox.shrink(),
Padding(
padding: widget.controlSize.padding,
child: Align(
alignment: widget.alignment,
widthFactor: 1.0,
heightFactor: 1.0,
child: Row(children: [
DefaultTextStyle(
style: widget.controlSize.textStyle(
baseStyle),
child: widget.child,
),
],)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run dart formaton this file

@GroovinChip GroovinChip linked an issue Nov 7, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Push Buttons with Icons
2 participants