ideabrowser.com — find trending startup ideas with real demand
Try itnpx skills add https://github.com/madteacher/mad-agents-skills --skill flutter-adaptive-uiCreate Flutter applications that adapt gracefully to any screen size, platform, or input device. This skill provides comprehensive guidance for building responsive layouts that scale from mobile phones to large desktop displays while maintaining excellent user experience across touch, mouse, and keyboard interactions.
Core Layout Rule: Constraints go down. Sizes go up. Parent sets position.
3-Step Adaptive Approach:
Key Breakpoints:
Follow the 3-step approach to make your app adaptive.
Identify widgets that need adaptability and extract common data. Common patterns:
For navigation, create a shared Destination class with icon and label used by both NavigationBar and NavigationRail.
Choose the right measurement tool:
MediaQuery.sizeOf(context) - Use when you need app window size for top-level layout decisions
MediaQuery.of() for size queriesLayoutBuilder - Use when you need constraints for specific widget subtree
BoxConstraintsExample:
// For app-level decisions
final width = MediaQuery.sizeOf(context).width;
// For widget-specific constraints
LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth < 600) {
return MobileLayout();
}
return DesktopLayout();
},
)
Apply breakpoints to select appropriate UI. Don't base decisions on device type - use window size instead.
Example breakpoints (from Material guidelines):
class AdaptiveLayout extends StatelessWidget {
@override
Widget build(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
if (width >= 840) {
return DesktopLayout();
} else if (width >= 600) {
return TabletLayout();
}
return MobileLayout();
}
}
Flutter layout follows one rule: Constraints go down. Sizes go up. Parent sets position.
Widgets receive constraints from parents, determine their size, then report size up to parent. Parents then position children.
Key limitation: Widgets can only decide size within parent constraints. They cannot know or control their own position.
For detailed examples and edge cases, see layout-constraints.md.
Row/Column
Row arranges children horizontallyColumn arranges children verticallymainAxisAlignment and crossAxisAlignmentExpanded to make children fill available space proportionallyContainer
Expanded/Flexible
Expanded forces child to use available spaceFlexible allows child to use available space but can be smallerflex parameter to control proportionsFor complete widget documentation, see layout-basics.md and layout-common-widgets.md.
Break down widgets
const widgetsDesign to platform strengths
Solve touch first
Never lock orientation
Avoid device type checks
Platform.isIOS, Platform.isAndroid for layout decisionsUse breakpoints, not orientation
OrientationBuilder for layout changesMediaQuery.sizeOf or LayoutBuilder with breakpointsDon't fill entire width
GridView or flex patternsSupport multiple inputs
For complete best practices, see adaptive-best-practices.md.
Separate what your code can do from what it should do.
Capabilities (what code can do)
Policies (what code should do)
// Capability class
class Capability {
bool hasCamera() {
// Check if camera API is available
return Platform.isAndroid || Platform.isIOS;
}
}
// Policy class
class Policy {
bool shouldShowCameraFeature() {
// Business logic - maybe disabled by store policy
return hasCamera() && !Platform.isIOS;
}
}
Benefits:
For detailed examples, see adaptive-capabilities.md and capability_policy_example.dart.
Switch between bottom navigation (small screens) and navigation rail (large screens):
Widget build(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
return width >= 600
? _buildNavigationRailLayout()
: _buildBottomNavLayout();
}
Complete example: responsive_navigation.dart
Use GridView.extent with responsive maximum width:
LayoutBuilder(
builder: (context, constraints) {
return GridView.extent(
maxCrossAxisExtent: constraints.maxWidth < 600 ? 150 : 200,
// ...
);
},
)
This skill currently has no executable scripts. All guidance is in reference documentation.
This skill includes complete Dart example files demonstrating:
These assets can be copied directly into your Flutter project or adapted to your needs.