Responsive
A responsive design system similar to Tailwind CSS, allowing you to create layouts that adapt to different screen sizes.
Overview
FlutterWind provides a powerful Responsive
design system that allows you to create layouts that adapt to different screen sizes. Similar to Tailwind CSS, FlutterWind uses breakpoints and responsive prefixes to apply different styles based on the viewport width.
Breakpoints
FlutterWind comes with default breakpoints that match Tailwind CSS:
These breakpoints can be customized in your flutterwind.yaml
configuration file.
Responsive Prefixes
You can use responsive prefixes to apply styles at specific breakpoints. The syntax is {breakpoint}:{utility}
:
In this example:
text-sm
applies on all screen sizesmd:text-base
applies on medium screens (768px) and uplg:text-lg
applies on large screens (1024px) and upxl:text-xl
applies on extra large screens (1280px) and up
Available Responsive Utilities
Almost all FlutterWind utilities can be made responsive by adding a breakpoint prefix. Here are some examples:
Responsive Layout
Responsive Sizing
Responsive Typography
Responsive Spacing
Responsive Grid
Mobile-First Approach
FlutterWind follows a mobile-first approach, where styles without a breakpoint prefix apply to all screen sizes, and breakpoint prefixes apply to that screen size and up.
This means you should start by designing for mobile screens and then add responsive prefixes to adapt the layout for larger screens.
Responsive Variants
You can also create responsive variants for state-based utilities like hover and focus:
Detecting Current Breakpoint
You can detect the current breakpoint in your code using the FlutterWindBreakpoints
class:
Implementation Details
The responsive design system is implemented in the FlutterWindParser
class, which parses utility classes and applies them based on the current screen width.
When a widget with responsive utilities is built, FlutterWind checks the current screen width against the defined breakpoints and applies the appropriate styles.
The FlutterWindBreakpoints
class provides utilities for working with breakpoints, including methods to get the current breakpoint and check if a specific breakpoint is active.
Best Practices
- Start with mobile designs: Define base styles without breakpoint prefixes, then add responsive prefixes for larger screens.
- Use meaningful breakpoints: Customize breakpoints to match your design requirements rather than using arbitrary values.
- Test on real devices: Responsive designs should be tested on actual devices to ensure they work as expected.
- Avoid breakpoint-specific logic: Try to use responsive utilities rather than conditional logic based on breakpoints.
- Group responsive utilities: Keep related responsive utilities together for better readability:
- Use the smallest set of utilities: Only add responsive variants when necessary to keep your code clean and maintainable.