-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
API docs for Container.color should have a "troubleshooting" section that talks about "mysterious dividers" #15035
Comments
/cc @Hixie @HansMuller for their thoughts |
That's pretty strange: it's wrong but it looks sort-of attractive. Could you provide a small example that demos the problem? |
@Hixie suggests setting the background colour for the entire Drawer to the colour you're using for the list tiles. It's likely this is a result of sub-pixel anti-aliasing. |
@cbracken Yes, setting the background of the entire drawer "visually" fixes the issue, but there is still the issue. @HansMuller Doesn't matter if it looks better. I didn't write anything in the code that should display dividers, and that's why this is the issue. |
I was able to reproduce this bug with very simple example: var putThisIntoScaffoldBody = new ListView.builder(itemBuilder: (BuildContext context, int index) {
return new Container(
decoration: new BoxDecoration(color: Colors.black),
height: 30.0,
);
}, itemCount: 30,
); Just put this widget into Scaffold body. On iOS I can see it when bouncing with the scroll. On Android, it's much easier to see it, you don't even need to scroll: You can also see that not every divider is same width. |
Understood. That was just my attempt at humor. |
@itsJoKr Yeah, that most recent screenshot shows that this is indeed what we suspected. You're drawing a series of rectangles adjacent to each other, on top of a different background color, but they don't quite line up with the physical pixel boundaries. This means we try to antialias the edges, and each one is painted on top of the background, so the background shows up in the antialiasing. This is working as intended; it's how graphics works. There's two basic ways to avoid this problem. The first is to do as suggested above -- if you want two adjacent boxes to have the same background and be adjacent, then draw the background once, e.g. by putting them into a single box with that background. The second is to wrap all those widgets with a RepaintBoundary, which will cause them to all be painted as one graphic which is then anti-aliased once with the parent. That might not solve the issue, depending on exactly what the alignment ends up being, but it should be better. In general though the right answer is the first suggestion here; don't put two adjacent boxes with the same background color, just put the background color on the common background. We should document this somewhere with diagrams to explain it better. Not sure where, maybe on |
OK, I understand it now, thanks for the explanation. |
"In general though the right answer is the first suggestion here; don't put two adjacent boxes with the same background color, just put the background color on the common background." Is this always a viable solution? For example, I want my I've also fixed this by moving from a bottom padding of 5.0 to a SizedBox of 5.0 and it "Fixed" the problem, but felt a bit weird. The solution you propose sounds like creating a Would be cool if padding "Just Worked" for this use case |
My problem here is the line: "This is working as intended; it's how graphics works." Because I'm pretty sure I wouldn't see this issue in Android and iOS native. |
For a specific artistic layout I was having this "mystery thin divider" problems with, I wrote the following: class PixelRatioDivider {
double quantizedUnit;
double remainder;
PixelRatioDivider(BuildContext context, pixels, divideBy) {
final pixelRatio = MediaQuery.of(context).devicePixelRatio;
quantizedUnit = (pixels * pixelRatio ~/ divideBy) / pixelRatio;
remainder = pixels - (quantizedUnit * divideBy);
}
} Using whole multiples of the |
See also #17084 |
Closing this as dupe of #17084. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
I have ListView with simple rows that have one Text, and BoxDecoration with the background color. When in the middle of scrolling, I can see dividers between rows. Not exactly dividers, but I can see through the list (confirmed by setting different background color).
Tested on iOS simulator and Android device.
Flutter Doctor
That is the normal case. But when scrolling I get this:
The text was updated successfully, but these errors were encountered: