A Flutter package providing a flexible system for defining and resolving responsive layout breakpoints. Inspired by popular CSS frameworks (Tailwind, Bootstrap, Ant Design) and Material 3 guidelines, it allows you to adapt your UI to different screen widths with ease.
-
Theme-based resolution via
ResponsiveBreakpointTheme
extension -
Customizable: define your own breakpoints by implementing
BreakpointSpec
-
Predefined enums for common systems:
- TailwindBreakpoint (
sm
,md
,lg
,xl
,xxl
) - MaterialUIBreakpoint (
small
,medium
,large
) - BootstrapBreakpoint (
xs
,sm
,md
,lg
,xl
,xxl
) - AntBreakpoint (
xs
,sm
,md
,lg
,xl
,xxl
)
- TailwindBreakpoint (
-
Comparison operators (
<
,>
,<=
,>=
) onBreakpointSpec
Add the dependency in your pubspec.yaml
:
dependencies:
responsive_breakpoints: latest_version
Then run:
flutter pub get
import 'package:flutter/material.dart';
import 'package:responsive_breakpoints/responsive_breakpoints.dart';
void main() {
runApp(
MaterialApp(
theme: ThemeData(
extensions: [
ResponsiveBreakpointTheme<TailwindBreakpoint>(
breakpoints: TailwindBreakpoint.values,
),
],
),
home: const MyHomePage(),
),
);
}
TextSpan(switch (ResponsiveBreakpointTheme.of<BootstrapBreakpoint>(context)) {
BootstrapBreakpoint.xs => '<576px',
BootstrapBreakpoint.sm => '≥576px',
BootstrapBreakpoint.md => '≥768px',
BootstrapBreakpoint.lg => '≥992px',
BootstrapBreakpoint.xl => '≥1200px',
BootstrapBreakpoint.xxl => '≥1400px',
},
),
Name | Min Width |
---|---|
sm | 640px |
md | 768px |
lg | 1024px |
xl | 1280px |
xxl | 1536px |
Name | Range |
---|---|
small | <600px |
medium | 600–839px |
large | ≥840px |
Name | Min Width |
---|---|
xs | 0px |
sm | 576px |
md | 768px |
lg | 992px |
xl | 1200px |
xxl | 1400px |
Name | Min Width |
---|---|
xs | 0px |
sm | 576px |
md | 768px |
lg | 992px |
xl | 1200px |
xxl | 1600px |
To define your own system, implement BreakpointSpec
:
enum MyBreakpoints implements BreakpointSpec {
mobile(breakpoint: 0),
tablet(breakpoint: 600),
desktop(breakpoint: 1024);
@override
final double breakpoint;
const MyBreakpoints({required this.breakpoint});
}
Then add it to your theme:
ThemeData(
extensions: [
ResponsiveBreakpointTheme<MyBreakpoints>(
breakpoints: MyBreakpoints.values,
),
],
);
Resolve and compare just like the built-in enums.
-
ResponsiveBreakpointTheme<T extends BreakpointSpec>
resolveBreakpoint(context)
— returns the currentT
based on screen widthstatic of<T>(context)
— helper to resolve from theme extensions
-
BreakpointComparison
extension onBreakpointSpec
- Operators:
>
,<
,>=
,<=
- Operators:
-
BreakpointSpec
interface:final double breakpoint
-
Enums:
TailwindBreakpoint
,MaterialUIBreakpoint
,BootstrapBreakpoint
,AntBreakpoint
.
This project is licensed under the MIT License. See the LICENSE file for details.