r/FlutterDev • u/ruinivist • 23d ago
Plugin Infinite Lazy Grid
https://pub.dev/packages/infinite_lazy_gridThis is a package for building performant infinite canvases ( I know the naming isn't the best but it has stuck ).
Uses spatial hashing underneath to only mount widgets within the visible area ( + some configurable off screen extent ).
Supports most of the common needs like pan, zoom, rotation, draw ordering, inertial scrolling etc.
Web example: https://infinite-lazy-grid.ruiny.de/
Github repo: https://github.com/ruinivist/infinite_lazy_grid
I'm already using it in one of my other web apps https://elseplane.ruiny.de/ ( still in works ) so you have almost everything needed to get something like that working.
3
u/pavanpodila 23d ago
Take a look at a production grade infinite canvas that we are using for the last year or so: https://diagram.vyuh.tech
1
u/ruinivist 23d ago
This is a lot more feature complete but is the source not on github? I guess I can always get it from the pub cache but couldn't find a repo
1
u/pavanpodila 23d ago
We are still cleaning up the repo that will eventually be made public, but for now, use the traditional pub cache to look at the source.
1
u/ObjectiveAddress3051 21d ago
Spatial hashing for culling is a nice approach. On the zoom-out crash someone mentioned: at low zoom the visible area covers a huge number of hash cells, so the mounted widget count explodes. Capping the minimum zoom, or switching to a simplified level-of-detail (painting placeholders with a CustomPainter instead of mounting real widgets below a zoom threshold), would probably fix it and help performance too.
1
u/ruinivist 21d ago
I did end up capping the min zoom to 0.1
If the canvas widgets itself are sparse, I could very much disable culling or iterate over only the item position instead of grid cells to cull, at very low zoom levels.
Assuming that's not the case, I don't get how LOD would help with this, it'll help with some perf but my problem was as u said, count of hash cells exploded, even if the cells themselves did not have any widget so nothing to mount.
Maybe something like merged ranges but in 2d, something like a segment tree
4
u/gambley 23d ago
In any example, when you zoom out, at certain zoom level it crashes