Aplicativos Flutter rodam em muitos tamanhos de tela (telefones, tablets, web, desktop), então construir UIs responsivas (adaptando-se ao tamanho) e adaptativas (adaptando-se à plataforma) é importante. Flutter oferece ferramentas como MediaQuery, LayoutBuilder e widgets flexíveis para isso.
Responsiva: adaptando-se ao tamanho da tela
// MediaQuery — get screen dimensions and adapt
final width = MediaQuery.of(context).size.width;
if (width > 600) {
// tablet/desktop layout (e.g. side-by-side)
} else {
// phone layout (e.g. stacked)
}
// LayoutBuilder — adapt based on the available space (parent constraints)
LayoutBuilder(builder: (context, constraints) {
if (constraints.maxWidth > 600) return WideLayout();
return NarrowLayout();
})
