Flutter Robot Maps: Rendering Large Occupancy Grids Efficiently
Robot maps can contain thousands or millions of cells. Building one widget per cell is usually the wrong abstraction; use a rendering strategy that matches scale and update patterns.
Separate map data from UI state
Store dimensions, resolution, origin, and cells in a model. Apply deltas to the model and notify the renderer only when visible regions change.
Choose a rendering strategy
CustomPainter can suit moderate grids with caching and repaint boundaries. Large, frequently changing maps may need tile caching or a native/GPU-backed renderer.
Avoid rebuilding every cell
Batch cells into rows, tiles, or layers. Cache static geometry and invalidate changed regions where supported.
Decouple map and telemetry refresh
Robot pose may update often while occupancy maps change rarely. Render layers at appropriate cadences.
Benchmark zoom and pan
Test representative map sizes, pixel ratios, zooming, and simultaneous telemetry. Track raster time, UI time, and memory.
Example implementation
This Dart snippet illustrates one part of the design. Adapt types, transport behavior, timestamp semantics, and platform APIs to your actual system before production use.
class MapViewportPainter extends CustomPainter {
MapViewportPainter(this.mapRevision);
final int mapRevision;
@override
void paint(Canvas canvas, Size size) {
// Draw cached tiles or batched geometry here.
// Avoid allocating one Paint or widget per occupancy cell.
}
@override
bool shouldRepaint(covariant MapViewportPainter oldDelegate) =>
oldDelegate.mapRevision != mapRevision;
}
Performance checklist
- Measure p95/p99 behavior on target hardware, not only a desktop simulator.
- Bound queues and buffers; define what may be coalesced or dropped.
- Keep heavy parsing, image processing, and inference away from the Flutter UI thread.
- Track source timestamps, sequence numbers, stale-data rate, and dropped updates.
- Test network degradation, reconnects, sustained operation, and resource pressure.
- Keep control commands and critical alerts separate from replaceable telemetry.
Useful Links
Website: www.v-modal.com
SDK Flutter: https://github.com/v-modal/vmodal_sdk_flutter
SDK Android: https://github.com/v-modal/vmodal_sdk_android
Discord: https://discord.gg/K72z28KUx
Top comments (0)