Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add example to SafeArea docs #157228

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

Merged
merged 4 commits into from
Oct 24, 2024
Merged

Conversation

loic-sharma
Copy link
Member

No description provided.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 19, 2024
Copy link
Contributor

@nate-thegrate nate-thegrate left a comment

Choose a reason for hiding this comment

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

Requesting changes (sadly not a joke this time).

Based on my own past experience, SafeArea can be kinda difficult to fully wrap your head around, so I think it'd be nice to have a fleshed-out DartPad sample for this.
Maybe it could have custom MediaQueryData so you can see how stuff interacts inside the browser!

Interested to hear your thoughts on this.

@@ -25,6 +25,23 @@ import 'media_query.dart';
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=lkF0TQJO0bA}
Copy link
Contributor

Choose a reason for hiding this comment

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

This "widget of the week" video gives a really nice overview, but in my mind there are some unanswered questions:

  • Is it good to give a safe area for both a scaffold's appBar and its body?
  • What about when a screen is built without using a Scaffold?
    (e.g. if a widget only covers the bottom half of the screen, do we need to set top: false or will Flutter automatically take care of it?)

Copy link
Member Author

Choose a reason for hiding this comment

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

@QuncCccccc do you know the answer to these questions & what the best practices are for Material and SafeArea?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it good to give a safe area for both a scaffold's appBar and its body?

If we have a Scaffold and have body only (without an app bar or bottom navigation bar), it's good to have a safe area to avoid intrusions, see doc here. If we have Scaffold.appBar, the safe area is taken care of by it, so we don't need to worry about the top of body, but if we want the bottom/left/right of the body to be inside of safe area, we should use SafeArea.

What about when a screen is built without using a Scaffold?
(e.g. if a widget only covers the bottom half of the screen, do we need to set top: false or will Flutter automatically take care of it?)

Sorry I'm mot super clear about the answer here. But for the example question, yes, we want to set top: false even if the widget only covers half the screen.

Please let me know if there's any questions or anything doesn't make sense:)!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it'd be nice to have a fleshed-out DartPad sample for this.

If the DartPad is only running on web, I just feel SafeArea is not that useful, so probably just providing a simple code snippet is a good way to show:) Just feel SafeArea is typically useful on mobile devices, like the "notch". But I'm open with other opinions:)

Copy link
Contributor

@nate-thegrate nate-thegrate Oct 23, 2024

Choose a reason for hiding this comment

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

Thanks very much for answering my questions!

If we have Scaffold.appBar, the safe area is taken care of by it, so we don't need to worry about the top of body

That's great to hear!

Copy link
Contributor

Choose a reason for hiding this comment

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

Just feel SafeArea is typically useful on mobile devices, like the "notch".

100% agree; setting a SafeArea is pretty useless on web.
However: I think we can still demo this by making our own "notch" with custom MediaQueryData :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I went ahead and made a DartPad sample since I thought it'd be fun. Let me know what you think!

I think the example is very interesting and great to have as a DartPad sample🤩! I'm thinking whether it makes sense to have both since the code snippet is very straightforward and easy to understand.

Copy link
Contributor

Choose a reason for hiding this comment

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

the code snippet is very straightforward and easy to understand.

True that, I put waay too much effort into "optimizing rebuilds" just for a demo file 😅


I've found that ~20 seconds of messing around with an interactive sample is much better at building the right intuition than ~2 minutes of reading through paragraphs of documentation.

I definitely agree that including both the snippet and the DartPad sample is something worth considering, since the snippet is indeed very simple & straightforward 👍

@loic-sharma loic-sharma marked this pull request as draft October 21, 2024 19:58
Copy link
Contributor

@QuncCccccc QuncCccccc left a comment

Choose a reason for hiding this comment

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

LGTM:)

Copy link
Contributor

@nate-thegrate nate-thegrate left a comment

Choose a reason for hiding this comment

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

Sorry for continuing to drag this out, but I still feel pretty strongly that it'd be great to have an interactive example app here.

I went ahead and made a DartPad sample since I thought it'd be fun. Let me know what you think!

@@ -25,6 +25,23 @@ import 'media_query.dart';
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=lkF0TQJO0bA}
Copy link
Contributor

