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 width property to SnackBarThemeData #112636

Merged
merged 21 commits into from
Oct 5, 2022
Merged

Conversation

esouthren
Copy link
Contributor

Adds a width property to SnackBarThemeData, so it can be applied to all snackbar instances via the theme.

Issue: #111419

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Sep 29, 2022
@HansMuller
Copy link
Contributor

Is this the best way to control the snack bar's width? Should it be a percentage of the parent's width plus some padding? Or the width of the snack bar's contents plus some padding? Or min/maxWidth?

@esouthren
Copy link
Contributor Author

@HansMuller

Is this the best way to control the snack bar's width? Should it be a percentage of the parent's width plus some padding? Or the width of the snack bar's contents plus some padding? Or min/maxWidth?

Good questions - there's a couple of things we could do here. The current behaviour is that the snackbar is full width of the parent, minus a little padding. You can override the width to a manual amount, but only on a per-widget basis, not via the theme.

Options to solve the issue in #111419 are -

  • Add a minimumFit theme property that shrinks the snackbar.

    • An optional bool that sets the width to contain the content only.
    • This is feasible but would mean inconsistency for users who want a consistent snackbar width. There may of course be users who would desire the shrink-to-fit property.
  • Add a width property to the theme

    • The solution here; it allows users to set a consistent fixed width via the theme.

I don't have strong feelings either way, but option b) seems closer to the current functionality of the SnackBar (choice of no width, or fixed width) and simply adds the property to theme data. You have more insight here - is there an approach here that is more consistent with other widgets?

@esouthren esouthren marked this pull request as ready for review October 5, 2022 10:00
Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

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

  _    ___ _____ __  __ 
 | |  / __|_   _|  \/  |
 | |_| (_ | | | | |\/| |
 |____\___| |_| |_|  |_|
                        

/// Default value for [SnackBar.width].
///
/// If this property is null, then the snack bar will take up the full device
/// width less the margin. This value is only used when behavior is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// width less the margin. This value is only used when behavior is
/// width less the margin. This value is only used when [behavior] is

@esouthren esouthren merged commit 4862a84 into flutter:master Oct 5, 2022
@esouthren esouthren deleted the snackbar branch October 5, 2022 11:21
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Oct 5, 2022
@esouthren esouthren linked an issue Oct 5, 2022 that may be closed by this pull request
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Oct 5, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Snackbar width property to SnackbarThemeData
3 participants