Closed aliasgar4558 closed 6 days ago
Closed by mistake, re-opened the PR.
When I run it locally, with you additional Expanded
, the navigation_rail_test
throws tons of errors for multiple tests. And even after I revert your changes (removing the Expanded
), your test throws the following assertion:
'package:flutter/src/material/navigation_rail.dart': Failed assertion: line 121 pos 16: '!extended
|| (labelType == null || labelType == NavigationRailLabelType.none)': is not true.
Yet somehow all checks have passed. Have you run it locally? I don't know what's happening.
@dkwingsmt - What are the configuration that I need to make to run the tests additionally, as when I tried to run the test, it didn't allowed me to execute.
What do you mean it doesn't allow you to execute? To run the test you cd
into packages/flutter
then run
flutter test test/material/navigation_rail_test.dart
Sure, will check and update here accordingly
@dkwingsmt - is 'dev' channel fine to work on this one? Or shall I verify on master or some other environment?
Any branch should be OK, since the navigation rail hasn't been changed for a while.
I tried with stable channel, but it shows several compile time errors which are related to conflicts into pubspec versions, so thats the purpose of asking if I can try with dev or master instead. Mind me asking, what env did you used to verify the changes?
I'm using the main channel. Can you try with that?
Yeah sure, Allow me some time. Will check out in main
channel
@dkwingsmt - Do we have to make any changes in pubspec in flutter/packages/flutter' folder, as I am unable to execute
pub get` there.?
@dkwingsmt - You are right, 18 tests are breaking. However, I found one issue with my test, so will update that and commit into this PR.
I don't feel like I shall change any other tests as it might result into something else to break. Please suggest your thoughts!
@dkwingsmt - Please check if you can verify now, as I am not getting any test breaks.
Root cause : Expanded
widget was the one causing issue as the widget is not bounded by parent.
Remedy : Replaced with Flexible
All tests now passes, but after I revert your changes (removing the Flexible
wrap) your test still passes. Can you check it out?
@dkwingsmt - sure, I will add more fine grain test which checks for "Flexible" with the longer texts.
The idea is that the unit test you add should fail before your change and pass after your change, so that it prevents your change from being reverted in the future. One unit test is enough as long as it's on the point.
@dkwingsmt - Yes I agree. Sure thing, will update the test so in future if something changes, it can be indicated. Thanks for the insights.
@dkwingsmt - Please have a check and let me know anything else we can add to make it better.
Your test checks if the text can be found within a Flexible
. It's not testing the feature, but the implementation. What you really care is that no overflow is reported, instead of whether it's implemented via Flexible
or any other widgets.
And in fact, your implementation does not solve the problem. Here's what I got from running your fix (which is the same as the current main branch):
How to test it:
examples/api/lib/material/navigation_rail/navigation_rail.1.dart
destinations: const <NavigationRailDestination>[
NavigationRailDestination(
icon: Icon(Icons.favorite_border),
selectedIcon: Icon(Icons.favorite),
label: Text('LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong'),
),
flutter run ~/dev/flutter/examples/api/lib/material/navigation_rail/navigation_rail.1.dart -d chrome
@dkwingsmt - I think problem is with how navigation rail is used in UI. It might require width constraints in normal case scenario also. Suggest your insights please!
When I revert this change, then also it is causing issue. Please do have a check and suggest!
When I revert this change, then also it is causing issue.
That's what I'm saying: this is the issue, and your current change sadly isn't fixing the problem.
Or did I misunderstand something? Can you demonstrate with an app what your change is fixing?
yes @dkwingsmt - There are 2 issues basically here. First, what I fixed - that is when long text added, it shall not overflow (wrapped in flexible) & second is NavigationRail
without max width constraints is over flowing when size is compressed (what you have faced - in your case, if you wrap navigation rail with SizedBox
& give width, then it will not overflow)
for first point, I have made the fix & it will work when navigation rail is available with max width constraint but the second thing that you faced, for that we need to take a change. [We can raise a bug for that for "NavigationRail"]
For 2nd point - I think we can introduce "maxWidth" parameter in NavigationRail
which will help to constraint its width. [New change]
Allow me some time, I will send the code snippet here - which will demonstrate my fix with an example for you.
@dkwingsmt any update on this one mate?
@dkwingsmt any update on this one mate?
Hi! I'm still waiting for the snippet you mentioned. Can you demonstrate the scenario that this PR fixes? Such as some comparison screenshots would be even better.
@dkwingsmt Ohh, Okay sure. I will be sending that across. Thank you
This is the problem you faced when you shrink the screen size very small.
But the problem is not with the fix that I made, it is because of "NavigationRail"'s width is not constraint & the other view is crashing/overflowing.
Example screenshot when NavigationRail
's width is given :
-- So from above screenshots, it seems like NavigationRail
shall be provided with width constraints in consumer applications so other views can be rendered correctly.
@dkwingsmt - Please have a check on this one & you can try the same thing out & let me know if anything.
(I referred to navigation_rail.1.dart
file for demo purpose)
(Sorry I missed your PR last week) Thanks for your screenshot comparison, which are super clear about what was fixed.
Now, my problem with your unit test is that, it tests an implementation detail ("the text must be wrapped within a Flexible
widget") instead of the behavior ("the text must wrap / the max-line must be triggered"). The widget might be refactored in the future with same functionality implemented differently, and you want your test to still be valid. My suggestion is that your test can check the height of the widget in this setup and ensure it's below some number that wasn't possible before the PR, which I think is one of the most observable difference.
Not a problem for the delay. Thanks for the valuable insights.
However, I didn't got your point to check what widget's height while in test. Can you please let me know more details on it ?
@dkwingsmt - Updated test case to check Text
widget's height value & compared with the other smaller destination's height (which is a normal one - which can be adjusted in a single line). Hope this is what you are expecting.
I ran the widget in your test individually but the result is not the desired one as you demonstrated.
Before PR: (with exception)
After PR:
Although they're indeed different, they do not demonstrate the ellipsis fix that you showed earlier.
I found out that it was because you missed the "ellipsis" setting for Text
in your test. With the "ellipsis",
Before PR: (with exception)
After PR:
Anyway, since with either cases the before-PR version throws a layout exception, I think we can omit checking anything here.
@dkwingsmt - Yes, ellipsis was intentionally not added in tests to demonstrate that text would be wrapped if navigation rail has a width constraint, so it can be determined that Flexible
is making some difference.
So, Do you suggest we can exclude the test cases for this fix?
I've applied the changes you suggested. @dkwingsmt - Thank you for the valuable insights
@aliasgar4558 Sorry for the burden, you will have to rebase this PR on the master
branch (you can close this one and file a new one if it is easier for you), main
branch can not be targeted for PRs on flutter/flutter (the bots won't work with it).
FYI, for the other Flutter repos, main branch is ok, especially for flutter/engine
but this is not the case for flutter/flutter.
@bleroux - Thanks for the suggestions. It seems good to have those in the PR so will add that.
Also, Just to confirm - instead of main
branch, we have to target this PR to master
branch. Is that correct?
Also, Just to confirm - instead of
main
branch, we have to target this PR tomaster
branch. Is that correct?
Yes, this is required in flutter/flutter. Sorry for the burden.
@bleroux - Not problem at all. I am here to learn and contribute & you guys are helping me. So all good. Will do the needful and update PR.
@bleroux - I have updated test as per your suggested changes & now PR is targeting to master
branch. Please review once you get some time.
@dkwingsmt @bleroux - Thank you so much for your valuable insights for this PR. Really Appreciate it ๐
Thank YOU for the contribution, and continuously addressing our comments!
It has been observed that while in extended navigation rail, if longer labels are given the it is overflowing. Problem identified in "NavigationRail" widget only in case of extended version of it. This PR includes the fix for the same.
Fixes https://github.com/flutter/flutter/issues/110901.
NO breaking changes.
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on [Discord].