@nate-thegrate nate-thegrate Oct 23, 2024

Choose a reason for hiding this comment

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

Thanks very much for answering my questions!

If we have Scaffold.appBar, the safe area is taken care of by it, so we don't need to worry about the top of body

That's great to hear!

@@ -25,6 +25,23 @@ import 'media_query.dart';
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=lkF0TQJO0bA}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just feel SafeArea is typically useful on mobile devices, like the "notch".

100% agree; setting a SafeArea is pretty useless on web.
However: I think we can still demo this by making our own "notch" with custom MediaQueryData :)

Copy link
Contributor

@nate-thegrate nate-thegrate left a comment

Choose a reason for hiding this comment

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

I think it's been a productive discussion!

I'd be happy with landing this change now, since this is a significant improvement over what the docs looked like previously.

(then I could take credit for the sample app in a separate PR 😏)

Comment on lines -39 to -40
/// The [left], [top], [right], [bottom], and [minimum] arguments must not be
/// null.
Copy link
Contributor

Choose a reason for hiding this comment

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

Great catch—this looks like something left over from pre-null safety days!

Comment on lines -33 to +57
/// * [MediaQuery], from which the window padding is obtained.
/// * [MediaQuery], from which the view padding is obtained.
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yeah that's right—the window getter is deprecated, good catch!

@loic-sharma loic-sharma marked this pull request as ready for review October 24, 2024 16:31
@loic-sharma
Copy link
Member Author

I went ahead and made a DartPad sample since I thought it'd be fun. Let me know what you think!

This sample is awesome. I would consider adding this in the examples/ directory with tests, or, embedding this interactive example in the relevant adaptive & responsive design docs (you can find prior art or embedding DartPad on the docs website here).

then I could take credit for the sample app in a separate PR 😏

That sounds good! :)

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 24, 2024
@auto-submit auto-submit bot merged commit fe95b2e into flutter:master Oct 24, 2024
67 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 24, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Oct 26, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Oct 26, 2024
Roll Flutter from 4faa4a415ec9 to 5a11904383d1 (67 revisions)

flutter/flutter@4faa4a4...5a11904

