Profile cover photo
Profile photo
Filip Hráček
7,863 followers -
Google employee in the Dart team; gamebooks and pancakes enthusiast
Google employee in the Dart team; gamebooks and pancakes enthusiast

7,863 followers
About
Posts

Post has attachment
Add a comment...

Post has attachment
Oh look, I interviewed Tim Sneath at #DartConf. I'm especially proud of my acting at 1:24 and 1:56.
Add a comment...

Post has attachment
První ryze česká Flutter aplikace (o které vím) je na Play Store.
Add a comment...

Post has attachment
I used a genetic algorithm to schedule a developer conference (DartConf 2018). Here's how it went.
Add a comment...

Post has attachment
Stát Kalifornie legalizoval prodej marihuany pro rekreační účely. Už existují služby typu DámeJídlo, jednou z nich je eaze.com
Photo
Add a comment...

Post has shared content
In Flutter, we occasionally get the question "how do you set a negative margin?". This usually comes after people find the Container widget's "margin" property, try to set it to a negative value, and find that it asserts with a message saying padding must be positive. It turns out that Container's idea of margin and padding is actually just to put a Padding widget on the outside of its DecoratedBox for the margin, and a Padding widget on the inside for the padding. Many complicated-looking widgets in Flutter tends to decompose in this way.

So how would you get a negative-margin-like effect in Flutter?

To answer this question you first have to define what "negative margins", or really "margins" in general, really are. In CSS, margins have various meanings in the various layout models, most commonly, they are one of several values that contribute to computing the offset that the block layout model uses to place subsequent children; a negative total margin in this case merely means the next child is placed above the bottom of the previous child instead of after it.

In Flutter, as in CSS, there are several layout models; however, there is currently no widget that is equivalent to the CSS block layout model (which supports margin collapsing, negative margins, skipping floats, etc). Such a layout model could certainly be implemented, it just hasn't been implemented yet, at least not in the framework itself.

To implement such a layout model, you would create a RenderBox descendant similar to RenderFlex or RenderListBody, probably providing a way to set the margins of each child using a ParentDataWidget in the same way that Flex children can have their `flex` configured using the Expanded widget.

Probably the most complicated part of designing a new layout model like this would be deciding how to handle overflow or underflow, when the children are too big or too small to fit the constraints passed to this new layout render object. The RenderFlex render object has a way to distribute the space if the children underflow, and considers it an error if they overflow (in debug mode, this is shown by a yellow-and-black striped warning area and a message logged to the console); the RenderListBody render object on the other hand takes the view that the constraints must be unbounded in the main axis, which means you can basically only use this layout model inside a list (hence the name).

If writing a new layout model is not attractive, you could use one of the existing layout widgets that allow overlapping children. Stack is the obvious choice, where you set the explicit positions of each child and they can overlap arbitrarily (this is vaguely similar to the CSS absolute position layout model). Another option is the CustomMultiChildLayout widget, which lets you layout and position each child in turn. With this, you could position each child one after the other, simulating negative margins by setting the position of the subsequent child to a value that's derived from the size and position of the previous child, but such that the subsequent child's top is above the previous child's bottom.

If there's interest in a block-like layout model, we could certainly implement it (please file a bug and describe the model you'd like implemented, or, implement it yourself and send a pull request for review). So far, though, we've not found that it has been that useful in practice, at least not useful enough to justify the complexity.

And that's why the answer we usually give to the question of "how do you do negative margins" ends up being a higher-level question in return: what effect are you really trying to achieve?
Add a comment...

Post has attachment
Every once in a while a revolutionary product comes along that changes everything.
Photo
Add a comment...

Post has shared content
Finally a real use of Virtual Reality: exploring non-Euclidean space. How long before someone creates a walkable R'lyeh?
For you Cthulhu cultists out there. Walking through non-Euclidian space.
Add a comment...

Post has attachment
Travel time from London in 1881.
Photo

Post has attachment
Nějaký tip na knížku pro kluky 10-11 let co zatím moc nečtou? Hledám nějakou "gateway drug" -- pravděpodobně komiks nebo ilustrovanou knihu.

Vzpomínám, že jedna z prvních knížek, na kterých jsem se sekl, byla o římských legiích, kde skoro každá stránka byla obrovská ilustrace z ptačí perspektivy — vojenské ležení, bitva, obléhání. Text tam byl, ale zpočátku šlo hlavně o prohlížení si miniaturních ballist. :)

Tak něco takového. Snažil jsem se to najít v elektronických knihkupectvích ale zatím jsem nic (v češtině) nenašel a ani upřímně nevím, jaká klíčová slova mám použít.
Photo
Add a comment...
Wait while more posts are being loaded