Le app Flutter funzionano su molte dimensioni di schermo (telefoni, tablet, web, desktop), quindi costruire UI responsive (adattandosi alle dimensioni) e adaptive (adattandosi alla piattaforma) è importante. Flutter fornisce strumenti come MediaQuery, LayoutBuilder, e widget flessibili per questo.
Responsive: adattamento alle dimensioni dello schermo
// 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();
})