2024-10-26 [email protected] Relands "Wide gamut framework gradient test (#153976)" (flutter/flutter#157643)
2024-10-26 [email protected] Roll Flutter Engine from 7c5c5fe5c84d to c9b8ac96f6ce (3 revisions) (flutter/flutter#157662)
2024-10-26 [email protected] Add test for `navigator_state.restorable_push_and_remove_until.0.dart` (flutter/flutter#157595)
2024-10-26 [email protected] Tighten up `throwToolExit`, explain when to use it. (flutter/flutter#157561)
2024-10-26 [email protected] Remove extraneous `throw`. (flutter/flutter#157658)
2024-10-26 [email protected] Add tests for `navigator.restorable_push.0.dart` (flutter/flutter#157492)
2024-10-25 [email protected] Roll Flutter Engine from 43e4d9a30666 to 7c5c5fe5c84d (1 revision) (flutter/flutter#157644)
2024-10-25 [email protected] Roll Flutter Engine from 5061358e255f to 43e4d9a30666 (1 revision) (flutter/flutter#157637)
2024-10-25 [email protected] Roll Flutter Engine from eb867e055790 to 5061358e255f (2 revisions) (flutter/flutter#157623)
2024-10-25 [email protected] Create flutter specific leak troubleshooting guidance. (flutter/flutter#157396)
2024-10-25 [email protected] Update CupertinoNavigationBar to support large layout (flutter/flutter#157133)
2024-10-25 [email protected] Roll Flutter Engine from 38e9be1f74fa to eb867e055790 (3 revisions) (flutter/flutter#157613)
2024-10-25 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Wide gamut framework gradient test (#153976)" (flutter/flutter#157615)
2024-10-25 [email protected] Wide gamut framework gradient test (flutter/flutter#153976)
2024-10-25 [email protected] Roll Flutter Engine from b413d9996c86 to 38e9be1f74fa (2 revisions) (flutter/flutter#157604)
2024-10-25 [email protected] Roll Packages from a556f0f to e0c4f55 (2 revisions) (flutter/flutter#157605)
2024-10-25 [email protected] Support backdrop key in flutter framework. (flutter/flutter#157278)
2024-10-25 [email protected] Add 3.24.4 changelog to master (flutter/flutter#157600)
2024-10-25 [email protected] Update flutter.groovy to catch unknown task exception when finding api task (flutter/flutter#157282)
2024-10-25 [email protected] Roll Flutter Engine from c4b0184c8783 to b413d9996c86 (1 revision) (flutter/flutter#157580)
2024-10-25 [email protected] Roll Flutter Engine from b1c2ba8c4d52 to c4b0184c8783 (1 revision) (flutter/flutter#157578)
2024-10-25 [email protected] Add test for `build_owner.0.dart` (flutter/flutter#157499)
2024-10-25 [email protected] Add tests  for `focusable_action_detector.0.dart` (flutter/flutter#157575)
2024-10-25 [email protected] Add test for `navigator.restorable_push_and_remove_until.0.dart` (flutter/flutter#157487)
2024-10-25 [email protected] Roll Flutter Engine from 29440ed1e225 to b1c2ba8c4d52 (1 revision) (flutter/flutter#157572)
2024-10-25 [email protected] Roll Flutter Engine from 88716d804aef to 29440ed1e225 (1 revision) (flutter/flutter#157569)
2024-10-25 [email protected] Roll Flutter Engine from b8b28c80a737 to 88716d804aef (2 revisions) (flutter/flutter#157567)
2024-10-24 [email protected] Roll Flutter Engine from 48ff670d256b to b8b28c80a737 (2 revisions) (flutter/flutter#157564)
2024-10-24 [email protected] Use discenrable characters (replace `' ð��� ð��� '` in error logs) (flutter/flutter#157548)
2024-10-24 [email protected] Remove unused `PubDependenciesProjectValidator`. (flutter/flutter#157516)
2024-10-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Upgrade tests to AGP 8.7/Gradle 8.10.2/Kotlin 1.8.10 (#157032)" (flutter/flutter#157559)
2024-10-24 [email protected] Mark mac impeller as bringup. (flutter/flutter#157551)
2024-10-24 [email protected] Deprecate `ThemeData.dialogBackgroundColor` in favor of `DialogThemeData.backgroundColor` (flutter/flutter#155072)
2024-10-24 [email protected] Upgrade tests to AGP 8.7/Gradle 8.10.2/Kotlin 1.8.10 (flutter/flutter#157032)
2024-10-24 [email protected] Roll Flutter Engine from 246344f26edc to 48ff670d256b (2 revisions) (flutter/flutter#157544)
2024-10-24 [email protected] Allow opting out of `.flutter-plugins`, opt-out in `refreshPluginsList`. (flutter/flutter#157527)
2024-10-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reverts "Added a warning if `flutter.groovy` uses a `.flutter-plugins` file. (#157388)" (#157541)" (flutter/flutter#157549)
2024-10-24 [email protected] Changes the offset computation to first item for RenderSliverMainAxisGroup (flutter/flutter#154688)
2024-10-24 [email protected] Roll Packages from 5e03bb1 to a556f0f (7 revisions) (flutter/flutter#157539)
2024-10-24 [email protected] Add partial test for flutter build ios-framework on non-module (flutter/flutter#157482)
2024-10-24 [email protected] Add example to SafeArea docs (flutter/flutter#157228)
2024-10-24 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Added a warning if `flutter.groovy` uses a `.flutter-plugins` file. (#157388)" (flutter/flutter#157541)
2024-10-24 [email protected] Added a warning if `flutter.groovy` uses a `.flutter-plugins` file. (flutter/flutter#157388)
2024-10-24 [email protected] Roll Flutter Engine from be56084344d1 to 246344f26edc (2 revisions) (flutter/flutter#157504)
2024-10-24 [email protected] Add ability to disable CupertinoSegmentedControl (flutter/flutter#152813)
2024-10-24 [email protected] Update `Tab.height` parameter doc for tab height lower than default (flutter/flutter#157443)
...
@loic-sharma loic-sharma deleted the safearea_docs branch October 28, 2024 17:54
auto-submit bot pushed a commit that referenced this pull request Nov 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants