Junior — Middle
What components or tools do you use to create interfaces that adapt to different screen sizes?
sobes.tech AI
Answer from AI
To create responsive interfaces in Flutter, the following components and approaches are usually used:
-
MediaQuery — allows obtaining the screen size and device orientation to adjust widget sizes and layout.
-
LayoutBuilder — provides size constraints from the parent widget, helping to build different layouts depending on available space.
-
Flexible and Expanded — help flexibly distribute space among child widgets.
-
AspectRatio — maintains a specified aspect ratio.
-
OrientationBuilder — reacts to changes in screen orientation.
-
Responsive frameworks and packages (e.g., flutter_screenutil, responsive_builder) — simplify the creation of responsive interfaces.
Example of using MediaQuery:
Widget build(BuildContext context) {
var screenWidth = MediaQuery.of(context).size.width;
if (screenWidth < 600) {
return MobileLayout();
} else {
return TabletLayout();
}
}